简体   繁体   English

如何测试NuGet软件包是否与较低版本的依赖项一起工作?

[英]How to test if a NuGet package works with a lower version of its dependency?

Say I am using a NuGet package, in my project, that's dependent on version 1.2.3 of xyz However, I want to test to see if the NuGet package works with version 1.1.1 of xyz 假设我在我的项目中使用的是NuGet程序包,它依赖于xyz的1.2.3版本。但是,我想测试一下NuGet程序包是否适用于xyz的1.1.1版本。

I have tried doing assembly binding in App.config of my project this way, with the 1.1.1 version placed in the same directory where the 1.2.3 was. 我试过用这种方式在项目的App.config中进行程序集绑定,将1.1.1版本放在与1.2.3相同的目录中。

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
          <assemblyIdentity name="x.y.z" publicKeyToken="xxxx" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-1.2.3 newVersion="1.1.1" />
       </dependentAssembly>
      </assemblyBinding>
</runtime>

However, I still get this error: 但是,我仍然收到此错误:

Could not load file or assembly 'x.y.z, Version=1.2.3, Culture=neutral, 
PublicKeyToken=xxxx' or one of its dependencies. 
The system cannot find the file specified.

Any ideas how I can test to see if the NuGet package works with a lower version of a dll? 有什么想法可以测试以查看NuGet程序包是否与较低版本的dll兼容?

Thanks 谢谢

NuGet is a dependency management tool. NuGet是一个依赖项管理工具。 By default, it will fetch the latest version of any library when you install it into your project. 默认情况下,当您将其安装到项目中时,它将获取任何库的最新版本。 In your example, your project has version 1.2.3 of xyz installed which means it won't find version 1.1.1 like you tried to point it too. 在您的示例中,您的项目安装了xyz的1.2.3版本,这意味着它不会像您试图指出的那样找到1.1.1版本。

To test with an older version, step one needs to be uninstall the current version of the package from your project. 要使用旧版本进行测试,第一步需要从项目中卸载软件包的当前版本。 You need go to the Package Manager Console and execute the command Uninstall-Package xyz on your project. 您需要转到程序包管理器控制台,然后在项目上执行命令Uninstall-Package xyz

卸载程序包

Once you've done that, you will need to install the specific version of xyz that you want to test with. 完成此操作后,您将需要安装要测试的特定版本的xyz。 To do this, you need to run Install-Package xyz -Version 1.1.1 . 为此,您需要运行Install-Package xyz -Version 1.1.1 This will go out to NuGet, get the 1.1.1 version of the package and install it and now you be able to run your tests. 这将发布到NuGet,获取软件包的1.1.1版本并安装它,现在您可以运行测试了。 Keep in mind that the NuGet repository needs to have version 1.1.1 otherwise this will generate an error. 请记住,NuGet存储库必须具有版本1.1.1,否则将生成错误。 Refer to the projects NuGet page for the versions that are hosted and available. 有关托管的版本和可用的版本,请参考项目的NuGet页面。

安装特定的软件包版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM