4.8 — launchSettings.json¶
← Roadmap · Section: 4. Fundamentals and Application Startup Prev: 4.7 Environments · Next: 4.9 Kestrel vs IIS vs HTTP.sys
Markers: ⚠️ · Confidence: 🔴 · Last reviewed: —
TL;DR¶
launchSettings.json tells your IDE or dotnet run how to start the app on your own
machine — which URL, which environment, which browser.
- It lives in
Properties/and is development-only. It is never published and has no effect on a deployed application. - It is the usual place
ASPNETCORE_ENVIRONMENT=Developmentgets set locally. - Do not put secrets in it. It is committed to source control.
Definitions¶
| Term | What it is | What it means |
|---|---|---|
launchSettings.json |
a JSON file | Lives in Properties/. Describes how to launch the app locally. Development only. |
| Profile | a named launch configuration | One way of starting the app — the dropdown next to the run button in your IDE. |
commandName |
a profile setting | Which launcher to use: Project (Kestrel), IISExpress, Executable, Docker. |
applicationUrl |
a profile setting | The URLs to listen on locally. Semicolon-separated. |
environmentVariables |
a profile setting | Variables set for that profile. This is where the environment name is set. |
launchBrowser |
a profile setting | Whether to open a browser on start. |
dotnetRunMessages |
a profile setting | Whether to print build/run progress messages. |
| IIS Express | a dev-only web server | A lightweight IIS for local development on Windows. Not for production. |
ASPNETCORE_URLS |
an environment variable | The deployed equivalent of applicationUrl. This one does apply in production. |
The concept¶
What it is for¶
When you press F5, or run dotnet run, something has to decide:
- Which port should the app listen on?
- Which environment is this?
- Should a browser open?
launchSettings.json answers those questions. It is a developer convenience file, and
nothing more.
A picture: it is the preset on your car seat. It remembers how you like things when you get in. It has no effect on how the car behaves when someone else drives it, and it is certainly not part of the engine.
⚠️ The single most important fact¶
It is never deployed and has no effect in production.
dotnet publish does not copy it. The file sits in Properties/ next to your project, gets
committed to git, and is used only by Visual Studio, Rider, VS Code and dotnet run.
This trips people up constantly:
"I set the environment to Staging in
launchSettings.jsonbut production is still running as Production."
Of course it is. The file was never deployed. Production takes its environment from a real environment variable set by the hosting platform — 4.7.
How it works¶
The simple version — a typical file¶
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
// Profile 1 — run with Kestrel directly. The usual choice.
"MyApp.Api": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7183;http://localhost:5183",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
// Profile 2 — run behind IIS Express (Windows only)
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
// Profile 3 — run in a container
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"publishAllPorts": true
}
}
}
Each top-level key under profiles is a name you pick, and it appears in the run dropdown of
your IDE.
Running a specific profile from the command line:
The commandName values¶
| Value | What it does |
|---|---|
Project |
Runs your app directly with Kestrel. The normal choice. |
IISExpress |
Runs behind IIS Express. Windows only, and increasingly rare. |
Executable |
Runs an arbitrary executable. |
Docker |
Builds and runs the container. |
Project is what you want by default. It is closest to how the app runs in production —
Kestrel, directly — so local behaviour matches deployed behaviour more closely. IIS Express
introduces a proxy layer that can mask problems, or create ones that only exist locally.
How it actually works — the precedence order¶
applicationUrl is one of several places a URL can come from, and the priority matters when
they disagree:
1. app.Urls / UseUrls() in code ← highest, wins over everything
2. --urls on the command line
3. ASPNETCORE_URLS environment variable
4. applicationUrl in launchSettings ← development only
5. Default (http://localhost:5000) ← lowest
Two practical consequences:
In production, only 1–3 exist. Setting ASPNETCORE_URLS=http://+:8080 in a container is
the standard approach (4.2).
Calling UseUrls() in code overrides everything, which is why hard-coding a URL there
makes the app impossible to configure at deployment time. Avoid it.
Multiple profiles for different scenarios¶
The genuinely useful pattern:
{
"profiles": {
"Normal": {
"commandName": "Project",
"applicationUrl": "https://localhost:7183",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
// Point at a real staging database to reproduce a bug
"Against Staging DB": {
"commandName": "Project",
"applicationUrl": "https://localhost:7183",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ConnectionStrings__Default": "Server=staging-sql;Database=App;..."
}
},
// Verify production-like error handling locally
"Production mode": {
"commandName": "Project",
"applicationUrl": "https://localhost:7183",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
}
}
That third profile is worth having. Production behaviour differs — generic error pages, no Swagger, HSTS enabled — and being able to check it locally catches a class of bug that otherwise only appears after deployment.
Note the double underscore in ConnectionStrings__Default. That is how nested
configuration keys are expressed as environment variables — __ becomes :. See
7.3.
⚠️ Do not put secrets here¶
// ✗ NEVER — this file is committed to git
"environmentVariables": {
"ConnectionStrings__Default": "Server=prod;User=sa;Password=RealPassword123!",
"ApiKeys__Stripe": "sk_live_abc123"
}
launchSettings.json is in source control by default. Anything in it is in your git history
permanently, visible to everyone with repository access, and picked up by secret scanners.
Use User Secrets instead — they live outside the project folder and are never committed:
dotnet user-secrets init
dotnet user-secrets set "ConnectionStrings:Default" "Server=localhost;..."
dotnet user-secrets set "ApiKeys:Stripe" "sk_test_..."
User Secrets are automatically loaded in Development only, which is exactly the right scope. See 7.3 and 17.7.
A pointer to a non-secret staging connection string in a launch profile is fine. Real credentials are not.
The deeper detail — should it be in source control?¶
Yes, usually. It is genuinely useful for a team: everyone gets the same ports, the same profiles, and a new joiner can clone and press F5.
The friction is that it also carries personal preferences — one person wants the browser to open, another does not — so it generates small, noisy diffs.
Some teams gitignore it and provide a launchSettings.json.template instead. That works, at
the cost of every new developer needing a setup step.
The pragmatic answer: commit it, keep it minimal, and never put a secret in it. The personal preferences are a small annoyance; a shared, working default is worth more.
Code¶
A clean file for a typical API project:
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"API": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "scalar/v1",
"applicationUrl": "https://localhost:7183;http://localhost:5183",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"API (production mode)": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "https://localhost:7183",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
}
}
And the deployed equivalent, which does not use this file at all:
# Kubernetes
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Production"
- name: ASPNETCORE_URLS
value: "http://+:8080"
Those two blocks are the real configuration. launchSettings.json is only ever the local
convenience.
Interview questions¶
Q: What is launchSettings.json and when does it apply?
It is a development-only file in the Properties folder that tells your IDE or dotnet run
how to start the application locally — which URLs to listen on, which environment name to set,
whether to open a browser. The critical point is that it is never published, so it has no
effect whatsoever on a deployed application. Production takes its environment and URLs from
real environment variables set by the hosting platform.
Q: Someone changed the environment in launchSettings.json but production is unchanged. Why?
Because the file is not deployed — dotnet publish does not copy it. It only affects local
launches from an IDE or dotnet run. To change the environment in production you set the
ASPNETCORE_ENVIRONMENT variable wherever the app is hosted: an ENV line in the Dockerfile,
an env entry in a Kubernetes manifest, or an application setting in Azure App Service.
Q: Should secrets go in launchSettings.json?
No. It is committed to source control by default, so anything in it enters your git history permanently and is visible to everyone with repository access. For local development secrets the right tool is User Secrets, which store values outside the project folder in your user profile and are loaded automatically in Development only. A pointer to a non-sensitive local or staging resource is fine in a launch profile; real credentials are not.
Q: What is the difference between applicationUrl and ASPNETCORE_URLS?
They set the same thing but in different scopes. applicationUrl is a launch profile setting
that only applies locally, while ASPNETCORE_URLS is a real environment variable that works
everywhere, including in containers and on servers. The precedence runs from code —
app.Urls or UseUrls — down through command-line arguments, then the environment variable,
then launchSettings. Hard-coding URLs in code is worth avoiding because it overrides
everything and makes the app impossible to configure at deployment time.
Traps ⚠️¶
- It is never deployed. Changing it has zero effect on production.
- Secrets in it end up in git history, permanently. Use User Secrets.
UseUrls()in code overrides everything, including the environment variable, making the app unconfigurable at deploy time.- IIS Express behaviour differs from Kestrel. Prefer the
Projectprofile so local matches production more closely. - Nested config keys use double underscores in environment variables:
ConnectionStrings__Default. - Deleting the file is harmless. The app falls back to
http://localhost:5000and Production. dotnet runuses the first profile by default, which may not be the one you expect.
Related¶
- 4.7 Environments — what the environment name actually does
- 4.2 Hosting model —
ASPNETCORE_URLSin containers - 4.9 Kestrel vs IIS — the IIS Express profile
- 7.3 Environment variables and User Secrets — where local secrets belong
- 17.7 Secrets management — the security view
- 24.3 Dockerfile — the deployed configuration