【问题标题】:.NET Core project not reading launchSettings.json.NET Core 项目未读取 launchSettings.json
【发布时间】:2020-06-02 19:27:47
【问题描述】:

我有一个使用 .NET Core 3.1 的网络应用程序,一切正常:

Now listening on: http://localhost:5000
Now listening on: https://localhost:5001

唯一的问题是这些端口不是我的 launchSettings.json 文件中指定的端口。

一个小故事:最初这两个 localhost 都是在 launchSettings.json 文件中指定的,然后我去掉了 5001,它只启动了 5000,这正是我想要的。

突然间 5001 又回来了,无论我在 launchSettings.json 文件中进行什么更改,它都会恢复为 5000 和 5001,我删除了 launchSettings.json 文件,它仍然侦听相同的地址/端口,我不知道它从哪里读来的。

仅供参考,这是我当前的 launchSettings.json 文件,它应该是从 StudentsWebApp 配置文件中读取的:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:61527",
      "sslPort": 44325
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "StudentsWebApp": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "applicationUrl": "http://localhost:5005",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

这就是我运行网络应用程序的方式,只需单击启动项目的播放按钮或 F5:

为什么它绕过了我的 launchSettings.json 文件?

【问题讨论】:

  • 你是如何运行你的应用程序的? launchSettings.json 基本上由您的 IDE 使用,而不是由运行时本身使用。
  • 添加了我运行网络应用程序的方式。

标签: .net-core settings


【解决方案1】:

经过更多搜索后,我得到了它的工作:

在项目属性 > 调试选项卡 > 应用程序参数中添加它

--urls=http://localhost:5000/

这样它会准确读取您想要的地址/端口。

【讨论】:

    猜你喜欢
    • 2019-02-25
    • 2020-03-20
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多