Dynamically display current year in assembly info

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

How to set current year in AssemblyInfo file?

I used

Instead of this:

 
         


        
5条回答
  •  梦谈多话
    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
    
    ")> 
    

    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.

提交回复
热议问题