我正在为一个项目学习C#,并且在依赖项方面遇到了一些麻烦。基本上这里是如何设置的:
项目本身,一个名为(XMLupdater)的库,依赖于NuGet包。然后我有另一个项目用于测试上面的库(我称之为XMLtester)。这是我的测试项目的解决方案,在Visual Studio中添加了库作为依赖项:link bc I can't embed images yet
据我所知,这里的一切都是好的,但我在运行时遇到一个错误,说它无法找到NuGet包。它说:
System.IO.FileNotFoundException: 'Could not load file or assembly 'XmlDiffPatch.Core, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.'
我已经尝试了所有我能想到的解决这个问题的方法,但它归结为这样一个事实,即我对这种语言和思想没有多少经验,而且依赖关系有时可能很奇怪。我已经让其他几个人无济于事,所以我决定向你们提出圣人的建议。有帮助吗?
谢谢!
看来你有汇编版本问题。解决方案中引用的程序集将具有与错误消息中显示的版本不同的版本。
有两种方法可以解决这种情况:
对于第二个选项,您可以在执行项目的配置文件中添加/更新<assemblyRedirect
元素。
<dependentAssembly>
<assemblyIdentity name="someAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="en-us" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="— add the actual version of the assembly referenced in your project —" />
</dependentAssembly>
使用属性
newVersion
设置项目中引用的XmlDiffPatch.Core的版本。你可以在这里找到更多相关的细节:https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions