views:

193

answers:

5

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.

+1  A: 

This is not possible because in .NET attributes may contain only constant expressions. You could use a before compile step that modifies the file and inserts current year.

Darin Dimitrov
+2  A: 

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.

Programming Hero
Agreed. For a show with a large number of projects or AssemblyInfo.cs files it might be worth automating your script to run annually, but it doesn't belong in the build process.
Peter LaComb Jr.
A: 

Is there a reason you need to update the year in your copyright notice? IANAL, but I thought once copyright was claimed it lasted for your life plus something like 70 years...

Chris Shaffer
+2  A: 

This is can be automated, but you'll need to use a method which manipulates the AssemblyInfo.cs file pre-build.

Should you be doing this though?

A term of copyright doesn't restart when you rebuild your code. If the copyright is currently 2009 it should remain at 2009 regardless of the current year, unless you make significant* code changes in a later year. For the value of 'significant' you need to consult a lawyer, not a software developer.

Joe Gauterin
A: 

Use @ {0} Microsoft in the AssemblyInfo.cs file and use string.Format in the server side to replace {0} with the current year value.

Thambu