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 的所有痕迹并重新安装它们,但错误是一样的。