launchProfile.json 中的“dotnet run”默认配置文件设置是什么?

问题描述 投票:0回答:3

根据 MS 文档: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run?source=docs

还有这个SO线程 如何确定asp.net core应用程序将运行在哪个环境?

我仍然无法确定 launchProfile.json 中的

dotnet run
默认配置文件设置是什么?

谢谢,皮奥特

c# .net development-environment
3个回答
30
投票
dotnet run --launch-profile "SampleApp"

此方法目前仅支持使用 .NET 6 的 Kestrel 配置文件。

--launch-Profile
仅支持
"SampleApp"
,其中
commandName
"Project"
文件中定义为
launchSettings.json

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:59481",
      "sslPort": 44308
    }
  },
  "profiles": {
    "SampleApp": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7152;http://localhost:5105",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

dotnet run
的默认配置文件将是
launchSettings.json
文件中的第一个配置文件,无论配置文件名称如何,也无论是否指定启动配置文件。这也写在 MS Learn 文档中,例如 .NET 8.0 Envinroments 中的 ASP.NET Core 和 .NET Aspire。 我认为默认设置只是列表中的第一个配置文件。


11
投票

默认启动配置文件的名称与您正在运行的项目相同。因此,如果您的项目名为

WebApi

3
投票

WebApi

 
中名为
Properties/launchSettings.json
的配置文件。 如果您使用
dotnet run --project <Projectname>
启动,那么最后一部分是相关的。

© www.soinside.com 2019 - 2024. All rights reserved.