Azure WebJob 脚手架失败

Azure WebJob Scaffolding failed

WebJob 在我的本地计算机上 运行。部署到应用服务后,WebJob 的状态始终为 "Restart pending",并附有以下日志。

[01/13/2020 16:04:03 > 8578d0: SYS INFO] Status changed to Starting
[01/13/2020 16:04:03 > 8578d0: SYS INFO] WebJob singleton setting is False
[01/13/2020 16:04:05 > 8578d0: SYS INFO] Run script 'dotnet-aspnet-codegenerator-design.exe' with script host - 'WindowsScriptHost'
[01/13/2020 16:04:05 > 8578d0: SYS INFO] Status changed to Running
[01/13/2020 16:04:06 > 8578d0: INFO] [Trace]: Command Line: 
[01/13/2020 16:04:06 > 8578d0: INFO] [Trace]:    at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
[01/13/2020 16:04:06 > 8578d0: INFO]    at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
[01/13/2020 16:04:06 > 8578d0: INFO]    at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.<>c__DisplayClass4_0.<<Execute>b__0>d.MoveNext()
[01/13/2020 16:04:06 > 8578d0: ERR ] Scaffolding failed.
[01/13/2020 16:04:06 > 8578d0: ERR ] Value cannot be null.
[01/13/2020 16:04:06 > 8578d0: ERR ] Parameter name: String
[01/13/2020 16:04:07 > 8578d0: SYS INFO] Status changed to Success
[01/13/2020 16:04:07 > 8578d0: SYS INFO] Process went down, waiting for 60 seconds
[01/13/2020 16:04:07 > 8578d0: SYS INFO] Status changed to PendingRestart

由于脚手架依赖于 NuGet,这里是为项目定义的 NuGet 依赖项

  <ItemGroup>
    <PackageReference Include="EntityFramework" Version="6.2.0" />
    <PackageReference Include="log4net" Version="2.0.8" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.4.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="System.IO.Compression" Version="4.3.0" />
    <PackageReference Include="System.Spatial" Version="5.8.4" />
    <PackageReference Include="Microsoft.Data.Edm" Version="5.8.4" />
    <PackageReference Include="Microsoft.Data.OData" Version="5.8.4" />
    <PackageReference Include="Microsoft.Data.Services.Client" Version="5.8.4" />
    <PackageReference Include="Microsoft.WindowsAzure.ConfigurationManager" Version="3.2.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="3.0.14" />
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.14" />
    <PackageReference Include="Microsoft.Azure.KeyVault.Core" Version="1.0.0" />
    <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>

和项目定义

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <GenerateSupportedRuntime>false</GenerateSupportedRuntime>  
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Platforms>AnyCPU;x64</Platforms>
    <RootNamespace>xxx.WebJob</RootNamespace>
  </PropertyGroup>

与 Azure.WebJobs 2.x 有同样的问题,升级到 3.x 但没有积极结果。 WebJob 的主要方法

public static async Task Main()
{
    var hostBuilder = new HostBuilder()
        .ConfigureWebJobs(conf => conf.AddAzureStorage())
        // custom name resolver to pickup runtime information (dev/test/prod)
        .ConfigureServices(services => services.AddSingleton<INameResolver, AppSettingsResolver>())
        // set the config file to read azure configurations.
        .ConfigureAppConfiguration((context, builder) => builder.SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddEnvironmentVariables());

    using (var host = hostBuilder.Build())
        await host.RunAsync();
}

在我看来,这是因为您应该使用 .NET Core,但 TargetFramework 是 Net Framework 4.7.2。

能否尝试替换以下 属性 群组:

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <GenerateSupportedRuntime>false</GenerateSupportedRuntime>  
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Platforms>AnyCPU;x64</Platforms>
    <RootNamespace>xxx.WebJob</RootNamespace>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>