Reputation: 28545
Is there a way to temporarily disable pre and post build events?
i.e. build without build events (which are taking a bit of time but arent always crucial to run)
At the moment, I have minification and a couple of other things going on and I don't always need that.
Upvotes: 14
Views: 8997
Reputation: 169
Another option not yet mentioned here involves modifying the .vcxproj.user
file. To disable build events, put this file next to your .vcxproj
:
<!-- ProjectName.vcxproj.user -->
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<PreBuildEvent>
<Command>echo Skipping pre-build event!</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>echo Skipping post-build event!</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
</Project>
This will print a message to the console instead of running pre/post-build events defined in your project. It is important to use <ItemDefinitionGroup>
tag for it to work.
As mentioned in other answers, one can also use the following properties to disable custom build events completely:
<PropertyGroup>
<PreBuildEventUseInBuild>false</PreBuildEventUseInBuild>
<PreLinkEventUseInBuild>false</PreLinkEventUseInBuild>
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
</PropertyGroup>
(note a <PropertyGroup>
should be used here instead of <ItemDefinitionGroup>
.)
Custom.After.Microsoft.Common.Targets
approach).vcxproj.user
file in the project directory.user
files by default)Upvotes: 0
Reputation: 876
I also played a little with msbuild foo.vcxproj /p:PreBuildEvent= /p:PostBuildEvent=
, but for me it didn't work, probably because I am using custom props files.
What I found to work however was /p:PostBuildEventUseInBuild=false
Upvotes: 6
Reputation: 6173
Check your post build event settings. On the "Build Events" tab change the "Run the post-build event" combo box value to "When the build updates project output". Post build events will be executed only when output assembly is updated.
OR
Use MSBuild command to build your solution (this is useful for multi-solution projects). Create "DisableBuildEvents.msbuild" file somehere on your PC. DisableBuildEvents.msbuild content:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PostBuildEvent"/>
<Target Name="PreBuildEvent" />
</Project>
Execute MsBuild with CustomAfterMicrosoftCommonTargets property set in the command line:
MSBuild.exe YourSolution.sln /t:Build p:CustomAfterMicrosoftCommonTargets="c:\DisableBuildEvents.msbuild"
Note: CustomAfterMicrosoftCommonTargets value should be full path name.
Upvotes: 4
Reputation: 941455
Stuff like minimization only matters for the Release build. So you could skip it like this:
if "$(ConfigurationName)" == "Debug" goto skip
; stuff here...
:skip
There are some other macros you can use, click the Edit button and the Macro>> button to see them. Environment variables can be tested as well, use %varname%. But are much harder to set.
Upvotes: 14
Reputation: 14164
The simplest way to disable the build events is passing empty values:
msbuild your.sln /p:PreBuildEvent=;PostBuildEvent=
Upvotes: 17