2013-10-14 61 views
3

我正在使用Microsoft Visual Studio Express 2012的構建事件將一些文件複製到$(TargetDir)。如果找不到特定的文件,我該如何停止構建。目前,我有這樣的:通過構建事件停止構建和顯示消息

IF EXIST somefile ( 
ECHO true 
) ELSE (
ECHO false 
) 

隨着顯示器truefalse到生成輸出對話框,適當的,但我想用

ELSE (
ECHO somefile was not found 
exit 
) 

更換ECHO falseexit從構建停止在Visual Studio項目和somefile was not found是輸出控制檯中顯示的最後一條消息。

回答

3

強制Visual Studio來阻止它僅需要設置ERRORLEVEL

IF NOT EXIST somefile (
    echo somefile was not found 
    echo ERROR: This will be displayed in the error list of VS 
    exit /b 1 
) 
+1

這'exit'命令不從時,作爲預建事件發出的建設項目停止Visual Studio中的版本。 –

+0

給予一個錯誤級別使得Visual Studio中抱怨預生成步驟本身'錯誤\t \t 1命令「IF NOT EXIST somefile1( 回波somefile未找到 出口3 )」與代碼退出3. \t'這似乎更多像黑客。 –

+0

退出不會阻止它,但它應該有一個錯誤級別。此外,您可以添加一些錯誤輸出,這將顯示在錯誤列表中,不僅在編譯輸出 – jeb