依赖项目之间的依赖关系不流动,导致 System.IO.FileNotFoundException

Dependencies not flowing between dependent projects, causing System.IO.FileNotFoundException

假设我的解决方案有 2 个项目:

第一个项目 (MainProject) 有一个名为 "dependencyX" 的 NuGet 依赖项。显然,项目 "MainProjectTests" 引用了 "MainProject".

因此,当测试运行程序运行 "MainProjectTests" 的测试时,它使用 "dependencyX" 从 "MainProject" 调用方法,我得到一个 System.IO.FileNotFoundException 异常:

System.IO.FileNotFoundException : Could not load file or assembly 'dependencyX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

为什么我会收到此异常?当我将 "dependencyX" 添加到 "MainProjectTests" 时一切正常,但在我看来这不是一个好的做法...如何解决?

我正在使用 Visual Studio Mac Community 7.2 预览版(7.2 build 583)

感谢您的帮助。

编辑:

尝试放置选项:

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

在 NUnit 项目中,但得到相同的结果。

这似乎是关于 .NET Standard 库(尤其是与 NUnit 结合使用)的已知错误。我已经提交了一份 bug report here,这似乎证实这不是预期的行为。虽然半年多了一点进展都没有

也许有人应该在确认只有在使用 NUnit 时才会发生这种情况后,在 NUnit 存储库中提交一个错误。

目前您需要引用 .NET Standard 项目中使用的所有库,以及您现在正在做的所有引用 .net 标准项目的库。

这是一个向 Microsoft 报告过几次的错误,他们似乎对此没有做太多,看看这个 Visual Studio does not copy referenced assemblies through the reference hierarchy

另一方面,至少对于 Nuget 包,您有一种简单的方法(将相同的包添加到同一解决方案中的多个项目),使用解决方案的包管理器,如您在此处所见 Nuget Package Manager.