dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.17k stars 4.72k forks source link

Project created with dotnet new wasmbrowser ignores the launchSettings.json in Visual Studio #108585

Closed dlemstra closed 2 weeks ago

dlemstra commented 2 weeks ago

Description

After running:

dotnet workload install wasm-tools
dotnet workload install wasm-experimental

and creating a project with dotnet new wasmbrowser the project seems to ignore the launchSettings.json file that is included in the project that was created. The file contains the following line:

{
  "profiles": {
      "TestDebug": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:7085;http://localhost:5200",
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
      }
  }
}

But when the application starts the following is shown:

WasmAppHost --use-staticwebassets --runtime-config C:\Projects\TestDebug\bin\Debug\net9.0\TestDebug.runtimeconfig.json

App url: http://127.0.0.1:60925/
App url: https://127.0.0.1:60926/
Debug at url: http://127.0.0.1:60925/_framework/debug
Debug at url: https://127.0.0.1:60926/_framework/debug

And when starting the project inside Visual Studio the browser is also not launched. With a Blazor project this needs to be done to attach the debugger inside Visual Studio to the debugger of the browser but that does not seem to happen here.

Reproduction Steps

See description

Expected behavior

That the launch settings are used and the project can be debugged inside Visual Studio when starting the project.

Actual behavior

Unable to change the launch port or debug the application with Visual Studio.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

.NET 9.0.100-rc.1.24452.12 Visual Studio 2022 Preview (17.20.0 Preview 2.1)

dotnet-policy-service[bot] commented 2 weeks ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 2 weeks ago

Tagging subscribers to this area: @thaystg See info in area-owners.md if you want to be subscribed.

maraf commented 2 weeks ago

Thank you for the report! It was already fixed in https://github.com/dotnet/runtime/pull/107392 and will be included in RC2. I'm going to close the issue now, feel free to reopen it if you face the problem in RC2 or later.

dlemstra commented 2 weeks ago

Does that fix also resolve the issue of launching the browser and debugging the application inside Visual Studio or is this just the ports?

maraf commented 2 weeks ago

Also launching and debugging from VS, it was all connected.

dlemstra commented 1 week ago

This issue was resolved and debugging now works again in this test application. Thanks for fixing this @maraf. I did notice something interesting in our application that does something similar. We were using Microsoft.NET.Sdk.BlazorWebAssembly as the project SDK instead of Microsoft.NET.Sdk.WebAssembly and that results in the following failure:

WasmAppHost --use-staticwebassets --runtime-config C:\Projects\TestDebug\bin\Debug\net9.0\TestDebug.runtimeconfig.json
Error: Cannot find runtime config at C:\Projects\TestDebug\bin\Debug\net9.0\TestDebug.runtimeconfig.json

Not sure if this is by design so I though I would mention that here.

And the error message in Visual Studio also send me in the wrong direction: Image

maraf commented 1 week ago

If you are using Microsoft.NET.Sdk.BlazorWebAssembly you should include Microsoft.AspNetCore.Components.WebAssembly.DevServer package reference (as Blazor template does). The development time server is not shared yet between (vanilla) Wasm and Blazor.

The one used by Wasm needs a runtime config and Blazor SDK disables runtime config, because it doesn't need it.