0

From a brand new console application template in visual studio, I edited the .csproj to build another project like this:

...
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="BeforeBuild">
  <MSBuild Projects=".\other.mproj"/>
</Target>    
...

Where other.mproj is:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">

   <Target Name="Build">
       <Message Text="kikou" />     
   </Target>

</Project>

After a while I discovered that modifying the content of other.mproj (for instance, by introducing errors or changing text kikou to something else) would not be taken into account unless unloading/reloading the project in visual studio.

Building from the command line with 'msbuild myproj.csproj' immediatly detect changes in 'other.mproj'. So it all looks like visual studio is working from a cached version of other.mproj file.

Why is visual studio caching this other script (which is even not included to the project), and how can I solve this issue ?

Update: I also tried this UseHostCompilerIfAvailable, it doesn't work.


NB1: I didn't add other.mproj as a project reference in the .csproj because it is not a .NET project at all (it just creates resources files for the .csproj from other inputs before the build)

NB2: I'm using VS2010 (10.0.10219.1SP1Rel + MSBuild 4.0.30319.1)

Community
  • 1
  • 1
CitizenInsane
  • 4,755
  • 1
  • 25
  • 56
  • No solutions that I know to this problem, it already happened to me and apart from unload/reload of the solution in visual studio, there don't seem to be a way. – Julien Roncaglia Feb 10 '12 at 12:23
  • @VirtualBlackFox: Ok, thx. As a workaround, i placed the msbuild command as a 'PreBuildEvent' instead of adding it to the 'BeforeBuild' target. This both saves from editing the '.csproj' and solves for '.mproj' caching issue :) – CitizenInsane Feb 10 '12 at 14:02

1 Answers1

1

Visual Studio caches all MSBuild files, this is done for performance reasons. You will not be able to have an MSBuild only way around this. It may be possible to achieve this via a VS add-in but I'm not 100% sure of that.

Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
  • Thank you for your quick answer. Hope VS cache mechanism will be later improved to correctly detect changes in related MSBuild files. Using the prebuild event is meantime quite ok (i.e works locally but not on our build-server because there 'msbuild.exe' is not on cruisecontrol env path, anyway it's easy to fix). Thanks again. – CitizenInsane Feb 12 '12 at 01:09
  • TADIN: Found an elegant workaround [here](http://stackoverflow.com/a/9177749/684399) – CitizenInsane Feb 12 '12 at 01:47
  • For information, after hours debugging, just discovered that great workaround I had found [here](http://stackoverflow.com/q/9227641/684399) for VS2010 no longer works in VS2012 ... `msbuild myproject.csproj` is still ok. `vs2012->myproject->build` does not enter `BeforeBuild` even with the temporary file workaround. – CitizenInsane Oct 22 '13 at 17:02