Current year in AssemblyInfo copyright

Is it possible to include the current year through DateTime.Now.Year in the AssemblyInfo.cs file?

I tried:

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

But it seems that an argument can only be a constant expression.

+3
source share
5 answers

As already mentioned, you cannot put values ​​in attributes that are not constants. DateTime.Nowis not a constant value and therefore cannot be used in an attribute.

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

, , , , . , "2009" . , Regex, "2009" "2010" AssemblyInfo.cs.

, , .

+4

, , AssemblyInfo.cs.

?

. 2009 , 2009 , .

* "" , .

+6

, .NET . , .

+3

@{0} Microsoft AssemblyInfo.cs string.Format , {0} .

+1

.

+1
source

Source: https://habr.com/ru/post/1726886/


All Articles