Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore warnings and errors of a postbuild event?

I have a postbuild event in my csproj. I want to ignore the output from this command, but whenever I do command >nul 2>&1 this csproj goes corrupt, probably because of the ">". I noticed when I write ">" from the postbuild window instead of editing the csproj directly if gets encoded.. Is there a workaround (other than running it from a bat file)

like image 687
blenddd Avatar asked Nov 09 '17 14:11

blenddd


People also ask

How do I set up a pre-build and post-build event?

On the Project menu, click Properties (or from Solution Explorer, press Alt + Enter ). Select Build > Events. In the Pre-build event section, specify the syntax of the build event. Pre-build events do not run if the project is up to date and no build is triggered. In the Post-build event section, specify the syntax of the build event.

What is pre build event in Visual Studio Mac?

Applies to: Visual Studio Visual Studio for Mac Visual Studio Code Use build events to specify commands that run before the build starts or after the build finishes. When a project is built, pre-build events are added to a file named PreBuildEvent.bat and post-build events are added to a file named PostBuildEvent.bat.

How do I terminate a pre-build or post-build?

The name of a batch file should be preceded by call to ensure that all subsequent commands are executed. If your pre-build or post-build event does not complete successfully, you can terminate the build by having your event action exit with a code other than zero (0), which indicates a successful action.

How do I use build events?

Use build events to specify commands that run before the build starts or after the build finishes. When a project is built, pre-build events are added to a file named PreBuildEvent.bat and post-build events are added to a file named PostBuildEvent.bat. If you want to ensure error checking, add your own error-checking commands to the build steps.


1 Answers

This can be done using MSBuild's <Exec> task from a custom target instead of relying on the default pre/post build script properties.

You can add this to your csproj file instead of using the default pre/post build scripts:

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
  <Exec Command="some command" IgnoreExitCode="true" />
</Target>

Note that for "sdk-based" projects (ASP.NET Core, .NET Core, .NET Standard) the above format is what is added when specifying a post build event in the Visual Studio UI already with the exception of the IgnoreExitCode attribute.

like image 66
Martin Ullrich Avatar answered Oct 22 '22 19:10

Martin Ullrich