.NET Framework Bookmark and Share   
 index > MSBuild > Error condition (target)
 

Error condition (target)

Hello,
I have a question regarding the Error Condition. In case I have a target and this target depends on some other 2 targets how can I insure that the condition will be verified before the other tartgets will run?

(For example :

<Target Name="Publish" DependsOnTargets="Compile">
<Error Condition="'$(Revision)' == ''" Text="Revision environment variable must be specified in order to build target: Publish"></Error>

</Target>

How can I insure that Error Condition will run before running the Compile target?

Thanks!

jimama
You could add another DependsOnTarget that does the check. e.g.

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Publish" DependsOnTargets="CheckState;Compile"/>

<Target Name="CheckState">
<Error Condition="'$(Revision)' == ''" Text="Revision environment variable must be specified in order to build target: Publish"></Error>
</Target>

<Target Name="Compile"/>
</Project>
Mike Fourie
Hi,
As Mike stated you should create another target, CheckState, which will execute the Error task. I would also suggest placing the CheckState target on the DependsOnTargets list for the Publish and Compile target. That target should be on the DependsOnTargets list for all targets which must assert that condition.

Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build
My Blog: sedodream.com
Visual C# MVP
Sayed Ibrahim Hashimi
You could add another DependsOnTarget that does the check. e.g.

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Publish" DependsOnTargets="CheckState;Compile"/>

<Target Name="CheckState">
<Error Condition="'$(Revision)' == ''" Text="Revision environment variable must be specified in order to build target: Publish"></Error>
</Target>

<Target Name="Compile"/>
</Project>
Mike Fourie
Hi,
As Mike stated you should create another target, CheckState, which will execute the Error task. I would also suggest placing the CheckState target on the DependsOnTargets list for the Publish and Compile target. That target should be on the DependsOnTargets list for all targets which must assert that condition.

Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build
My Blog: sedodream.com
Visual C# MVP
Sayed Ibrahim Hashimi

You can use google to search for other answers

Custom Search

More Threads

• BizTalk Deployment
• Static Linking
• How are custom tasks terminated
• Generate C# 2005 project files
• trouble referencing System.Management.Automation
• use ContinueOnError and still get the error status
• Msbee addin
• Console output text color / colour
• Msbuild merge error
• How do I test for empty properties set on the command line?