Original answer: https://stackoverflow.com/a/50607951/10522960
Backup:
For .NET Core projects, I adapted Postlagerkarte's answer to update the assembly Copyright field with the build date.
Directly Edit csproj
The following can be added directly to the first PropertyGroup
in the csproj:
<Copyright>Copyright © $([System.DateTime]::UtcNow.Year) Travis Troyer ($([System.DateTime]::UtcNow.ToString("s")))</Copyright>
Alternative: Visual Studio Project Properties
Or paste the inner expression directly into the Copyright field in the Package section of the project properties in Visual Studio:
Copyright © $([System.DateTime]::UtcNow.Year) Travis Troyer ($([System.DateTime]::UtcNow.ToString("s")))
This can be a little confusing, because Visual Studio will evaluate the expression and display the current value in the window, but it will also update the project file appropriately behind the scenes.
Solution-wide via Directory.Build.props
You can plop the <Copyright>
element above into a Directory.Build.props
file in your solution root, and have it automatically applied to all projects within the directory, assuming each project does not supply its own Copyright value.
<Project>
<PropertyGroup>
<Copyright>Copyright © $([System.DateTime]::UtcNow.Year) Travis Troyer ($([System.DateTime]::UtcNow.ToString("s")))</Copyright>
</PropertyGroup>
</Project>
Directory.Build.props: Customize your build
Output
The example expression will give you a copyright like this:
Copyright © 2018 Travis Troyer (2018-05-30T14:46:23)
Retrieval
You can view the copyright information from the file properties in Windows, or grab it at runtime:
var version = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
Console.WriteLine(version.LegalCopyright);