我已经关注了这个tutorial将 .NET Core 控制台应用程序部署到 Azure Web 服务 WebJob。
我的应用程序在本地运行没有任何问题(使用 dotnet 1.0.0-preview2-003131),但是当我尝试从 Azure 控制台运行它时,出现以下错误:
Failed to load the dll from
[D:\local\VirtualDirectory0\site\wwwroot\app_data\jobs\triggered\PopcornExportWebJob\hostpolicy.dll]
, HRESULT: 0x800700C1**An error occurred while loading required library hostpolicy.dll from
[D:\local\VirtualDirectory0\site\wwwroot\app_data\jobs\triggered\PopcornExportWebJob]
Azure .Net的版本是1.0.0-rc4-004771,hostpolicy.dll文件与我本地使用的相同。事实上,当我从 Azure 下载部署的 zip 并在本地运行它时,它工作正常。但在Azure环境上失败了。
另外,这是我的project.json:
{
"publishOptions": {
"include": [
"run.cmd"
]
},
"buildOptions": {
"emitEntryPoint": true,
"copyToOutput": "appsettings.json"
},
"copyright": "bbougot",
"dependencies": {
"FubarCoder.RestSharp.Portable.Core": "4.0.7",
"FubarCoder.RestSharp.Portable.HttpClient": "4.0.7",
"Microsoft.ApplicationInsights.AspNetCore": "2.0.0",
"Microsoft.Extensions.Configuration": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.DependencyInjection": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.NETCore.App": "1.1.0",
"MongoDB.Driver": "2.4.2",
"StructureMap.Microsoft.DependencyInjection": "1.3.0"
},
"description": "Popcorn Api Exporter",
"frameworks": {
"netcoreapp1.1": {
"imports": [
"portable-net45+win8"
]
}
},
"runtimes": {
"win10-x64": {}
},
"scripts": {
"postpublish": [ "7za.exe a -tzip PopcornExport.zip .\\bin\\Release\\PublishOutput\\*",
".\\WAWSDeploy.exe .\\PopcornExport.zip .\\popcornexport.PublishSettings /t app_data\\jobs\\triggered\\PopcornExportWebJob /v /d" ]
},
"title": "PopcornExport",
"version": "1.0.0-*"
}
我必须添加节点运行时(win10-x64,否则应用程序无法在本地运行)。但是,Azure Web 服务在 Windows Server 2012 上运行。这可能是一个问题吗?
我错过了什么?
最佳答案
好吧,我已经明白了。
如果要将 dotnet core 应用部署到 Azure Web 服务,请在 32 位平台模式下运行应用时包含运行时“win7-x86”。
对于 Visual Studio 2015 解决方案,您的project.json 应包括:
"runtimes": {
"win10-x64": {},
"win7-x86": {} //IMPORTANT FOR AZURE DEPLOY
},
或者,如果您已经迁移到 Visual Studio 2017,您的 .csproj 应将其包含在 PropertyGroup 中:
<RuntimeIdentifiers>win10-x64;win7-x86</RuntimeIdentifiers>
此外,您的发布配置文件应包含相同的内容:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PublishDir>bin\Release\PublishOutput</PublishDir>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier> // IMPORTANT
</PropertyGroup>
</Project>
关于c# - 将 .NET Core 控制台应用程序部署到 Azure WebJobs 时加载 hostpolicy.dll 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42396782/