在将.NET Core控制台应用程序部署到Azure WebJobs

时间:2017-02-22 16:15:53

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

我已按照此tutorial将.NET Core控制台应用程序部署到Azure Web Service WebJob。

我的应用程序在本地运行没有任何问题(使用dotnet 1.0.0-preview2-003131 )但是当我尝试从Azure控制台运行它时出现以下错误:

无法从[D:\ local \ VirtualDirectory0 \ site \ wwwroot \ app_data \ jobs \ triggered \ PopcornExportWebJob \ hostpolicy.dll]加载dll,HRESULT:0x800700C1

从[D:\ local \ VirtualDirectory0 \ site \ wwwroot \ app_data \ jobs \ triggered \ triggered \ PopcornExportWebJob]

加载所需的库hostpolicy.dll时发生错误

Azure dotnet的版本为 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上运行。这可能是一个问题吗?

我错过了什么?

3 个答案:

答案 0 :(得分:13)

好吧,我已经明白了。

如果要将dotnet核心应用程序部署到Azure Web Service,请在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>

答案 1 :(得分:1)

如果您的应用程序的位数与您的App Service的位数不匹配(例如,将64位部署发布到以32位模式运行的App Service),则可能会发生此错误。

要解决此问题,我必须将位数更改为Azure中的正确设置:

enter image description here

要与我在VS中发布个人资料的精确度相匹配:

enter image description here

答案 2 :(得分:0)

当我从以下位置更改run.cmd的内容时,我不再看到此错误

dotnet MyWorker.dll

MyWorker.exe