首页 > 解决方案 > 运行应用程序时在 VSCode 中的 ASP.NET Core 应用程序中启动特定 URL

问题描述

(如果重要的话,可以在 Mac 上运行。)

在 Visual Studio 中,您可以在运行或调试 ASP.NET Core 项目时使用此方法启动特定 URL。使用了 launchUrl 属性。这是一个示例 launchSettings.json 文件:

{
  "profiles": {
    "MyProjectName": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "customstartupurlgoeshere/?id=theanswertotheuniverse",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}

VS Code 中的类比是什么?我读到 VS Code 忽略了 launchSettings.json 文件。

标签: c#asp.net-corevisual-studio-codevscode-settings

解决方案


VSCode.vscode/launch.json在启动程序时进行配置。

使用了 launchUrl 属性.... VS Code 中的类比是什么?

您可以更改args参数以接受 的参数--urls。例如,如果你想让红隼听6001/ 6000

“配置”:[
    {
        "name": ".NET Core Launch (web)",
        “类型”:“coreclr”,
        “请求”:“启动”,
        "preLaunchTask": "构建",
        "程序": "${workspaceFolder}/bin/Debug/netcoreapp3.0/App.dll",
        "args": ["--urls","https://localhost:6001;http://localhost:6000"],
        "cwd": "${workspaceFolder}",
        “stopAtEntry”:假,
        “serverReadyAction”:{
            "action": "openExternally",
            “模式”:“^\\s*现在正在监听:\\s+(https?://\\S+)”
        },
        “环境”:{
            "ASPNETCORE_ENVIRONMENT": "发展"
        },
        “源文件映射”:{
            "/Views": "${workspaceFolder}/Views"
        }
    },

推荐阅读