nunit3-console 看不到来自 Microsoft.AspNETCore.App 的 DLL

问题描述 投票:0回答:1

当我从 Visual Studio 运行 UT 时,一切都运行良好,但是当我需要使用

nunit3-console My.Tests.dll
运行它时,我会看到像这样的
FileNotFoundException

无法加载文件或程序集“System.Security.Cryptography.Xml,...

我只看到来自

Microsoft.AspNETCore.App
文件夹的 DLL,来自
Microsoft.NETCore.App
的 DLL 加载得很好。

测试文件

[Test]
public void Test1()
{
    Assembly.Load("System.Security.Cryptography.Xml, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51");
}

如果我显式加载,则测试运行良好

Assembly.LoadFrom("C:\\Program Files\\dotnet\\shared\\Microsoft.AspNetCore.App\\8.0.0\\System.Security.Cryptography.Xml.dll");
c# nunit .net-8.0
1个回答
0
投票

看起来它是一个内部问题,

NUNIT3-CONSOLE
是运行时如何定位程序集,请阅读here

使用 dotner cli 和

dotnet test
可以轻松解决。

如果您必须使用它(很高兴知道为什么),您可以尝试修改运行时配置

[YourTestAssembly].runtimeconfig.json
类似:

{
  "runtimeOptions": {
    "tfm": "netcoreapp3.1",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "3.1.0"
    },
}

更改目标版本号。

© www.soinside.com 2019 - 2024. All rights reserved.