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)
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With