【发布时间】:2022-02-23 04:26:37
【问题描述】:
这个问题是关于为什么程序集找不到位于同一文件夹中的库。据我所知,调用者的位数(x64)与无法找到的 NuGet 包(AnyCPU)一致。
即使我将所有内容重新编译到 AnyCPU,错误消息仍然存在:
Could not load file or assembly 'ChoETL.Core, Version=1.2.1.28, etc.' The system cannot find the file specified.
我发布的 NET 5 exe (x64) 文件调用了一个发布的 NET 5 库,该库在错误消息 (exe->lib->ChoETL.Core) 中调用 Nuget 包 ChoETL.Core。
这是我用来构建程序 exe 和中间库 .csproj 文件的命令行。我不使用 Visual Studio,也不使用解决方案 .sln 文件。所有文件的构建都没有错误或警告。
msbuild -t:restore;publish /p:Platform=x64 /p:PlatformTarget=x64 /p:Configuration=Debug /p:TargetFramework=net5.0-windows7.0 /p:RuntimeIdentifier=win-x64 /p:PublishDir=c:\dev\holding\core.plt xxx.csproj
这是引用 ChoETL.Core 包的库的 .csproj 文件中的引用。请记住,msbuild 命令行属性会覆盖下面 csproj 文件中的 AnyCPU 值。
<PropertyGroup>
<UseWindowsForms>true</UseWindowsForms>
<Platforms>AnyCPU</Platforms>
<PlatformTarget>AnyCPU</PlatformTarget>
<TargetFramework>net5.0-windows7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ChoETL" Version="1.2.1.28" />
</ItemGroup>
我认为 CorFlags 值可能是问题所在,所以我检查了它们。如下(32bitreq/prefs 为零):
Program.exe: PE32+, flags 0x9, ILONLY 1, Signed 1
Library.dll: PE32+, flags 0x9, ILONLY 1, Signed 1
ChoETL.Core: PE32, flags 0x1, ILONLY 1, Signed 0
PE32+ 表示 x64,PE32 表示 AnyCPU(如果程序集加载到 64 进程中,它将作为 64 位程序集运行)。所以,它们应该是兼容的(此外,我无法编译 NuGet 包)。
我查看了这个 SO 问题,但没有帮助。 Could not load file or assembly, system could not find the file specified
当所有三个程序集并排在同一个文件夹中时,有谁知道为什么库找不到ChoETL.Core.dll 库?
我在这个问题上花了好几天没有进展或成功。谢谢。
【问题讨论】:
-
该程序集是否有任何其他无法找到的依赖项?
-
感谢您的建议。这是一个有趣的问题。 ChoETL(NuGet 包)依赖于 10 或 20 个其他包,但据我所知,NET 5 SDK 项目负责所有这些包。此外,我刚刚构建了一个运行的小型测试项目,它只需要包含可执行文件的文件夹中的单个程序集。所以我不认为链式依赖是问题所在。在这一点上,这对我来说是个谜。