c# - 如何解决错误 MSB4041(VS2017、C#、MSBuild、SpecFlow.Tools.MsBuild.Generation、SpecRun)?
问题描述
我有一个自动化测试套件,试图使用 SpecRun 并行运行测试。看来,我不能在测试资源管理器中运行测试,而是需要使用提供的“runtests.cmd”文件来运行它们......
@pushd %~dp0
@where /q msbuild
@IF ERRORLEVEL 1 (
echo "MSBuild is not in your PATH. Please use a developer command prompt!"
goto :end
) ELSE (
MSBuild.exe "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj"
)
@if ERRORLEVEL 1 goto end
@cd ..\packages\SpecRun.Runner.*\tools\net45
@set profile=%1
@if "%profile%" == "" set profile=Default
@if exist "%~dp0\bin\Debug\%profile%.srprofile" (
SpecRun.exe run "%profile%.srprofile" --baseFolder "%~dp0\bin\Debug" --log "specrun.log" %2 %3 %4 %5
) else (
SpecRun.exe run --baseFolder "%~dp0\bin\Debug" --log "specrun.log" %2 %3 %4 %5
)
:end
@popd
pause
...暂停语句是我添加的内容,以保持控制台打开以查看错误。
错误是:
Microsoft (R) Build Engine version 4.7.3056.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 08/07/2019 11:15:06.
Project "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" on node 1 (defau
lt targets).
C:\Users\me\source\repos\OurAutomation\src\packages\SpecFlow.Tools.MsBuild.Generation.3.0.220\build\Sp
ecFlow.Tools.MsBuild.Generation.props(1,1): error MSB4041: The default XML namespace of the project must be the MSBuild
XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/d
eveloper/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please
convert it to MSBuild 2003 format. [C:\Users\me\source\repos\OurAutomation\src\OurAutomati
on.csproj]
Done Building Project "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" (d
efault targets) -- FAILED.
Build FAILED.
"C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" (default target) (1) ->
C:\Users\me\source\repos\OurAutomation\src\packages\SpecFlow.Tools.MsBuild.Generation.3.0.220\build\
SpecFlow.Tools.MsBuild.Generation.props(1,1): error MSB4041: The default XML namespace of the project must be the MSBui
ld XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com
/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, pleas
e convert it to MSBuild 2003 format. [C:\Users\me\source\repos\OurAutomation\src\OurAutoma
tion.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.02
我已设置系统环境变量 PATH 以在 C:\Windows\Microsoft.NET\Framework\v4.0.30319 中查找 MSBuild.exe(这是我拥有的最新版本)。
我尝试按照错误提示进行操作,发现 OurAutomation.csproj 和 OurAutomation.csproj.user 文件都已经有:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
所以这是一个简单的解决方法 - 根本没有修复,因为 Project 标签已经具有所需的属性和值!
我一直在几个网站上寻找替代解决方案。其他人说他们从 VS2015 升级到 2017 时遇到了这个问题(他们从使用 project.json 更改为 *.csproj)。但是我还没有升级。我在 VS2017 中创建了我的项目。目标框架:.NET Framework 4.7.2,输出类型:类库。
不确定 SpecFlow.Tools.MsBuild.Generation 是否在这里引入了冲突,但我确实需要它。
请问你知道我将如何解决这个问题吗?没有想法了。
谢谢你。
解决方案
Pavel Anikhouski 的回答是解决方案,谢谢!
“从 VisualStudio 2015 开始,MSBuild 作为 IDE(或构建工具)的一部分提供,您应该使用此版本,例如 c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\”。
推荐阅读
- swift - 这是从 Notification.Name.CNContactStoreDidChange 通知中识别哪个联系人更新的正确方法吗?
- jquery - 点击时
- mysql - 如何更新引用 MySQL 中父表的外键字段的值?
- reactjs - React Native 只是在闪屏后崩溃
- c - 在结构中定义指针函数
- ios - 为什么 iPhone XR/Xs Max 不遵守比率约束?
- vb.net - VB.Net - 如何在 GeckoFX60 中获取新窗口 URL
- swift - Swift 中的 didSet 和 willSet 是如何实现的
- php - 如何获得 UNION ALL 的总和
- javascript - createdAt、updatedAt 和 deletedAt 字段中的 unix 时间戳