Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent external MSBuild files from being cached (by Visual Studio) during a project build?

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?

like image 624
Damian Powell Avatar asked May 25 '10 10:05

Damian Powell


People also ask

What are MSBuild targets?

MSBuild includes several . targets files that contain items, properties, targets, and tasks for common scenarios. These files are automatically imported into most Visual Studio project files to simplify maintenance and readability. Projects typically import one or more . targets files to define their build process.

Where are MSBuild properties set?

MSBuild lets you set properties on the command line by using the -property (or -p) switch. These global property values override property values that are set in the project file. This includes environment properties, but does not include reserved properties, which cannot be changed.

Which of the following tag is used to specify the path of project in MSBuild?

For example, bin\Debug. Specifies the path to the output directory, relative to the project directory, for example, bin\Debug. Specifies the file format of the output file.

How do I edit a MSBuild file?

A standard MSBUILD file is an XML file, so opening it using File -> Open -> File should open it in the XML editor in VS. Then you can edit, add it to a project or whatever as you need. I'm not sure if you need a certain edition for the Intellisense to work. There is no standard template for target files or build files.


1 Answers

I've just answered what appears to be a similar question on this.

How to turn off caching of build definitions in Visual studio

Hopefully it's relevant your issue too.

like image 165
KazR Avatar answered Oct 03 '22 18:10

KazR