Can you prevent MSBuild.exe from running Build Events?

Viewed 25593

I'm building a number of projects via a script, and the occasional use of custom build events causes a great deal of difficulty for the build system. If it is possible, I'd like to invoke MSBuild.exe in such a was as to block the execution of any build events. In the long run, this is not an issue for build automation - submitters of projects with build events are forewarned that such snafuery is against the rules.

In short, is there a way to call MSBuild that will prevent the execution of any custom build steps, if present?

UPDATE:

I'd considered doing an in-place (automated) edit of the project files, but would prefer the command-line equivalent of setting "Excluded From Build" (see the Build Events options) to Yes for each of the three events.

9 Answers
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" 
Condition="'$(VisualStudioDir)' != ''">

Adding this Condition to the Target for the PreBuild in the project csproj file is the only solution that worked for me. I ran into this issue trying to automate a build within VSTS where I wanted to skip the PreBuild event defined in the project csproj file. Using Visual Studio 2017, a .NET Core 2.0 project.

I tried the msbuild command line suggestions listed here but none of them worked for me.

Related