Asp.net core ASP.NET核心发布到Azure(暂存)

Asp.net core ASP.NET核心发布到Azure(暂存),asp.net-core,asp.net-core-webapi,Asp.net Core,Asp.net Core Webapi,VS 2019 ASP.NET核心3.1 我已经在本地开发了一个Web应用程序,现在我准备部署到Azure登台环境 我的Web应用程序最初是.Net(不是Core),部署它时没有问题 如何告诉部署过程使用“暂存”环境 My launchSettings.json包含以下内容: { "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication

VS 2019 ASP.NET核心3.1

我已经在本地开发了一个Web应用程序,现在我准备部署到Azure登台环境

我的Web应用程序最初是.Net(不是Core),部署它时没有问题

如何告诉部署过程使用“暂存”环境

My launchSettings.json包含以下内容:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:59000",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
我有一个appSettings.Staging.json指向临时数据库

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Warning"
    }
  },

  "ConnectionStrings": {
    "DbConnection": "Data Source=myapp.database.windows.net;Initial Catalog=MyAppCoreStaging;user id=myappstepadmin;password=mypassword;MultipleActiveResultSets=True"
  }
}
但我不知道如何告诉它在部署时使用暂存

在我部署时,浏览器在页面上启动,我得到:

HTTP Error 500.30 - ANCM In-Process Start Failure
Common solutions to this issue:
The application failed to start
The application started but then stopped
The application started but threw an exception during startup
Troubleshooting steps:
Check the system event log for error messages
Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect
For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265

是否需要在Azure上配置某些内容才能使用登台?

由于您正在部署到Azure,并且没有指定使用CI/CD管道作为发布方法,因此我假设您使用的是直接在Visual Studio中从Azure portal提供的发布配置文件

在发布对话框中,单击编辑->设置->配置并选择阶段

在Program.cs中,您的
CreateWebHostBuilder
(假设您使用的是ASP.NET Core 3.0+;2.2也可以,但不是
IWebHostBuilder
),您可以指定appsettings文件应取决于您的解决方案配置:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseEnvironment(Environment);

由于您正在部署到Azure,并且没有指定使用CI/CD管道作为发布方法,因此我假设您使用的是直接在Visual Studio中从Azure portal提供的发布配置文件

在发布对话框中,单击编辑->设置->配置并选择阶段

在Program.cs中,您的
CreateWebHostBuilder
(假设您使用的是ASP.NET Core 3.0+;2.2也可以,但不是
IWebHostBuilder
),您可以指定appsettings文件应取决于您的解决方案配置:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseEnvironment(Environment);

如果您使用构建管道,您应该看看这个

steps:
- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: true
    arguments: '-o $(build.artifactstagingdirectory) /p:EnvironmentName=Staging'

如果您使用构建管道,您应该看看这个

steps:
- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: true
    arguments: '-o $(build.artifactstagingdirectory) /p:EnvironmentName=Staging'

谢谢你的快速回复。我稍后会调查,看看是否有帮助。这是我第一次这样做。我已经创建了一个暂存解决方案配置,但是我应该在哪里设置STAGE pre-processor指令,以便在使用暂存解决方案配置时应用它?预处理器指令
STAGE
就是这样调用的,因为这是解决方案配置的名称。使用
#elif STAGING
而不是teadok。正在取得进展,感谢您的快速响应。我稍后会调查,看看是否有帮助。这是我第一次这样做。我已经创建了一个暂存解决方案配置,但是我应该在哪里设置STAGE pre-processor指令,以便在使用暂存解决方案配置时应用它?预处理器指令
STAGE
就是这样调用的,因为这是解决方案配置的名称。使用
#elif STAGING
而不是teadok。正在取得进展,谢谢