Running AppHost through visual studio adds rogue `ASPNETCORE_URLS` env var
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
When I run my app host through Visual studio, the `ASPNETCORE_URLS` environment variable gets somewhere, but it doesn't show up in the env var list on the dashboard.
If however you run the app through `dotnet run`, this env var doesn't show up.
I am trying to configure the port of my app via `ASPNETCORE_HTTPS_PORTS`, but the rogue `ASPNETCORE_URLS` is trumping that config.
```
[2026-03-09 13:17:46.638 +00:00 [WRN] Overriding HTTP_PORTS '' and HTTPS_PORTS '60397'. Binding to values defined by URLS instead 'https://localhost:5001/;http://localhost:5000/'. {EventId={Id=15}, SourceContext="Microsoft.AspNetCore.Hosting.Diagnostics", ThreadId=1, AssemblyVersion="0.0.1.0"}
[2026-03-09 13:17:46.733 +00:00 [INF] Now listening on: https://localhost:5001/ {EventId={Id=14, Name="ListeningOnAddress"}, SourceContext="Microsoft.Hosting.Lifetime", ThreadId=1, AssemblyVersion="0.0.1.0"}
```
### Expected Behavior
`ASPNETCORE_URLS` shouldn't be being set at all.
### Steps To Reproduce
Create a project resource, and don't start it with a launch profile.
This project starts via `dotnet run`, but if you start via Visual Studio, it binds to port 5000 / 50001 instead.
```cs
var testEndpoint = builder
.AddProject("resource", x => x.ExcludeLaunchProfile = true)
testEndpoint
.WithHttpsEndpoint(env: "ASPNETCORE_HTTPS_PORTS")
.WithHttpHealthCheck(path: "/swagger/index.html", endpointName: "https");
```
### Exceptions (if any)
_No response_
### .NET Version info
### Anything else?
You can work around this by explicitly passing an empty value for `ASPNETCORE_URLS`
```
.WithEnvironment("ASPNETCORE_URLS", "") // If running in VS, it helpfully tries to add a default value, which ends up trumping the `ASPNETCORE_HTTPS_PORTS`
```
Contributor guide
Assessment
This issue has not been assessed yet.