0

I have a webapi app made using rider and asp net core 3.1

Under the Properties folder of my project I have a launchSettings.json that seems the place to add all the information to make my app launch the way I like. Here is my launchSettings.json:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": false
  },
  "profiles": {
    "AuthWebApi": {
      "commandName": "Project",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://0.0.0.0:5137"
    }
  }
}

My problem comes when I want to publish my app. Everything goes well but when I execute my dll with donet, it starts on port 5000 instead of the one I configured in launchSettings.json (5137). I guess this is because the configuration I defined takes effect only in debug. But I'm not sure.

I know I could use the url param when running my binary to make it listen on the port I want but I prefer to have all configuration in the launchsettings.json.

Is this possible? How do you handle your launch settings for a publisher app?

Notbad
  • 5,936
  • 12
  • 54
  • 100

2 Answers2

2

launchSettings.json is used only for development environment:

The launchSettings.json file:

  • Is only used on the local development machine.
  • Is not deployed.
  • contains profile settings.

To set up production/staging environment you can use environment variables and/or configuration files.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • Thanks, could you expand a bit on what are these configuration files? Are files specific to asp net core? – Notbad Jul 03 '20 at 22:54
  • @Notbad [here](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1) you can read about configuration is ASP Core. – Guru Stron Jul 03 '20 at 22:58
  • 1
    Ok, thanks. I knew this files, just wanted to make sure we were talking about the same ones ;) – Notbad Jul 03 '20 at 23:01
  • @Notbad Also for urls [this](https://stackoverflow.com/questions/44117840/can-i-set-listen-urls-in-appsettings-json-in-asp-net-core-2-0-preview) should work. – Guru Stron Jul 03 '20 at 23:10
0

There is also an answer for your question here

You can use following command:

dotnet run --urls=http://localhost:5001/
Hassan Monjezi
  • 1,060
  • 1
  • 8
  • 24