asp.netassemblyinfocopyright-display

Current year in AssemblyInfo copyright


Is there a possibility to include the current year via DateTime.Now.Year in the AssemblyInfo.cs-file?

I have tried:

[assembly: AssemblyCopyright("Copyright " + DateTime.Now.Year)]

But it seems the argument can only be a constant expression.


Solution

  • As has been said, you cannot put values into attributes which are not constants. DateTime.Now is not a constant value and therefore cannot be used in an attribute.

    If you especially wanted this behaviour, you can add a script a pre-compile step which inserts the date into files.

    Personally, given the rate at which the year changes, it would be time poorly spent creating an autonomous task to do this. I have numerous projects which have "2009" in their Assembly Info. I have a task in my list to complete in the new year, to run a Regex tool to find and replace all instances of "2009" with "2010" in the AssemblyInfo.cs files.

    I would submit that this is a lot less work than integration into your build process.