Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

launch.json does not pickup a seondary launchConfigurationId from Properties/launchSettings.JSON #7584

Open
patoJamriska opened this issue Sep 20, 2024 · 6 comments
Assignees
Labels

Comments

@patoJamriska
Copy link

Trying to debug an application using different environment variables for the use use of appSettings.env.json i.e.:

"environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
}

does not pick up a secondary profile. So I can have a Development env and a UAT env but it only picks up the first one when I hit debug. Same thing happens on Compounds:

launch.json sample:

{
"version": "0.2.0",
    "configurations": [
      {
        "name": "MyAppDev",
        "type": "dotnet",
        "request": "launch",
        "projectPath": "${workspaceFolder}/MyApp/MyApp.csproj",
        "launchConfigurationId": "TargetFramework=;MyAppDev"
      },
      {
        "name": "MyAppUAT",
        "type": "dotnet",
        "request": "launch",
        "projectPath": "${workspaceFolder}/MyApp/MyApp.csproj",
        "launchConfigurationId": "TargetFramework=;MyAppUAT"
      },
]
}

LaunchSettings.Json sample:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "MyAppDev": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "clients",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
      },
      "applicationUrl": "https://localhost:44334"
    }
    "MyAppUAT": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "clients",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "UAT",
      },
      "applicationUrl": "https://localhost:44334"
    }
  }
}

If the CSharp: Report an issue command doesn't appear, make sure that you have C# extension version 1.17.0 or newer installed.

Environment data

VS Code version: 1.93.1 (Universal)
C# Extension version: current latest and Pre-release versions

Steps to reproduce

  1. go to Debug
  2. select profile 1, run, it loads c# app on development.
  3. select profile 2, run, it loads c# app still on development instead of UAT

Expected behavior

the UI will pick the correct profile to launch

Additional context

This was working on a few versions ago, but I didnt had to use vscode on this project for a while until recently that realized it was not picking up my other environments.

@patoJamriska patoJamriska changed the title launch.jsopn does not pickup a seondary launchConfigurationId from Properties/launchSettings.JSON launch.json does not pickup a seondary launchConfigurationId from Properties/launchSettings.JSON Sep 20, 2024
@WardenGnaw
Copy link
Contributor

@patoJamriska Do you have C# Dev Kit installed?

launchConfigurationId was not intended to really be saved in a launch.json but was supposed to be used by the dynamic configuration provider which is used internally by the resolver in C# Dev Kit.

The dotnet debug type only supports using projectPath if you are using launch.json

@WardenGnaw WardenGnaw self-assigned this Sep 20, 2024
@stewartadam
Copy link

stewartadam commented Sep 23, 2024

@WardenGnaw I had a similar issue to @patoJamriska because the documentation isn't very clear on this. Is launchSettingsProfile property on a launch configuration in .vscode/launch.json the expected way to provide which launchSettings profile to use?

When I tried (this was ~2mo back at this point) it just ignored everything and would always pick the first profile in launchSettings.json anyways. This was true of manually configured launch profiles or the dynamic configuration.

I also found applicationUrls of the selected profile is ignored; workaround was setting ASPNETCORE_URLS as an env variable.

Anyways about the documentation

  • It should make clear in which file launchSettingsProfile should be configured
  • It would be helpful if the "launchSettingsProfile": "ProfileNameGoesHere" example showed a few lines above/below.
  • If launchSettingsProfile is a valid option for launch.json, it should appear in the launch profile schema/autocomplete suggestions (today it does not)
  • If launchConfigurationId is internal, it should be removed from autocomplete suggestions and documented as such so users don't try to manually configure what the VSCode generates for them and have nothing happen as a result.

@patoJamriska
Copy link
Author

@patoJamriska Do you have C# Dev Kit installed?

launchConfigurationId was not intended to really be saved in a launch.json but was supposed to be used by the dynamic configuration provider which is used internally by the resolver in C# Dev Kit.

The dotnet debug type only supports using projectPath if you are using launch.json

Yes, I am using the C# developer extension

@patoJamriska
Copy link
Author

@WardenGnaw I had a similar issue to @patoJamriska because the documentation isn't very clear on this. Is launchSettingsProfile property on a launch configuration in .vscode/launch.json the expected way to provide which launchSettings profile to use?

When I tried (this was ~2mo back at this point) it just ignored everything and would always pick the first profile in launchSettings.json anyways. This was true of manually configured launch profiles or the dynamic configuration.

I also found applicationUrls of the selected profile is ignored; workaround was setting ASPNETCORE_URLS as an env variable.

