Web 作业:找不到库
Web Job: Library not found
我们有一个连续的 WebJob,它是用 .NET Core 2.x 编写的,并且在过去几周 运行 一直很好。最近有人对此 WebJob 进行了一些更改,并引入了第 3 方 NuGet 包。现在,我无法启动 WebJob,因为它无法找到第 3 方库依赖项之一。
这是错误信息:
D:\local\Temp\jobs\continuous\Temp1\oitdncff.sfg>dotnet Temp1.dll
Error:
An assembly specified in the application dependencies manifest (Temp1.deps.json) was not found:
package: 'System.Drawing.Common', version: '4.5.0-preview1-25914-04'
path: 'runtimes/win/lib/netcoreapp2.0/System.Drawing.Common.dll'
我在谷歌搜索这个问题时尝试了一些我发现的东西。这是 csproj 文件中的 PropertyGroup 和 ItemGroup(NuGet 包):
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<ApplicationIcon />
<StartupObject>Temp1.Program</StartupObject>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>latest</LangVersion>
<Version>1.0.0.0</Version>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="AsyncEnumerator" Version="2.1.0" />
<PackageReference Include="EPPlus.Core" Version="1.5.4" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.5.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.5.1" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
根据网上的建议,我添加了行
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
和
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
有依赖关系的相关包是EPPlus.Core
我已确认库 System.Drawing.Common
确实存在于我们的 Azure Web 应用程序的应用程序文件夹中,但是当 WebJob 启动时,它忽略了该文件并在运行时查找 (GAC ) 和失败。
更新:
我意识到 EPPlus.core 包不是官方的,所以切换到官方包希望这能解决错误。同样的错误,但 System.Drawing.Common version: 4.5.0-preview1-26216-02
的新版本
我已手动将 System.Drawing.Common version: 4.5.0-preview2-26406-04
的 NuGet 包添加到项目中,这消除了原始错误,但随后我开始收到无法找到 Microsoft.Win32.SystemEvents version: 4.5.0-preview2-26406-04
的错误。该库依赖于 System.Drawing.Common
。
我尝试做与上面相同的事情,并将 Microsoft.Win32.SystemEvents version: 4.5.0-preview2-26406-04
的 NuGet 包直接添加到项目中,但这次错误没有消失。
进一步更新:
经过更多搜索后,我发现了一个帖子 ,其中谈到 发布 然后压缩发布的目录并上传 zip。这确实有效,有问题的错误消失了,但这并不是真正的解决方案。我们使用 VSTS 作为我们的回购系统和我们的 CI/CD。我将构建配置设置为进行发布,然后复制文件。 WebJob 在通过此过程部署时抛出错误。
首先,我想声明,截至今天,据我所知,Azure WebJobs 并非 100% 支持 .NET Core(如果我错了,请随时纠正我),但是有很多文章和有关如何使它们发挥作用的帖子。
以下是我为解决上述问题而采取的解决方案,虽然我觉得这并不优雅,但我确实觉得 Microsoft 做了一些奇怪的事情,大多数开发人员认为这不是正确的方法。
我遇到问题的原因是当我构建(调试或发布)时,清单文件始终指向运行时 (GAC)。 运行 在我的本地盒子上从来都不是问题,因为可以找到文件。奇怪的是,在发布模式下构建时,所有文件都被复制到 bin 文件夹,但清单仍然告诉程序查看运行时而不是使用本地副本。当这被推送到 WebJob 本身时,这些文件在运行时不存在,因此 WebJob 会抛出异常。
我必须做的解决方法如下:
- dotnet build(解决方案 - 发布配置)
- dotnet publish(仅限 WebJobs - 不要 Zip)
- dotnet publish(仅限 Web 项目 - 不要压缩)
- 将 WebJob 数据从发布复制到 Web 项目目录 \App_Data\jobs\continuous\ 目录
- 压缩 Web 项目发布目录(这是部署的内容)
我的诚实意见是,当我在发布模式下构建 webjob 项目时,该过程应该转换清单以在本地查找任何引用的库,然后再尝试在运行时查找它们。
我们有一个连续的 WebJob,它是用 .NET Core 2.x 编写的,并且在过去几周 运行 一直很好。最近有人对此 WebJob 进行了一些更改,并引入了第 3 方 NuGet 包。现在,我无法启动 WebJob,因为它无法找到第 3 方库依赖项之一。
这是错误信息:
D:\local\Temp\jobs\continuous\Temp1\oitdncff.sfg>dotnet Temp1.dll
Error:
An assembly specified in the application dependencies manifest (Temp1.deps.json) was not found:
package: 'System.Drawing.Common', version: '4.5.0-preview1-25914-04'
path: 'runtimes/win/lib/netcoreapp2.0/System.Drawing.Common.dll'
我在谷歌搜索这个问题时尝试了一些我发现的东西。这是 csproj 文件中的 PropertyGroup 和 ItemGroup(NuGet 包):
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<ApplicationIcon />
<StartupObject>Temp1.Program</StartupObject>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>latest</LangVersion>
<Version>1.0.0.0</Version>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="AsyncEnumerator" Version="2.1.0" />
<PackageReference Include="EPPlus.Core" Version="1.5.4" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.5.1" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.5.1" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="3.0.0-beta4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
根据网上的建议,我添加了行
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
和
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
有依赖关系的相关包是EPPlus.Core
我已确认库 System.Drawing.Common
确实存在于我们的 Azure Web 应用程序的应用程序文件夹中,但是当 WebJob 启动时,它忽略了该文件并在运行时查找 (GAC ) 和失败。
更新:
我意识到 EPPlus.core 包不是官方的,所以切换到官方包希望这能解决错误。同样的错误,但 System.Drawing.Common version: 4.5.0-preview1-26216-02
我已手动将 System.Drawing.Common version: 4.5.0-preview2-26406-04
的 NuGet 包添加到项目中,这消除了原始错误,但随后我开始收到无法找到 Microsoft.Win32.SystemEvents version: 4.5.0-preview2-26406-04
的错误。该库依赖于 System.Drawing.Common
。
我尝试做与上面相同的事情,并将 Microsoft.Win32.SystemEvents version: 4.5.0-preview2-26406-04
的 NuGet 包直接添加到项目中,但这次错误没有消失。
进一步更新:
经过更多搜索后,我发现了一个帖子
首先,我想声明,截至今天,据我所知,Azure WebJobs 并非 100% 支持 .NET Core(如果我错了,请随时纠正我),但是有很多文章和有关如何使它们发挥作用的帖子。
以下是我为解决上述问题而采取的解决方案,虽然我觉得这并不优雅,但我确实觉得 Microsoft 做了一些奇怪的事情,大多数开发人员认为这不是正确的方法。
我遇到问题的原因是当我构建(调试或发布)时,清单文件始终指向运行时 (GAC)。 运行 在我的本地盒子上从来都不是问题,因为可以找到文件。奇怪的是,在发布模式下构建时,所有文件都被复制到 bin 文件夹,但清单仍然告诉程序查看运行时而不是使用本地副本。当这被推送到 WebJob 本身时,这些文件在运行时不存在,因此 WebJob 会抛出异常。
我必须做的解决方法如下:
- dotnet build(解决方案 - 发布配置)
- dotnet publish(仅限 WebJobs - 不要 Zip)
- dotnet publish(仅限 Web 项目 - 不要压缩)
- 将 WebJob 数据从发布复制到 Web 项目目录 \App_Data\jobs\continuous\ 目录
- 压缩 Web 项目发布目录(这是部署的内容)
我的诚实意见是,当我在发布模式下构建 webjob 项目时,该过程应该转换清单以在本地查找任何引用的库,然后再尝试在运行时查找它们。