我在解决方案中有一个项目,最开始是一个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文件且在构建之间不被缓存?