Getting a Target to run BEFORE anything else runs when building from Visual Studio
I'm trying to get a one-time costly target to run only when building a certain top-level project (that has many dependencies).
I have no problem on getting this working from plain msbuild / command line build. I do this with setting and InitialTargets on the project, or alternatively with
< BeforeBuild />.
The tricky part is with Visual Studio. When I build the same project from VS. VS runs the dependencies before even invoking my .csproj, so my target (which affects how the other projects are built) doesn't get to run until they have already been built.
Is there someway to force VS to run a target before invoking the 开发者_如何学JAVAdependencies?
I'm currently working around this, by running the same costly target from my most low-level project (the one that get's always built...) by using:
Condition=" $(BuildingInsideVisualStudio) "
Any ideas on how to get this done "properly"? Again, I'm looking for a solution that will work FROM VS.
The only way to do this (if I understand the question) is to create a dummy project, that you tell VS to build first, that does whatever you want. VS will accept pretty much any MSBuild file if you give it a .csproj extension and the Build target.
Visual Studio uses an in proc compiler to help with the UX of the build process. Becuase of this there can be some difference between VS and MSBuild. Try setting the property UseHostCompilerIfAvailable to false in your project file. This will force VS to use MSBuild for the build. The drawback is performance inside Visual Studio.
You would use the follwing fragement in your .csproj (or .vbproj) file.
<PropertyGroup>
<UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
</PropertyGroup>
Why not override the <Target Name="BeforeBuild" />
target? That will be executed before the actual building of the project (since the Build
target depends on BeforeBuild
). Visual Studio is calling the Build target (or Rebuild), so overriding that target in the .csproj will cause it to be called first.
Unless you're looking to do something even earlier than that in the msbuild?
精彩评论