尝试这个:
<Assembly: AssemblyCopyright("Copyright $([System.DateTime]::Now.ToString('yyyy')), Company Name.")>
我还没有完全尝试过。由于我使用此答案WriteCodeFragment
中描述的a 通过 .csproj 定义了程序集信息的其他部分,所以我也这样做 - 我定义属性
<!-- 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>
然后,在更新程序集信息的任务中,我有一个ItemGroup
包括
<AssemblyAttributes Include="AssemblyCopyright">
<_Parameter1>"Copyright © $(CopyrightYears) ..."</_Parameter1>
</AssemblyAttributes>
之后ItemGroup
我在该任务中有以下内容
<MakeDir Directories="$(IntermediateOutputPath)" />
<WriteCodeFragment Language="C#"
OutputFile="$(IntermediateOutputPath)Version.cs"
AssemblyAttributes="@(AssemblyAttributes)" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)Version.cs" />
</ItemGroup>
您可以用作属性的函数记录在此处