我的解决方案中有一个项目,它最初是一个 C# 库项目。就代码而言,它对它没有任何兴趣,它只是在我的解决方案中用作其他项目的依赖项,以确保首先构建它。构建此项目的副作用之一是创建了一个共享的 AssemblyInfo.cs,其中包含其他项目正在使用的版本号。
我通过将以下内容添加到 .csproj 文件来完成此操作:
<ItemGroup>
<None Include="Properties\AssemblyInfo.Shared.cs.in" />
<Compile Include="Properties\AssemblyInfo.Shared.cs" />
<None Include="VersionInfo.targets" />
</ItemGroup>
<Import Project="$(ProjectDir)VersionInfo.targets" />
<Target Name="BeforeBuild" DependsOnTargets="UpdateSharedAssemblyInfo" />
引用的文件 VersionInfo.targets 包含以下内容:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!--
Some properties defining tool locations and the name of the
AssemblyInfo.Shared.cs.in file etc.
-->
</PropertyGroup>
<Target Name="UpdateSharedAssemblyInfo">
<!--
Uses the Exec task to run one of the tools to generate
AssemblyInfo.Shared.cs based on the location of AssemblyInfo.Shared.cs.in
and some of the other properties.
-->
</Target>
</Project>
VersionInfo.targets 文件的内容可以简单地嵌入到 .csproj 文件中,但它是外部的,因为我试图将所有这些都转换为项目模板。我希望模板的用户能够将新项目添加到解决方案中,编辑 VersionInfo.targets 文件并运行构建。
问题是修改和保存 VersionInfo.targets 文件并重建解决方案没有任何效果 - 项目文件使用 .targets 文件中的值,就像打开项目时一样。即使卸载和重新加载项目也没有效果。为了获得新值,我需要关闭 Visual Studio 并重新打开它(或重新加载解决方案)。
如何进行设置,以便配置在 .csproj 文件外部并且不在构建之间缓存?