dotnet / dotnet/vscode-csharp

Use applicationUrl from launchSettings.json when launching browser, like VS

Open
#2,868 4 comments 0 reactions 0 assignees View on GitHub
Debugger OmniSharp
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
18h 40m
Merged PRs (30d)
31

Description

## Issue Description ##

I'm using Kestrel for local development. During a debugging session, the URL that's being passed to the browser (with `${auto-detect-url}` in `launch.json`) is always based on one of the endpoints configured for Kestrel, and is always using `localhost` as the hostname. E.g. if my Kestrel configuration looks like this:

```
{
"Kestrel": {
"EndPoints": {
"Https": {
"Url": "https://my.domain.local:4430"
}
},
"Certificates": {
"Default": {
"Subject": "*.domain.local",
"Store": "Root",
"Location": "LocalMachine",
"AllowInvalid": true
}
}
}
}
```

The URL that's passed to the browser seems to be the one from the Kestrel endpoint, with `my.domain.local` replaced with `localhost`. I believe that's how Kestrel ends up using them for its purposes (it only cares about the port it needs to bind to), but for debugging purposes, I actually want to browse to `https://my.domain.local:4430` instead of `https://localhost:4430`, since my SSL cert is for the former. I know there's a dev cert for localhost, but in my use case the hostname matters to the application, so I can't use a URL with localhost in it.

Now, my `launchSettings.json` file looks like this:

```
{
"profiles": {
"MyProject": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://my.domain.local:4430"
}
}
}
```

Visual Studio uses the value of `applicationUrl` when it starts the browser after I hit F5, but VS Code doesn't, and I think it'd be good to match the behavior. Furthermore, it seems like the only option to launch the browser with a non-localhost URL.

## Steps to Reproduce ##

In any project, set `applicationUrl` in `launchSettings.json` to a non-localhost URL, and start a debugging session in VS Code.

## Expected Behavior ##

The browser navigates to the URL specified in `applicationUrl`.

## Actual Behavior ##

The browser navigates to a URL that matches one of the endpoints configured for Kestrel, always using `localhost` instead of whatever URL was written in the Kestrel endpoint configuration.

## Logs ##

A bit of relevant log from the debugging session:

```
2019-02-21T00:22:29.209|DEBUG||Loaded hosting startup assembly MyProject |Microsoft.AspNetCore.Hosting.Internal.WebHost|assemblyName=MyProject

Hosting environment: Development

Content root path: F:\path\to\my\project\MyProject

Launching browser (cmd.exe /C start https://localhost:4430)

Now listening on: https://[::]:4430

Application started. Press Ctrl+C to shut down.
```

### OmniSharp log ###
```
Starting OmniSharp server at 2/21/2019, 12:38:54 AM
Target: f:\path\to\my\project\MySolution.sln

OmniSharp server started.
Path: C:\Users\alexv\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\OmniSharp.exe
PID: 11204

[info]: OmniSharp.Stdio.Host
Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 3 MSBuild instance(s)
1: Visual Studio Professional 2017 15.9.28307.344 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
2: Visual Studio Enterprise 2019 16.0.28602.52 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin"
3: StandAlone 15.0 - "C:\Users\alexv\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: Visual Studio Professional 2017 15.9.28307.344 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
[info]: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in 'f:\path\to\my\project'.
[info]: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
Detecting projects in 'f:\path\to\my\project\MySolution.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
Queue project update for 'f:\path\to\my\project\MyProject\MyProject.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'f:\path\to\my\project'.
[info]: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: f:\path\to\my\project\MyProject\MyProject.csproj
[info]: OmniSharp.WorkspaceInitializer
Configuration finished.
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location 'f:\path\to\my\project' on host 17172.
[info]: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'f:\path\to\my\project\MyProject\MyProject.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
Adding project 'f:\path\to\my\project\MyProject\MyProject.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
Update project: MyProject
```

### C# log ###
Empty

## Environment information ##

**VSCode version**: 1.31.1
**C# Extension**: 1.17.1

Dotnet Information
.NET Core SDK (reflecting any global.json):
Version: 2.2.101
Commit: 236713b0b7

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.101\

Host (useful for support):
Version: 2.2.0
Commit: 1249f08fed

.NET Core SDKs installed:
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.503 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009426 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009472 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions

|Extension|Author|Version|
|---|---|---|
|application-insights|VisualStudioOnlineApplicationInsights|0.4.2|
|azure-account|ms-vscode|0.8.0|
|azurecli|ms-vscode|0.4.2|
|azurerm-vscode-tools|msazurermtools|0.4.2|
|bower|donjayamanne|0.0.3|
|csharp|ms-vscode|1.17.1|
|debugger-for-chrome|msjsdiag|4.11.2|
|docker-explorer|formulahendry|0.1.6|
|dotenv|mikestead|1.0.1|
|EditorConfig|EditorConfig|0.13.0|
|githistory|donjayamanne|0.4.6|
|gitignore|codezombiech|0.6.0|
|gitlens|eamodio|9.5.1|
|LiveServer|ritwickdey|5.5.1|
|material-icon-theme|PKief|3.6.3|
|mssql|ms-mssql|1.4.0|
|PowerShell|ms-vscode|1.11.0|
|python|ms-python|2019.1.0|
|rest-client|humao|0.21.1|
|theme-dracula|dracula-theme|2.16.0|
|vscode-azureappservice|ms-azuretools|0.12.0|
|vscode-azurefunctions|ms-azuretools|0.14.0|
|vscode-docker|PeterJausovec|0.5.2|
|vscode-eslint|dbaeumer|1.8.0|
|vscode-markdownlint|DavidAnson|0.24.0|
|vscode-nginx|shanoor|0.6.0|
|vscode-proto3|zxh404|0.2.2|
|vscode-pull-request-github|GitHub|0.4.0|
|vscode-yaml|redhat|0.3.0|
|vsliveshare|ms-vsliveshare|0.3.1225|
|xml|DotJoshJohnson|2.4.0|;

Contributor guide

Open the contributing guide

Research direction

Start by tracing how ${auto-detect-url} is resolved during a debugging session and how launchSettings.json is read, using the reported launch.json and applicationUrl configuration. Reproduce the issue with a non-localhost applicationUrl and compare the browser URL with the expected value; done means the browser navigates to applicationUrl rather than the Kestrel-derived localhost URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.