问题描述
我的解决方案中有一个项目,最初是C#库项目.就代码而言,它没有任何意义,它只是在我的解决方案中的其他项目中用作依赖项,以确保首先构建它.构建此项目的副作用之一是,将创建一个共享的AssemblyInfo.cs,其中包含其他项目正在使用的版本号.
I have a project in my solution which started life as a C# library project. It's got nothing of any interest in it in terms of code, it is merely used as a dependency in the other projects in my solution in order to ensure that it is built first. One of the side-effects of building this project is that a shared AssemblyInfo.cs is created which contains the version number in use by the other projects.
我通过将以下内容添加到.csproj文件中来完成此操作:
I have done this by adding the following to the .csproj file:
<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包含以下内容:
The referenced file, VersionInfo.targets, contains the following:
<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文件,然后运行构建.
The contents of the VersionInfo.targets file could simply be embedded within the .csproj file but it is external because I am trying to turn all of this into a project template. I want the users of the template to be able to add the new project to the solution, edit the VersionInfo.targets file, and run the build.
问题在于,修改和保存VersionInfo.targets文件并重建解决方案无效-项目文件使用.targets文件中的值,就像打开项目时一样.即使卸载和重新加载项目也没有效果.为了获得新值,我需要关闭Visual Studio并重新打开它(或重新加载解决方案).
The problem is that modifying and saving the VersionInfo.targets file and rebuilding the solution has no effect - the project file uses the values from the .targets file as they were when the project was opened. Even unloading and reloading the project has no effect. In order to get the new values, I need to close Visual Studio and reopen it (or reload the solution).
我该如何进行设置,以使配置位于.csproj文件的外部,而不是在构建之间进行缓存?
How can I set this up so that the configuration is external to the .csproj file and not cached between builds?
推荐答案
我刚刚回答了似乎与此类似的问题.
I've just answered what appears to be a similar question on this.
希望这也与您的问题有关.
Hopefully it's relevant your issue too.
这篇关于如何在项目构建期间防止外部MSBuild文件被Visual Studio缓存(通过Visual Studio)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!