1
A
回答
2
This文章根據控制檯應用程序的退出代碼顯示如何失敗。
從批處理文件中配置構建活動後,使用exit
命令。
使用exit /b 0
表示一切正常,或exit /b 1
表示發生錯誤。 exit
命令結束批處理文件的執行,將errorlevel/exitcode設置爲'/ b'參數後面的值。
0
您可以使用context.TrackBuildError方法來標記構建錯誤。
+0
在InvokeProcess中,我們如何使用'context.TrackBuildError'? –
0
您可以使用MSBUILD調用bat文件。使用Exit代碼我們可以在bat文件失敗時失敗構建。
的MSBuild文件wrapper.proj
<Project DefaultTargets="Demo" ToolsVersion="3.5"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BatchFile>test.bat</BatchFile>
<FromMSBuild>FromMSBuild</FromMSBuild>
<build_configurations></build_configurations>
</PropertyGroup>
<Target Name="Demo">
<Message Text="Executing batch file $(BatchFile)" Importance="high"/>
<PropertyGroup>
<_Command>$(BatchFile) $(build_configurations) </_Command>
</PropertyGroup>
<Exec Command="$(_Command)">
<Output PropertyName="CommandExitCode" TaskParameter="ExitCode"/>
</Exec>
<Message Text="CommandExitCode: $(CommandExitCode)"/>
</Target>
</Project>
test.bat的
ECHO OFF
IF (%1)==() goto Start
SET fromMSBuild=1
:Start
ECHO fromMSBuild:%fromMSBuild%
REM ***** Perform your actions here *****
set theExitCode=101
GOTO End
:End
IF %fromMSBuild%==1 exit %theExitCode%
REM **** Not from MSBuild ****
ECHO Exiting with exit code %theExitCode%
exit /b %theExitCode%
由於@Sayed易卜拉欣哈希米他Post
相關問題
- 1. 如何在Maven構建失敗時停止批處理執行
- 2. Ant腳本執行失敗
- 3. 從批處理腳本傳遞參數到PowerShell腳本失敗
- 4. Springfuse - 執行失敗的目標:生成
- 5. 使用Popen執行腳本失敗
- 6. 批處理腳本 - Ping地址 - 寫入文件如果失敗
- 7. 批處理文件執行失敗,jenkins的PostBuildScript插件
- 8. 如何通過批處理腳本檢查VCBUILD是失敗還是成功
- 9. 停止ant腳本不失敗生成
- 10. 調用另一個批處理文件調用批處理文件失敗
- 11. 如何在exec-maven-plugin上執行清理腳本:exec失敗?
- 12. MStest失敗時,從Coded中調用批處理文件ui
- 13. 替代執行jdbc中的批處理,具有不同的失敗處理?
- 14. 構建失敗而執行Ant腳本
- 15. Windows中Powershell腳本執行失敗
- 16. 命令執行失敗perl腳本
- 17. 如何處理inet_ntop()失敗?
- 18. 如何處理AsyncTask失敗
- 19. 如何處理「getaddrinfo失敗」?
- 20. 如何處理url.get()失敗
- 21. 如何處理NetworkStream.Write失敗
- 22. 如何處理DDD失敗?
- 23. 處理失敗的API調用提取
- 24. 批處理腳本在IF語句中失敗
- 25. 缺少操作員批處理腳本失敗
- 26. 「批處理執行失敗,HTTP狀態碼爲BadGateway,端點
- 27. 如何在SQL作業步驟失敗時執行SQL腳本
- 28. 如何使用windows批處理腳本在informatica中使任務流失敗
- 29. maven版本:執行失敗
- 30. spring批處理Hadoop失敗,出現org.springframework.beans.factory.BeanNotOfRequiredTypeException
我沒放線'退出/ B 1'到指示我的.bat文件失敗,但構建仍然成功。你給出的文章是關於自定義流程活動的。我只使用本地的'InvokeProcess'。 –
@ NamG.VU,'InvokeProcess'只是啓動一個程序並返回'Result'(退出代碼/錯誤級別)。但有必要指出結果值的條件以使構建失敗。這就是變量保留返回值和變量的'if'來拋出錯誤的原因。 –
請更新您的答案以包含'Result'值以及如何在該變量的'if'中使用它以使構建失敗。謝謝! –