[英]Nuget package references cause “Could not load file or assembly” ?
There is a recent principle on Nuget package parsing. Nuget包解析有一个最近的原则。 For details, see how NuGet parses package dependencies.
有关详细信息,请参阅NuGet如何解析包依赖项。 A Microsoft diagram is used to explain:
Microsoft图表用于解释:
This time you will choose the most recent package, which is the 2.0 version.
这次您将选择最新的软件包,即2.0版本。 no problem.
没问题。
One problem I encountered today is that one of my Nuget packages (called Package A current version 1.2.3) originally only supports the version of netstandard 2.0, which is defined in the csproj file. 我今天遇到的一个问题是我的一个Nuget包(称为Package A当前版本1.2.3)最初只支持netstandard 2.0的版本,它在csproj文件中定义。
<TargetFramework>netstandard2.0</TargetFramework>
I have another product, the ECS Nuget package (called Package B version 1.0.0), and Package B needs to reference Package A. 我有另一个产品,ECS Nuget包(称为包B版1.0.0),包B需要引用包A.
The relationship route is [Package B 1.0.0] -> [Package A 1.2.3] 关系路线是[包B 1.0.0] - > [包A 1.2.3]
At this time, the two packages in the program can be used normally. 此时,程序中的两个包可以正常使用。
Later, due to the support of the .net framework, I modified the original package A nuget package and changed it to the following. 后来,由于.net框架的支持,我修改了原始包A nuget包并将其更改为以下内容。
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
Package A package generation version is 1.3.2. 包的包生成版本是1.3.2。 At this time, I refer to the above two packages and find that the compilation is ok, but I am getting an error at runtime.
这时,我参考上面的两个包,发现编译没问题,但我在运行时遇到错误。
I can solve the above problem by upgrading Package B, but why is this error?
我可以通过升级包B解决上述问题,但为什么会出现这个错误? Is it because of the use of TargetFrameworks?
是因为使用了TargetFrameworks吗? I also hope that the big men will give pointers.
我也希望大个子能指点一下。
When I compare the *.deps.json
file, I found something helpful. 当我比较
*.deps.json
文件时,我发现了一些有用的东西。 Here is the first scenario get the following json file: 这是第一个获取以下json文件的场景:
"aliyun-net-sdk-core/1.3.2": {
"dependencies": {
"Serilog": "2.5.0",
"Serilog.Exceptions": "4.0.0",
"Serilog.Sinks.File": "4.0.0"
},
"runtime": {
"lib/netstandard2.0/aliyun-net-sdk-core.dll": {
"assemblyVersion": "0.0.0.0",
"fileVersion": "0.0.0.0"
}
}
}
Because of the reference to version 1.3.2, however, the CLR can't find the DLL with Version 1.3.2 when loading the assembly, there is only assembly version 0.0.0.0, so the CLR looks for the 1.2.3 version referenced by the original project, but it is not found, so it reports an error. 但是,由于引用了1.3.2版本,CLR在加载程序集时找不到版本1.3.2的DLL,只有程序集版本0.0.0.0,所以CLR查找引用的1.2.3版本由原始项目,但没有找到,所以它报告错误。 Clearly understood.
清楚地了解。
After I make up the miss assembly version of the project, I got the right result. 在我编写项目的miss assembly版本后,我得到了正确的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.