[英]'Could not load file or assembly. The system cannot find the file specified' - thrown after packaging .NET Framework NuGet package
I am trying to package a class library which references another DLL called 'TestDLL'我正在尝试 package 一个 class 库,该库引用另一个名为“TestDLL”的 DLL
The target is .NET framework 4.8 and I am using NuGet Package Explorer to build the package.目标是 .NET 框架 4.8,我正在使用 NuGet Package Explorer 来构建 ZEFE90A8E604A7C840D88D03A6C840D88D03A6C840E88D03。 I have added a lib folder and a folder named after the target framework, in which I have the dll for the main project and then the referenced DLL which I have called 'TestDLL'
我添加了一个 lib 文件夹和一个以目标框架命名的文件夹,其中我有主项目的 dll,然后是引用的 DLL,我称之为“TestDLL”
See below:见下文:
Here is the metadata (nuspec content) which contains a reference to TestDLL.dll这是包含对 TestDLL.dll 的引用的元数据(nuspec 内容)
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
<metadata>
<id>Nexbotix.OCR</id>
<version>1.0.7</version>
<authors>Nexbotix.OCR</authors>
<owners></owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package Description</description>
<dependencies>
<group targetFramework=".NETFramework4.8" />
</dependencies>
<references>
<group targetFramework=".NETFramework4.8">
<reference file="TestDLL.dll" />
</group>
</references>
</metadata>
</package>
I am packaging this up into a nupkg file from Package Explorer.我将它打包到来自 Package Explorer 的 nupkg 文件中。 Everything seems fine in that I am able to import the nuget package into my target project without error.
一切似乎都很好,因为我能够将 nuget package 导入到我的目标项目中而不会出错。 Then when I go to run the code, if I attempt to reference an object from within TestDLL.dll, I get this error stating that the file for reference TestDLL.dll cannot be found.
Then when I go to run the code, if I attempt to reference an object from within TestDLL.dll, I get this error stating that the file for reference TestDLL.dll cannot be found.
Obviously there is something wrong with the way I am constructing the nuget package file structure.显然,我构建 nuget package 文件结构的方式有问题。 I simply want to package a class library in .NET Framework which itself references another DLL which is visible to whichever project imports the nuget package.
I simply want to package a class library in .NET Framework which itself references another DLL which is visible to whichever project imports the nuget package. Can anyone help point me in the right direction?
谁能帮我指出正确的方向?
I found the reason this is happening and it is not because of anything I was doing wrong in dependency management.我找到了发生这种情况的原因,这不是因为我在依赖管理中做错了什么。
Instead, it was due to a problem in the original open-source project.相反,这是由于原始开源项目中的问题造成的。
I reached out to the repository maintainer who explained that it is a known issue with dependencies and that there is a requirement for a specific project in the solution to also have a reference to the dependency until the issue is fixed.我联系了存储库维护人员,他解释说这是依赖项的一个已知问题,并且解决方案中的特定项目还需要引用依赖项,直到问题得到解决。
Thank you to everyone who attempted to answer this question.感谢所有试图回答这个问题的人。 Much appreciated.
非常感激。
Not sure if nuget cache caused this.不确定 nuget 缓存是否导致此问题。 Try the following steps:
尝试以下步骤:
1) uninstall your nuget package Nexbotix.OCR
1)卸载您的 nuget package
Nexbotix.OCR
2) clean nuget caches or just delete all files under C:\Users\xxx\.nuget\packages
2) 清理 nuget 缓存或删除
C:\Users\xxx\.nuget\packages
下的所有文件
3) when you pack your nuget project with the nuspec
file, I suggest you should remove 3)当你用
nuspec
文件打包你的 nuget 项目时,我建议你应该删除
<references>
<group targetFramework=".NETFramework4.8">
<reference file="TestDLL.dll" />
</group>
</references>
When you used this, it will only reference TestDLL.dll
and MyProject.dll
will never be added into your main project.当您使用它时,它只会引用
TestDLL.dll
和MyProject.dll
永远不会添加到您的主项目中。 This is the result of my test.这是我的测试结果。 Whichever you specify in
<references>
, it will only install that.无论您在
<references>
中指定哪个,它都只会安装它。
Or , you should add all the dlls into references
node like this:或者,您应该将所有 dll 添加到
references
节点中,如下所示:
<references>
<group targetFramework=".NETFramework4.8">
<reference file="TestDLL.dll" />
<reference file="MyProject.dll" />
</group>
</references>
In fact , if you do this too much, nuget will install all the content of the lib
folder automatically without using the References
node.事实上,如果你这样做太多,nuget 将自动安装
lib
文件夹的所有内容,而不使用References
节点。
The whole nuspec file I used is this:我使用的整个 nuspec 文件是这样的:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>xxx</id>
<version>1.0.0</version>
<title>me</title>
<authors>me</authors>
<owners>me</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
....
<tags>Tag1 Tag2</tags>
<dependencies>
<group targetFramework=".NETFramework4.8" />
</dependencies>
</metadata>
<files>
<file src="bin\Debug\TestDLL.dll" target="lib\net48" />
<file src="bin\Debug\TestDLL.pdb" target="lib\net48" />
<file src="bin\Debug\MyProject.pdb" target="lib\net48" />
</files>
</package>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.