How to launch swagger url through vscode? - visual-studio-code

I am trying to launch swagger UI in browser using dotnet run command. Here is what I have tried in launch.json file. Expected outcome is that it should launch browser at the specified url and open swagger UI automatically. FYI I am using dotnet5 and created new web api project that already has swagger baked in. It doesn't launch the browser.

If you are using dotnet run command then its a known limitation that it doesn't launch a browser.
Please refer to this link for confirmation
While it doesn't launch it, it will still have your project running just means you manually have to type it in browser or use one of the workarounds listed in that issue.

Use compounds launch settings
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/WebApi/bin/Debug/net7.0/YourWebDll.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": "Launch Chrome",
"request": "launch",
"type": "chrome",
"url": "https://localhost:5001/swagger/index.html",
"webRoot": "${workspaceFolder}"
}
],
"compounds": [
{
"name": ".Net Core & Chrome",
"configurations": [".NET Core Launch (console)","Launch Chrome"]
}
]
This will run your app and launch chrome at the URL you want.

Related

How do I get new HTML files to execute in VS Code?

I have recently started learning WebDev using Colt Steele Udemy course. I've created few HTML files and whenever I try to execute any of them only the first created .html file opens in Chrome. How do I get the other files to open in the browser. Eg: If I create 3 files i.e a.html, b.html & c.html only a.html opens in Chrome even if b/c is open in the editor. This happens with both debugging or run without debugging. My VS Code version is 1.65.2. Please advice.
The launch.json code is:
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Open a.html",
"file": "e:\\\\Colt Steele\\HTML the essentials\\a.html"
}
The launch configuration you're showing is telling VSCode what to do when running the project. You can change the launch configuration to open a different file by default:
{
"type": "pwa-chrome",
"request": "launch",
"name": "Open b.html",
"file": "e:\\\\Colt Steele\\HTML the essentials\\b.html"
}
Or perhaps add multiple launch configurations, which you can select when debugging/running:
{
"type": "pwa-chrome",
"request": "launch",
"name": "Open a.html",
"file": "e:\\\\Colt Steele\\HTML the essentials\\a.html"
},
{
"type": "pwa-chrome",
"request": "launch",
"name": "Open b.html",
"file": "e:\\\\Colt Steele\\HTML the essentials\\b.html"
}
In general any given "application" would have a single default page as the entry point, and from there you can navigate through the application to use the other pages. So you might have a single index.html as the launch file, and in whatever you're building there would be links to other files as needed for the application.
But if what you're building for whatever reason truly has different "entry points" then you can just set up your build configurations based on that and select which configuration to use when running the application.
Alternatively (and I haven't tested this), you should be able to tell it to launch "the current file" by using a variable called file in the launch config:
{
"type": "pwa-chrome",
"request": "launch",
"name": "Open Current File",
"program": "${file}"
}

Launching and debugging Blazor server and webasm on VS Code

I have tried run visual studio code, to build, launch and debug (using omnisharp and dotnet...) the blazor server and webasm project but It seems to only launch one project at a time even tho task.json has both of the projects? is there a way to launch both project at the same time? or to keep one executing while the other is launched in case this wasnt possible?
here is my launch.json
{
"version": "0.2.0",
"configurations":
[
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/BlazorApp/bin/Debug/net5.0/BlazorApp.dll",
"args": [],
"cwd": "${workspaceFolder}/BlazorApp",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5010"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
"type": "blazorwasm",
"name": "Launch and Debug Blazor WebAssembly Application",
"request": "launch"
}
]
}
the answer is using compounds parameters in the launch.json
How to run multiple tasks in VS Code on build?
as for debugging I have yet to see how to get the js debugger to work on Chrome

Run and Debug problems in Visual Studio Code using haxe

I'm currently coding in Haxe with Heaps using Visual Studio Code. The latter has recently updated to version 1.56 which is now giving my a strange problem I can't manage to fix. Before the update, I was able to click Run and Debug using Hashlink in order to open the window of my game. After the update, when I Run and Debug it no longer opens the window, despite the compile.hxml and launch.json being exactly the same as before:
compile.hxml:
-cp src
-lib heaps
-lib hlsdl
-hl main.hl
-main Main
.json
"version": "0.2.0",
"configurations": [
{
"name": "HashLink (launch)",
"request": "launch",
"type": "hl",
"cwd": "${workspaceFolder}",
"preLaunchTask": {
"type": "haxe",
"args": "active configuration"
}
},
{
"name": "HashLink (attach)",
"request": "attach",
"port": 6112,
"type": "hl",
"cwd": "${workspaceFolder}",
"preLaunchTask": {
"type": "haxe",
"args": "active configuration"
}
}
]
Is anyone experiencing a similar problem?
Update: hashlink-debugger 1.1.2 was released, which should fix the problem.
It's a known issue:
HL debugger no longer works in latest vscode #97
You can downgrade to the previous VSCode release or subscribe to the issue and wait for the hashlink-debugger update.

how to launch vscode live server as a task in launch.json

I need to have vscode to launch vscode live server as a run configuration in launch.json, to be able to include its launch with other run configurations in a compound launch.
I have tried the "Launch Extension" of type "pwa-extensionHost" with several different arguments and runtimeexecutables, for example
{
"name": "Launch Extension",
"request": "launch",
"type": "pwa-extensionHost",
"runtimeExecutable": "liveserver"
}
and
{
"name": "Launch Extension",
"request": "launch",
"type": "pwa-extensionHost",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"liveserver"
]
}
but couldn't get it run.

Can not change debug environment automatically on visual studio code with config

For example, my root workstation directory is /home/chain/Project. And I have two separate projects which is python and website. My launch.json goes:
{
"version": "0.2.0",
"configurations":
[
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/python_project_source/test.py",
"cwd": "${workspaceRoot}/python_project_source",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "${workspaceRoot}/website/test.html",
"webRoot": "${workspaceRoot}/website"
}
]
}
As expected when I select test.py and press 'F5' it can switch to python debug environment, and when I select test.html the Chrome will be opened.
The fact is, VS code only remember the environment I debugged last time rather than change it automatically. So the only thing I do now is adding some comments to one environment (/* */) when I need to compile the other.:(
Is there something wrong in my launch.json?
Automatically switching the debug environment based on the file (or file-type) is not a current feature of Visual Studio Code, I believe.
You'll have to manually switch the launch configuration depending on the type of debugging task you want to perform.
And, of course, you could consider writing a feature request: https://github.com/Microsoft/vscode