Build doesn't work from VisualStudio, but is ok from msbuild

允我心安 提交于 2019-12-02 16:43:04

问题


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)


回答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.



来源:https://stackoverflow.com/questions/9227641/build-doesnt-work-from-visualstudio-but-is-ok-from-msbuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!