2009-03-03 104 views
1

我正在尝试在批处理文件中创建多个.sln文件。到目前为止,一切都很好。我试图在批处理文件中添加一个检查,所以如果错误数大于0,那么批处理文件将停止执行,并且不会生成下一个.sln文件。我怎样才能做到这一点?基本上是这样的:Visual Studio,MS Build

的MSBuild test.sln (检查是否生成错误> 0 停止) 的MSBuild test2.sln

回答

4

MSBUILD将设置ERRORLEVEL,所以沿着线的东西:

msbuild test.sln 
IF NOT ERRORLEVEL 0 exit 1 

编辑:显然,这应该是:

msbuild test.sln 
IF ERRORLEVEL 1 exit 1 
+0

“not errorlevel 0”始终为false,因为“errorlevel 0”始终为真。 – 2009-03-03 18:01:11

+2

这似乎不适合我。无论是否有错误,MSBuild始终返回0的错误级别。 – Phil 2011-05-27 16:40:34

1
msbuild.exe test.sln 
if errorlevel 1 goto :errors 

msbuild.exe test2.sln 
if errorlevel 1 goto :errors 

:: ... 

:: Everything was fine. 
echo Build completed without errors. 
goto :eof 

:error 
echo Build failed. 
1

在我看来,在这里使用一个自定义的msbuild文件并且在你的解决方案中使用msbuild任务要容易得多。详情请见here