2014-05-07 103 views
0

是否可以終止作爲正常執行流程的項目(* .csproj)的MSBuild進程?從一個項目中終止MSBuild沒有錯誤

喜歡的東西

<Exit Condition="..."></Exit> 

這應該不會引發錯誤。它應該是在某些條件下跳過構建項目的有效流程。

該項目是一個Visual Studio項目,這意味着構建目標是在Microsoft.Common.Target文件中定義的,而不是在csproj中定義的。單獨

回答

0

錯誤標籤將終止腳本沒有引發錯誤: 試試這個:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <Target Name="Build"> 
    <Message Text="Before error"/> 
    <Error/> 
    <Message Text="After error"/> 
    </Target> 
</Project> 
+0

我可以在Visual Studio項目中使用它嗎?已經有一個「Build」目標。我只是想在某些情況下停止建設項目。在你的例子中,我應該把條件放在哪裏? –

0

我發現了一個辦法解決這個。也許這不是最優雅的事情,但它的工作原理。我不得不重寫「Build」目標。原始目標在Microsoft.Common.Targets文件中定義。我考察壽看到「創建」的目標是如何定義的文件,它是這樣

<Target 
    Name="Build" 
    Condition=" '$(_InvalidConfigurationWarning)' != 'true' " 
    DependsOnTargets="$(BuildDependsOn)" 
    Returns="$(TargetPath)" /> 

所以,在我的項目文件,我不得不創建自己的「生成」的目標這將是與上面那一個,與它會附加條件邏輯

在我的csproj文件唯一的區別我創造了這個:

<Target 
    Name="Build" 
    Condition=" '$(_InvalidConfigurationWarning)' != 'true' And (.... more conditions here....) " 
    DependsOnTargets="$(BuildDependsOn)" 
    Returns="$(TargetPath)" /> 

這似乎是工作,特別是當項目建成多重的批量構建的一部分項目內的解決方案。

相關問題