How can I prevent external MSBuild files from being cached (by Visual Studio) during a project build
Posted
by Damian Powell
on Stack Overflow
See other posts from Stack Overflow
or by Damian Powell
Published on 2010-05-25T10:31:30Z
Indexed on
2010/05/25
12:31 UTC
Read the original article
Hit count: 271
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.
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" />
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>
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.
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).
How can I set this up so that the configuration is external to the .csproj file and not cached between builds?
© Stack Overflow or respective owner