本文介绍了在生成事件中执行bat文件得到错误“错误MSB3073:命令" call"MyTest.bat"以代码1退出."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的解决方案中,我们有150多个项目,我需要先构建一个项目,但是我不想一一设置100多个项目的项目引用或项目依赖项.这是浪费时间.因此,我在提出这个问题之前先提出以下问题:

In our solution we have more than 150 projects, I need build one of project before others, but I did not want to set project reference or project dependencies for more than 100 projects one by one. This is a waste of time. So I ask following question before this one:

设置构建顺序而不使用项目引用

@Leo Liu建议我可以先使用批处理文件来构建项目,这应该是一个有效的解决方法.作为优化,我想在该项目的build事件中设置此bat文件,以便只构建该项目,而无需从外部手动运行bat文件.

And as @Leo Liu suggested that I could use batch file to build the project first, it is should be a valid workaround. As optimization, I want set this bat file in the build event of that project so that I only need to build that project, do not need to manually run the bat file from outside.

但是,当我使用以下构建事件构建该项目时:

However, when I build that project with below build event:

call "$(ProjectDir)\MyTest.bat"

我收到此错误:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(5074,5): error MSB3073: The command "call "C:\Users\Myname\Source\repos\MysolutionName\GenerateFile\MyTest.bat"" exited with code 1. [C:\Users\\Source\repos\MysolutionName\GenerateFile\GenerateFile.csproj]

更新:bat文件中的脚本为:

Update:The scripts in the bat file is:

@echo OFF
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
echo "Starting Build for all Projects with proposed changes"
MSBuild.exe "C:\Users\MyName\Source\repos\MySolutionName\MySolutionName.sln"
pause
echo "All builds completed."

有什么建议吗?预先感谢.

Any suggestion? Thanks in advance.

推荐答案

根据您的问题,我创建了一个测试样本,并收到30多个错误,但没有其他详细信息:

According to your question, I created a test sample and got more than 30 errors without any other detailed info:

error MSB3073: The command "call "D:\TestSample.bat"" exited with code 1.

进一步的研究发现了这些错误的原因,因为您在bat文件中构建了解决方案,然后在解决方案中一个项目的构建事件中设置了该bat文件,该项目在bat文件中进行了调用.

Further study found the reason for those errors, that because you build the solution in the bat file, then you set this bat file in the build event of one project in the solution, which called in the bat file.

因此将生成无限循环,这就是为什么在构建事件中一个命令行中出现30多个错误的原因.

So an infinite loop will generated, that is the reason why we got more than 30 errors for one command line in the build event.

要解决此问题,在使用bat文件构建解决方案时,我们不应构建指定项目,因此您可以打开Configuration Manager,取消选中用于生成项目的构建复选框:

To resolve this issue, we should not build the specify project when we build the solution with bat file, so you could open Configuration Manager, uncheck the build checkbox for generate project:

使用此设置,当您使用该bat文件构建解决方案时,该项目将被忽略.

With this setting, this project will be ignore when you build the solution with that bat file.

这篇关于在生成事件中执行bat文件得到错误“错误MSB3073:命令" call"MyTest.bat"以代码1退出."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 14:01