【发布时间】:2017-08-24 01:05:40
【问题描述】:
dotnet new xunit ->
dotnet restore ->
dotnet test
测试总数:1。通过:1。失败:0。跳过:0。 试运行成功。 测试执行时间:1,7148 秒。
.csproj;将目标框架更改为 net461:
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
</Project>
那么
dotnet restore ->
dotnet test
Starting test execution, please wait...
No test is available in C:\Projects\testing\bin\Debug\net461\testing.dll. Make sure that installed test discoverers & executors, platform & framework version sett
ings are appropriate and try again.
我应该如何使用 xunit 测试 net461 项目? 我已经有一个从 .NET Core 1.0 升级的大项目,并且在升级之前测试工作正常,因此更改测试框架需要一些工作。
更新
事实证明,这可能与 xunit 和测试无关 - 针对 net461 的 ASP.NET Core 项目将不再在我的机器上运行,无论是通过 VS 还是通过 cmd。
我尝试运行的项目是 VS 模板中的一个新的空 Web 项目。 csproj 看起来像这样:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
</ItemGroup>
</Project>
我得到的错误是这样的:
dotnet run
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Hosting, Version=1.1.1.0, Culture=neutral, PublicKeyTo
ken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
at WebApplication2.Program.Main(String[] args)
我已尝试从我的机器中删除 Visual Studio 和 .NET Core 的所有痕迹并重新安装它们,但错误是一样的。
【问题讨论】:
-
重复所有列出的步骤 - 使用
net461成功发现测试。检查dotnet --version和dotnet输出-您使用的是最新/发布版本吗?检查父文件夹 - 也许你有global.json与 sdk 重定向到其他(旧)版本... -
dotnet --info .NET 命令行工具 (1.0.1) 产品信息: 版本:1.0.1 提交 SHA-1 哈希:005db40cd1 运行时环境:操作系统名称:Windows 操作系统版本:6.3.9600操作系统平台:Windows RID:win81-x64 基本路径:C:\Program Files\dotnet\sdk\1.0.1
-
我忘了说;当我安装旧的 SDK 时,这曾经可以工作。尝试修复 VS2017 的问题并进行测试,我清除了所有 SDK 并重新安装了最新的。
-
好的,测试应该可以工作(将 testclass 添加到问题文本以 100% 确定)。尝试手动删除 bin 和 obj 文件夹(仅保留两个文件 - csproj 和 cs)并重新运行 restore/test...
-
xUNIT 可与最新版本的 .NET Framework 和 .NET 核心一起正常工作。您无需更改测试框架。 docs.microsoft.com/en-us/dotnet/articles/core/testing/… 有一个 xUNIT 示例。
标签: asp.net-core .net-core xunit dotnet-cli