Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 停止生成并显示包含生成事件的消息_Windows_Visual Studio_Batch File_Visual Studio 2012_Cmd - Fatal编程技术网

Windows 停止生成并显示包含生成事件的消息

Windows 停止生成并显示包含生成事件的消息,windows,visual-studio,batch-file,visual-studio-2012,cmd,Windows,Visual Studio,Batch File,Visual Studio 2012,Cmd,我正在使用Microsoft Visual Studio Express 2012的生成事件将一些文件复制到$(TargetDir)。如果找不到特定文件,如何停止生成。目前我有一些类似于: IF EXIST somefile ( ECHO true ) ELSE ( ECHO false ) 在构建输出对话框中显示true和false,但我想将ECHO false替换为 ELSE ( ECHO somefile was not found exit ) 其中exit停止Visual

我正在使用Microsoft Visual Studio Express 2012的生成事件将一些文件复制到
$(TargetDir)
。如果找不到特定文件,如何停止生成。目前我有一些类似于:

IF EXIST somefile ( 
ECHO true 
) ELSE (
ECHO false 
)
在构建输出对话框中显示
true
false
,但我想将
ECHO false
替换为

ELSE (
ECHO somefile was not found
exit
) 

其中
exit
停止Visual Studio生成项目,并且
somefile未找到
是输出控制台中显示的最后一条消息

强制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
)

exit
命令在作为预生成事件发出时,不会阻止Visual Studio生成项目。给出错误级别会使Visual Studio抱怨预生成步骤本身
Error 1命令“IF not EXIST somefile1(echo somefile not found exit 3)”退出时代码为3。
这更像是一次黑客攻击。退出不会阻止它,但它应该具有错误级别。此外,您还可以添加一些错误输出,这些输出将显示在错误列表中,而不仅仅显示在生成输出中。我始终使用prebuild.bat文件,VS会报告批处理文件的错误(就像它在链接时报告错误一样)
Fehler 2错误MSB3073:Der Befehl“D:\Projekte\xyz\Tools\prebuild.bat:VCEnd”wurde mit dem代码2 beendet.C:\Program Files(x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.cppcomon.targets 103您不能直接访问它们,只能作为批处理参数访问。我的预链接事件是
$(ProjectDir)\PreBuild.bat“$(SolutionDir)”
。我使用引号来避免从批处理中访问
%1
参数时出现空格或特殊字符问题