【发布时间】:2017-04-11 14:50:50
【问题描述】:
在我的一生中,我无法通过基于 msbuild 的新 netcoreapp1.0 xunit 项目模板在 Visual Studio 2017 中进行单元测试。
要求单元测试在 Visual Studio(针对开发人员)和 CLI 上的 dotnet test 中都可以用于自动化构建过程,但是,我无法让两者都能始终如一地工作。
这是我尝试过的:
在现有解决方案中,创建一个新项目并选择 .NET Core > xUnit Test Project。
从 Visual Studio 构建项目,默认测试出现并成功运行,现在在 powershell 提示符下运行dotnet test,得到:
> dotnet test
Test run for D:\...\bin\Debug\netcoreapp1.0\MyProj.dll(.NETCoreApp,Version=v1.0)
dotnet exec needs a managed .dll or .exe extension. The application specified was 'C:\Program'
或使用 csproj 文件进行 dotnet 测试:
> dotnet test MyProject.csproj
(same error as above)
> dotnet test ..\MySolution.sln
Couldn't find a project to run test from. Ensure a project exists in D:\...
Or pass the path to the project
如果我添加 xunit.runner.console 或 xunit.runner.msbuild nuget 包,它会停止在 Visual Studio 中进行单元测试。
如何让两者同时工作?
谢谢!
【问题讨论】:
-
@tommed,你能在 Visual Studio 命令提示符下构建/运行它吗?这个问题可能是因为 VS 2017 中的 msbuild 是应用程序本地的,这意味着有特殊的环境变量用于确定 msbuild 的位置、使用的 .targets 和类库。
-
@MichaelBraude 对此表示感谢。我也在 Developer Command Prompt 和 MSBuild Command Prompt 中尝试过同样的操作,并得到了同样的错误 - 不过想法不错!
-
虽然与 NET Core 无关,但我将其作为评论发布:VS2017 Full NET 4.5 framework here,同样的问题:找不到单元测试。我不得不使用 Nuget 从我的一个项目中卸载并重新安装
xunit.runner.visualstudio。然后重建解决方案,并找到测试。希望这会有所帮助。
标签: unit-testing msbuild xunit.net .net-core visual-studio-2017