C#递归依赖未找到

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

我正在为一个项目学习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.'

我已经尝试了所有我能想到的解决这个问题的方法,但它归结为这样一个事实,即我对这种语言和思想没有多少经验,而且依赖关系有时可能很奇怪。我已经让其他几个人无济于事,所以我决定向你们提出圣人的建议。有帮助吗?

谢谢!

c# visual-studio dependencies
1个回答
0
投票

看来你有汇编版本问题。解决方案中引用的程序集将具有与错误消息中显示的版本不同的版本。

有两种方法可以解决这种情况:

  1. 获取错误中显示的精确版本的程序集,并添加对该错误的引用。
  2. 在配置文件中使用bindingRedirect告诉编译器要查找的版本。

对于第二个选项,您可以在执行项目的配置文件中添加/更新<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

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