依赖项在依赖项目之间不流动,从而导致System.IO.FileNotFoundException [英] Dependencies not flowing between dependent projects, causing System.IO.FileNotFoundException
问题描述
假设我的解决方案有2个项目:
Let's say my solution has 2 projects:
- 第一个称为"MainProject"(.NETStandard 2.0项目).
- 第二个叫"MainProjectTests"(一个NUnit测试项目),每个类的一些单元测试都进入"MainProject".
第一个项目(MainProject)具有一个名为"dependencyX"的NuGet依赖项.显然,项目"MainProjectTests"具有对"MainProject"的引用.
The first project (MainProject) has a NuGet dependency called "dependencyX". Obviously, the project "MainProjectTests" has a reference to "MainProject".
因此,当测试运行程序运行"MainProjectTests"测试,并使用"dependencyX"从"MainProject"调用方法时,我得到一个System.IO.FileNotFoundException
异常:
So when the test runner runs a test of "MainProjectTests" that calls methods from "MainProject" using "dependencyX" I'm getting a System.IO.FileNotFoundException
exception:
System.IO.FileNotFoundException:无法加载文件或程序集 'dependencyX,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'或一个 的依赖项.
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"时,一切正常,但是在我看来,这不是一个好习惯……如何解决?
Why am I getting this exception? When I add "dependencyX" to "MainProjectTests" all works fine, but it seems to me not a good practice... How to solve it?
我正在使用Visual Studio for Mac Community 7.2预览版(7.2 build 583)
I'm using Visual Studio for Mac Community 7.2 preview (7.2 build 583)
感谢您的帮助.
尝试放置选项:
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
在NUnit项目中,但得到相同的结果.
in the NUnit project, but getting the same result.
推荐答案
这似乎是有关.NET标准库的已知错误(尤其是与NUnit结合使用).我已经提交了错误在此处报告,这似乎证实这不是预期的行为.半年以来一直没有任何进展.
This seems to be a known bug regarding .NET Standard libraries (and maybe especially in conjunction with NUnit). I already filed a bug report here which seems to confirm that this is not the intended behaviour. Altough there has been no progress for over half a year.
在确认只有在使用NUnit时才会发生这种情况,也许应该在NUnit仓库中提交一个错误.
Maybe one should file a bug in the NUnit repo after confirming this only happens when using NUnit.
暂时,您需要像现在一样在引用.net标准的所有项目中引用.NET Standard项目中使用的所有库.
For the time beeing you'll need to reference all libraries used in a .NET Standard project also in all projects referencing the .net standard one as you are doing right now.
这篇关于依赖项在依赖项目之间不流动,从而导致System.IO.FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!