[英]Same Nuget package on two different projects in same solution
I have two API projects within the same solution (one in which is mine, and another in which I need to reference and should not be changing).我在同一个解决方案中有两个 API 项目(一个是我的,另一个是我需要参考且不应更改的)。 Both of these API projects add reference to the
Ninject
and Ninject.Web.Common
package.这两个 API 项目都添加了对
Ninject
和Ninject.Web.Common
package 的引用。 Here is how the packages are setup:以下是软件包的设置方式:
Ninject.Web.Common
In Web Api A - \packages\Ninject.Web.Common.3.3.2\lib\net45\Ninject.Web.Common.dll
Ninject.Web.Common
In Web Api A - \packages\Ninject.Web.Common.3.3.2\lib\net45\Ninject.Web.Common.dll
Ninject.Web.Common
in Web Api B - \packages\Ninject.Web.Common.3.2.3.0\lib\net45-full
Ninject.Web.Common
in Web Api B - \packages\Ninject.Web.Common.3.2.3.0\lib\net45-full
(note the versions are different 3.3.2
and 3.2.3
) (注意版本不同
3.3.2
和3.2.3
)
What's happening is when I try to run my solution I get发生的事情是当我尝试运行我得到的解决方案时
Could not load type 'Ninject.Web.Common.OnePerRequestHttpModule' from assembly 'Ninject.Web.Common, Version=3.3.2.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7'.
on my Web Api B
project (note it's trying to reference the 3.3.2
version from my Web Api A
project). on my
Web Api B
project (note it's trying to reference the 3.3.2
version from my Web Api A
project).
How can I keep both projects the same and have them reference their own respective version of Ninject?如何保持两个项目相同并让它们引用各自版本的 Ninject?
You can typically only resolve one version of a given dependency in your dependency graph ( nuget restore
is mainly for calculating which version to use given your dependency graph).您通常只能在依赖关系图中解析给定依赖关系的一个版本(
nuget restore
主要用于计算给定依赖关系图使用哪个版本)。
This is usually fine, but your problem is that OnePerRequestHttpModule
was removed between versions 3.2.3 and 3.3.2 of Ninject.Web.Common https://www.fuget.org/packages/Ninject.Web.Common/3.3.2/lib/netstandard2.0/diff/3.2.3/ and WebApiB wanted to use it. This is usually fine, but your problem is that
OnePerRequestHttpModule
was removed between versions 3.2.3 and 3.3.2 of Ninject.Web.Common https://www.fuget.org/packages/Ninject.Web.Common/3.3.2/ lib/netstandard2.0/diff/3.2.3/和 WebApiB 想使用它。
Your options here are to modify WebApiB so it doesn't use OnePerRequestHttpModule
any more, or to downgrade the version of Ninject.Web.Common in WebApiA to 3.2.3您在此处的选择是修改 WebApiB 使其不再使用
OnePerRequestHttpModule
,或者将 WebApiA 中的 Ninject.Web.Common 的版本降级到 3.2.3
You can try one of these approaches:您可以尝试以下方法之一:
<configuration>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="SomeStrongNameLib" culture="neutral" publicKeyToken="6a770f8bdf3d476a" />
<codeBase version="1.0.0.0" href="StrongNameLibV10/SomeStrongNameLib.dll"/>
<codeBase version="1.1.0.0" href="StrongNameLibV11/SomeStrongNameLib.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Reference:参考:
Using two different versions of same the nuget package 使用相同的两个不同版本 nuget package
https://michaelscodingspot.com/how-to-resolve-net-reference-and-nuget-package-version-conflicts/ https://michaelscodingspot.com/how-to-resolve-net-reference-and-nuget-package-version-conflicts/
https://devnet.kentico.com/articles/referencing-multiple-versions-of-the-same-assembly-in-a-single-application https://devnet.kentico.com/articles/referencing-multiple-versions-of-the-same-assembly-in-a-single-application
I see you are on 4.5 FW but:我看到你在 4.5 FW 但是:
If you are already on the newer csproj format or you can upgrade to it (this is just to change the format of csproj, the project itself will still target what it was targeting )如果您已经在使用较新的 csproj 格式或者您可以升级到它(这只是为了更改 csproj 的格式,项目本身仍将针对它的目标)
https://natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/ https://natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/
then you could stop the dependecies flowing to the top (the link is for dotnet core, but if the project format is the newer one from above, then the suggestion is still valid):那么您可以停止依赖项流向顶部(该链接用于 dotnet 核心,但如果项目格式是上面较新的格式,那么该建议仍然有效):
The way to change the default behavior is to add
更改默认行为的方法是添加
<PrivateAssets>all</PrivateAssets>
for each package/project dependency inclusion.
对于每个包/项目依赖项包含。
https://curia.me/net-core-transitive-references-and-how-to-block-them/ https://curia.me/net-core-transitive-references-and-how-to-block-them/
this should work also on some Full.Net FW pojects.这也应该适用于一些 Full.Net FW 项目。
Once you managed to stop the flowing of dependencjes you can add to your project your reference to the needed version of your dependency一旦您设法停止依赖项的流动,您就可以将您对所需版本的依赖项的引用添加到您的项目中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.