In an ASP.NET Core 10 project, what do the profiles in Properties/launchSettings.json configure, which tools apply them, and why don't they reach production?
answer
- a developer-only file
- http and https profiles, commandName Project
- applicationUrl becomes ASPNETCORE_URLS
- dotnet run --launch-profile, --no-launch-profile
- CopyToPublishDirectory Never in the Web SDK
basics
~20 slaunchSettings.json holds named launch profiles (environment variables, application URLs, browser options) that dotnet run, Visual Studio and VS Code apply when starting the app locally. The Web SDK keeps it out of build and publish output, so servers never see it.
solid answer
~40 sThe web templates write an `http` and an `https` profile, each with `commandName: Project`, an `applicationUrl` on a randomly generated port (5000-5300 for HTTP, 7000-7300 for HTTPS) and `environmentVariables` setting `ASPNETCORE_ENVIRONMENT` to `Development`. `dotnet run` uses the first profile whose `commandName` it supports, or the one named with `--launch-profile` (`-lp`), and skips the file with `--no-launch-profile`; it exports `applicationUrl` as `ASPNETCORE_URLS`, sets `DOTNET_LAUNCH_PROFILE`, and lets the profile's variables override inherited ones, while `-e NAME=VALUE` overrides the profile. Visual Studio and VS Code read the same file and act on extras such as `launchBrowser`. The Web SDK adds `Properties/launchSettings*.json` as `None` items with `CopyToOutputDirectory` and `CopyToPublishDirectory` set to `Never`, so a published app started with `dotnet App.dll` knows nothing about it.
code
json · 20 lines{
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7129;http://localhost:5087",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"staging": {
"commandName": "Project",
"applicationUrl": "http://localhost:5088",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
}
}
}
}go deeper
Know that the profiles in launchSettings.json are why the app is Development locally and that the file stays on your machine.
Explain how dotnet run picks a profile, what applicationUrl turns into, and how -e and --no-launch-profile change the result.
Keep secrets and deployment settings out of launch profiles and make sure every value a profile sets is provided again on the server.
Treat the file as shared developer ergonomics, committed and reviewed, and never as a channel for configuration that production depends on.
## What the file is `Properties/launchSettings.json` is a **developer tooling file**. It describes one or more named **launch profiles**: how to start the project, with which environment variables, on which URLs, and whether to open a browser. The app never reads it. A tool that starts the app reads it and turns the chosen profile into process arguments and environment variables. ## What the templates write `dotnet new webapi` in ASP.NET Core 10 writes two profiles and no IIS Express profile: - **`http`**: `commandName: Project`, `dotnetRunMessages: true`, `launchBrowser: false`, an HTTP `applicationUrl`, and `ASPNETCORE_ENVIRONMENT` set to `Development`. - **`https`**: the same, with an HTTPS URL followed by the HTTP one. The port numbers are not fixed: the template engine replaces the placeholder ports with a generated port between 5000 and 5300 for HTTP and between 7000 and 7300 for HTTPS, so two projects on one machine rarely collide. `dotnet new` takes `--exclude-launch-settings` if you want no file at all. ## How dotnet run applies a profile 1. It looks for `Properties/launchSettings.json` next to the project. With `--no-launch-profile` it skips the file entirely. 2. It selects the profile named by `--launch-profile` (`-lp`), matched case-insensitively, or else the **first** profile in file order whose `commandName` it supports. 3. It sets `ASPNETCORE_URLS` from `applicationUrl` and `DOTNET_LAUNCH_PROFILE` to the profile name. 4. It sets every entry of `environmentVariables`, overriding variables the shell already had. 5. It applies `-e NAME=VALUE` options last, so they override the profile. `launchBrowser` and `launchUrl` are kept in the parsed profile, but `dotnet run` itself opens no browser; Visual Studio and other launch tooling act on them. Visual Studio and VS Code with C# Dev Kit read the same file and show the profiles in their launch drop-downs. ## Profile types and other properties `commandName` decides what a profile starts. For `dotnet run` the values are case-sensitive and only two are supported: | `commandName` | What `dotnet run` does | |---|---| | `Project` | builds the project and runs what it produces | | `Executable` | builds, then starts the program named by `executablePath` | Visual Studio understands more values, such as `IISExpress` for older templates, which is one reason a profile can work in the IDE and be skipped by `dotnet run`. A profile can also carry `commandLineArgs`, which `dotnet run` passes to the app unless you supply arguments yourself, so a profile is a convenient way to pin `--environment` or other switches for one local scenario. The SDK's parser also tolerates JSON comments and trailing commas in the file. ## A trap with -e On `dotnet run`, `-e` / `--environment` is the SDK's **environment-variable** option: each value is parsed as `NAME=VALUE`. It is not the hosting environment name. To start in Staging you write one of these: ```bash dotnet run -e ASPNETCORE_ENVIRONMENT=Staging dotnet run --launch-profile staging dotnet run -- --environment Staging ``` The last form passes `--environment Staging` after `--` to the app itself, where the host reads it as a command-line argument. ## Why it never reaches production | Mechanism | Effect | |---|---| | The Web SDK adds `Properties/launchSettings*.json` as `None` items | the file is not compiled, embedded or treated as content | | `CopyToOutputDirectory="Never"` | it is not in `bin/` | | `CopyToPublishDirectory="Never"` | it is not in the `dotnet publish` output | | `dotnet App.dll` and the app host do not read launch profiles | even a hand-copied file would be ignored | So everything a profile sets, the environment, URLs and any other variables, must be set again by whatever starts the app in production: a service definition, a container's environment, IIS `web.config`, or command-line arguments. ## Good uses and bad uses - **Good**: extra local profiles, such as a `staging` profile to reproduce a staging bug against local services, or one with a different `applicationUrl`. - **Good**: committing the file so the team shares the same local ports and profiles. - **Bad**: secrets in `environmentVariables`; the file is usually committed to source control, and secrets belong in user secrets or a vault. - **Bad**: treating it as deployment configuration; nothing in it exists on the server.
- If launchSettings.json sets ASPNETCORE_ENVIRONMENT=Development and the shell already exports Staging, which does dotnet run use?Development. dotnet run sets the profile's environmentVariables on the child process after inheriting the shell's variables, so the profile wins. Only a -e NAME=VALUE option, applied after the profile, or --no-launch-profile lets the shell's value through.
- Why might dotnet run report a different port than the one in the launch profile?applicationUrl becomes ASPNETCORE_URLS, which an explicit setting can still override: an ASPNETCORE_URLS entry in the profile's environmentVariables or from -e takes precedence, and code or configuration that sets Kestrel endpoints explicitly overrides the URLs too.
- launchSettings.json is copied to the publish folder and applied on the server.
- dotnet run -e Staging sets the hosting environment to Staging.
- Variables already set in the shell beat the launch profile's environmentVariables.
- Visual Studio is the only tool that reads launchSettings.json.
- launchBrowser makes dotnet run open a browser window.