raklos
raklos

Reputation: 28545

How to temporarily disable build events in Visual Studio?

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

Answers (5)

pcfist
pcfist

Reputation: 169

Disabling build events via the User Settings file

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>.)

Advantages of this approach

  • No need to modify project/solution files
  • Doesn't require changing the environment (see Custom.After.Microsoft.Common.Targets approach)
  • Works for both command line and IDE builds—no extra arguments required, just put the .vcxproj.user file in the project directory
  • Does not interfere with source control (Git etc. usually ignores .user files by default)

Upvotes: 0

AndreiM
AndreiM

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

Ludwo
Ludwo

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

Hans Passant
Hans Passant

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

KMoraz
KMoraz

Reputation: 14164

The simplest way to disable the build events is passing empty values:

msbuild your.sln /p:PreBuildEvent=;PostBuildEvent=

Upvotes: 17

Related Questions