Anyways about the documentation

  • It should make clear in which file launchSettingsProfile should be configured
  • It would be helpful if the "launchSettingsProfile": "ProfileNameGoesHere" example showed a few lines above/below.
  • If launchSettingsProfile is a valid option for launch.json, it should appear in the launch profile schema/autocomplete suggestions (today it does not)
  • If launchConfigurationId is internal, it should be removed from autocomplete suggestions and documented as such so users don't try to manually configure what the VSCode generates for them and have nothing happen as a result.

applicationUrls actually instead I use the launchUrl which is also in the properties/launchSettings. And I agree it is not clear that it is dependent on this file but it looks like the plugin is definetly trying to emulate how Visual studio works in that regards, but it is incomplete.

@patoJamriska
Copy link
Author

patoJamriska commented Sep 26, 2024

I have still being doing research on this Because of other issues arising on the work I am doing, and run into this on the MS documentation. https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-8.0#development-and-launchsettingsjson

This section actually shows how to use the coreclr to pass environment variables at the launch.json level, but obviosuly that is not an option since we are using the c# plugin and the launch is "type": "dotnet". Not sure if there has been anyone looking into this besides what has been shared by now?

PD: going thru the github LaunchSettings is using coreclr, and doing a bit more digging on the console, I can see that the dotnet type does launch coreclr in the brackground regardless, so I think until this can be properly investigated and I can see some reply about it, I will most likely switch to use coreclr again on the launch.json to have full control on vscode.
I removed PII from this on my logs so you can have the sample of the launch on the console:

{ "command": "launch", "arguments": { "name": "yourProjectNameDev", "type": "coreclr", "request": "launch", "projectPath": "/yourProjectPath.csproj", "launchConfigurationId": "TargetFramework=;MyApp_Dev", "__configurationTarget": 6, "preRestartTask": "dotnet: build /yourProjectPath.csproj", "program": "/yourProjectPath/bin/Debug/net8.0/yourProjectPath", "args": "", "cwd": "/yourProjectPath", "env": { "ASPNETCORE_URLS": "https://localhost:44324", "ASPNETCORE_HTTPS_PORT": "44324", "LOCAL_DEVELOPMENT": "true", "ASPNETCORE_ENVIRONMENT": "Development" }, "console": "internalConsole", "checkForDevCert": true, "launchSettingsProfile": null, "debugConsoleVerbosity": "verbose", "debuggerStartDebugTelemetry": { "buildCompletedTimestamp": "0x1922f6721ba", "totalBuildTime": 3353, "projectType": "Web" }, "serverReadyAction": { "action": "openExternally", "pattern": "\\bNow listening on:\\s+https?://\\S+", "uriFormat": "https://localhost:44324/clients" }, "hotReloadOnSave": true, "hotReloadVerbosity": "detailed", "stopAtEntry": false, "justMyCode": true, "requireExactSource": true, "enableStepFiltering": true, "logging": { "exceptions": true, "moduleLoad": true, "programOutput": true, "browserStdOut": true, "elapsedTiming": false, "threadExit": false, "processExit": true, "engineLogging": false, "diagnosticsLog": { "protocolMessages": false, "dispatcherMessages": "none", "debugEngineAPITracing": "none", "debugRuntimeEventTracing": false, "expressionEvaluationTracing": false, "startDebuggingTracing": false }, "consoleUsageMessage": true }, "suppressJITOptimizations": false, "symbolOptions": { "searchPaths": [], "searchMicrosoftSymbolServer": false, "searchNuGetOrgSymbolServer": false, "cachePath": "", "moduleFilter": { "mode": "loadAllButExcluded", "excludedModules": [], "includedModules": [], "includeSymbolsNextToModules": true, "includeSymbolsOnDemand": true } }, "expressionEvaluationOptions": { "allowImplicitFuncEval": true, "allowToString": true, "allowFastEvaluate": true, "showRawValues": false }, "internalConsoleOptions": "openOnSessionStart", "__sessionId": "90ecc55a-5069-42e8-a332-14ce69577c5f" }, "type": "request", "seq": 2 }

@CaCTuCaTu4ECKuu
Copy link

Did something changed or update?
I had problem that launching any configuration in launch.json leads to loading first config from launchSettings.json which screw my environment variables, and I got here, but projectPath and launchConfigurationId are not allowed as properties in configuration (anymore?)

I check docs

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-8.0#development-and-launchsettingsjson

and setting launchSettingsProfile property in launch.json config solved my issue and it's even better that config is shared, so is this issue resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants