Dynamically display current year in assembly info

前端 未结 5 790
天命终不由人
天命终不由人 2021-02-13 07:05

How to set current year in AssemblyInfo file?

I used

Instead of this:

 


        
相关标签:
5条回答
  • 2021-02-13 07:49

    Probably the best way is to integrate this into your build process using tools like NAnt or MSBuild.

    Here is an article that explains how to change your AssemblyInfo using MSBuild: Updating Assemblies with A Version Number.

    0 讨论(0)
  • 2021-02-13 07:53

    I saw something on another post (https://stackoverflow.com/a/827209/857307) that could really be helpful here.

    Try this.

    Add a new file to your source repository somewhere common to all of the projects in your solution. Call the file something like AssemblyCopyright.tt

    In the file, add the following code for c#

    <#@ template language="C#" #>
    using System;
    using System.Reflection;
    
    [assembly: AssemblyCopyright("Copyright © CompanyName <#=DateTime.Now.Year#>")]
    

    or vb

    <#@ template language="VB" #>
    <#@ output extension=".vb" #>
    Imports System
    Imports System.Reflection
    
    <Assembly: AssemblyCopyright("Copyright © CompanyName <#=DateTime.Now.Year#>")> 
    

    Then, remove the AssemblyCopyright attribute from each of your AssemblyInfo.cs files.

    Finally, add a link to the AssemblyCopyright.tt file to each of your projects.

    The template file will recreate a new AssemblyCopyright.cs file on every build with the correct year.

    0 讨论(0)
  • 2021-02-13 08:04

    You can use NANT/MSBuild tasks to modify the AssemblyInfo.cs file like we do to change the Version of each assembly for every build.

    For more information, visit http://msbuildtasks.tigris.org/

    0 讨论(0)
  • 2021-02-13 08:06

    Typically, for that kind of substitution, you use a pre-build step that invokes a script that automatically generates your assemblyInfo.cs file.

    You can have a look at this thread : How can you find and replace text in a file using the Windows command-line environment?

    0 讨论(0)
  • 2021-02-13 08:07

    I had similar question, but for new style csproj file; that contains the file version info. I found a great answer here How to define current system date in post build event. Oddly, that is about a question that is somewhat different than my and the OP question. But, I think the accepted answer to that is what I want. Namely, $([System.DateTime]::Now.Year) in the csproj files evaluates to the current year.

    0 讨论(0)
提交回复
热议问题