Thoughts about setup and deployment issues, WiX, XNA, the .NET Framework and Visual Studio
All postings are provided AS IS with no warranties, and confer no rights. Additionally, views expressed herein are my own and not those of my employer, Microsoft.
While working on some Windows Media Center development scenarios over this past weekend, I ran into an interesting scenario that I could not figure out how to accomplish in Visual Studio 2005 - I wanted to be able to run a pre-build event command line but have Visual Studio 2005 ignore the return code in case of failure.
I searched around in the Visual Studio UI and in the MSDN documentation, but could not find a way to cause Visual Studio to continue if the pre-build event failed. Eventually I found a way to do this, but I had to ask a friend of mine who works on the MSBuild team in Visual Studio. Hopefully anyone else who searches for a way to do this will be able to find this post and figure it out more easily than I did.
I started out by adding the pre-build event in the Visual Studio IDE by doing the following:
When I built my project, if my pre-build event failed, it would report an error in the Task List and the build stopped at that point.
What I found out from my friend is that the default syntax for the pre-build event is defined in %windir%\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets. This is the file that defines all of the steps in the standard build process for .NET projects. The syntax for the default pre-build event looks like the following:
<Target Name="PreBuildEvent" Condition="'$(PreBuildEvent)'!=''" DependsOnTargets="$(PreBuildEventDependsOn)"> <Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" /></Target>
You will notice in the <Exec> command above that there is not any statement regarding return code processing. That causes Visual Studio to always stop in the case of a non-zero return code from the command line that is executed as a pre-build step.
There are a few options that I found that enabled Visual Studio 2005 to ignore errors in the pre-build event:
Option 1 - Override the PreBuildEvent target in your project file using IgnoreExitCode
In this option, you define your own customized version of the PreBuildEvent <Target> that will override the default version listed in Microsoft.Common.targets. You can add the following to the end of your project file (such as a vbproj or csproj file):
<Target Name="PreBuildEvent" Condition="'$(PreBuildEvent)'!=''" DependsOnTargets="$(PreBuildEventDependsOn)"> <Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" IgnoreExitCode="true" /></Target>
This <Target> section will cause the pre-build event to run if the command line is non-blank in the project file or in the Visual Studio IDE UI. It will ignore the return code from the process and not report it back to you in the Task List, and the build will continue.
If you choose this option, you will have to add the above <Target> section to each project file you want to ignore the pre-build event return code.
Option 2 - Override the PreBuildEvent target in your project file using ContinueOnError
In this option, you also define your own customized version of the PreBuildEvent target that will override the default version listed in Microsoft.Common.targets, but you use different return code processing logic than in option 1. You can add the following to the end of your project file (such as a vbproj or csproj file):
<Target Name="PreBuildEvent" Condition="'$(PreBuildEvent)'!=''" DependsOnTargets="$(PreBuildEventDependsOn)"> <Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" ContinueOnError="true" /></Target>
This <Target> section will cause the pre-build event to run if the command line is non-blank in the project file or in the Visual Studio IDE UI. It will ignore the return code from the process, but it will report it back to you as a warning in the Task List. The build will also continue even if any errors are encountered.
Option 3 - Change the default PreBuildEvent target
In this option, you directly modify %windir%\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets to add IgnoreExitCode="true" or ContinueOnError="true" to the PreBuildEvent <Target> section as shown above.
If you choose this option, you will cause all .NET projects that you build in Visual Studio 2005 to ignore the pre-build event return code.
PingBack from http://blog.nufer.org/2007/09/19/visual-studio-post-pre-build-events/
Dans Subversion (SVN), le numéro de révision est un identifiant qui est incrémenté automatiquement à chaque fois que des fichiers sont commités dans le référentiel. Ainsi, ce numéro permet d'identifier de manière sûr l'état du projet à un instant T.Il
You don't need a separate batch file to make use of the "exit 0" technique. The pre- and post- build command line inputs are multiline textboxes and accept multiple commands... basically you are writing a batch file into those fields. You all you need to do is add "exit 0" as your last line in the command textbox and it will work as desired. I just tried it and it works. Much simpler than editing .csproj files.
and the cool part is... it works for VS 2010 too