How to: Ignore Errors in Tasks
Sometimes you want a build to be tolerant of faults in certain tasks. If those non-critical tasks fail, you want the build to continue because it can still produce the required output. For example, if a project uses a SendMail task to send an e-mail message after each component is built, you might consider it acceptable for the build to proceed to completion even when the mail servers are unavailable and the status messages cannot be sent. Or, for example, if intermediate files are usually deleted during the build, you might consider it acceptable for the build to proceed to completion even when those files cannot be deleted.
Using the ContinueOnError Attribute
The ContinueOnError attribute of the Task element controls whether a build stops or continues when a task failure occurs. Setting ContinueOnError to true specifies that the build will continue even if the task fails.
The default value of ContinueOnError is false. Setting the attribute to false does not change the behavior, but does make the behavior explicit to anyone who reads the project file.
To ignore an error in a task
Use the ContinueOnError attribute of the task. For example:
<Delete Files="@(Files)" ContinueOnError="true"/>
The following code example illustrates that the Build target still runs and the build is considered a success, even if the Delete task fails.
<Project DefaultTargets="FakeBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Files Include="*.obj"/> </ItemGroup> <Target Name="Clean"> <Delete Files="@(Files)" ContinueOnError="true"/> </Target> <Target Name="FakeBuild" DependsOnTargets="Clean"> <Message Text="Building after cleaning..."/> </Target> </Project>