Stop build and display message with Build Events

2019-07-07 03:36发布

I am using the Build Events with Microsoft Visual Studio Express 2012 to copy some files into the $(TargetDir). How can I stop the build if a particular file isn't found. Currently I have something like:

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

With displays true and false to the build output dialog as appropriate but I'd like to replace ECHO false with

ELSE (
ECHO somefile was not found
exit
) 

Where exit stops the Visual Studio from building the project and somefile was not found is the last message displayed in the output console.

1条回答
做自己的国王
2楼-- · 2019-07-07 04:15

Forcing visual studio to stop the build it needs only to set the 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
)
查看更多
登录 后发表回答