c# - 将 .NET Core 控制台应用程序部署到 Azure WebJobs 时加载 hostpolicy.dll 时出错

标签 c# .net azure asp.net-core azure-webjobs

我已经关注了这个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/

相关文章:

c# - IE Web 驱动程序在 TeamCity Windows Server 2012 上运行速度慢 3-5 倍

sql-server - 了解使用 Azure 数据工厂的专用终结点的托管 VNet

python-3.x - 用于 DataFactory 的 Azure Python SDK 指向特定的 GIT 分支

azure - Azure 应用程序网关中的黑名单客户端 IP

c# - 使用 activemq 请求响应 - 始终发送双重响应

c# - Elasticsearch NEST 和基本搜索查询

c# - button_click 在 TextBox 中按下 Return - ASP.NET

c# - 如何从 C# 将 const char* 传递给 C 函数?

c# - 将属性绑定(bind)到整数

c# - 每秒触发一个事件