Try this:
<Assembly: AssemblyCopyright("Copyright $([System.DateTime]::Now.ToString('yyyy')), Company Name.")>
I haven't tried this exactly. Since i define some other parts of the assembly info via the .csproj using a WriteCodeFragment
as described in this answer, I do it this way too - I define properties
<!-- We started in 2021. So, if it's still 2021 we just want to show '2021' -->
<PropertyGroup Condition="$([System.DateTime]::Now.ToString('yyyy')) == '2021'">
<CopyrightYears>2021</CopyrightYears>
</PropertyGroup>
<!-- But for later years we want a range. E.g. in 2023 it will show '2021 - 2023' -->
<PropertyGroup Condition="$([System.DateTime]::Now.ToString('yyyy')) != '2021'">
<CopyrightYears>2021 - $([System.DateTime]::Now.ToString('yyyy'))</CopyrightYears>
</PropertyGroup>
Then, within the task that updates the assembly info i have an ItemGroup
including
<AssemblyAttributes Include="AssemblyCopyright">
<_Parameter1>"Copyright © $(CopyrightYears) ..."</_Parameter1>
</AssemblyAttributes>
The after the ItemGroup
I have the following within that task
<MakeDir Directories="$(IntermediateOutputPath)" />
<WriteCodeFragment Language="C#"
OutputFile="$(IntermediateOutputPath)Version.cs"
AssemblyAttributes="@(AssemblyAttributes)" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)Version.cs" />
</ItemGroup>
The functions you can use as properties are documented here