How to set current year in AssemblyInfo file?
I used
Instead of this:
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.
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.
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/
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?
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.