Dynamically display current year in assembly info

前端 未结 5 2093
轻奢々
轻奢々 2021-02-13 07:32

How to set current year in AssemblyInfo file?

I used

Instead of this:

 
         


        
5条回答
  •  感情败类
    2021-02-13 08:10

    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.

提交回复
热议问题