Failed to launch debug adapter locally when changing ASPNETCORE_ENVIRONMENT - visual-studio

I have a solution with a pretty standard config structure
appsettings.json
appsettings.Development.json
appsettings.Testing.json
appsettings.Production.json
Testing and Production servers have an ASPNETCORE_ENVIRONMENT set to Testing and Production respectively and the everything works, proper config get's chosen, etc.
I wanted to load appsettings.Testing.json in my local Visual Studio so I went to my launchSettings.json and changed ASPNETCORE_ENVIRONMENT to Testing and Studio throws the error on launch.
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:28725",
"sslPort": 44342
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Testing" <- was "Development"
},
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
}
}
}
Just to summarize all I did was changed that one setting from Testing to Development and Studio throws the Failed to launch debug adapter error upon launching.
And that's kinda it, nothing in the output windows, nothing in the windows eventviewer that I could find.

Related

Understanding the ports in lauchsettings.json

Background
I have the following launchsettings.json:
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54732",
"sslPort": 44382
}
},
"profiles": {
"NoteKeeperService": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7249;http://localhost:5249",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
This was generated by Visual Studio and I am trying to understand the different ports that it generated. Specifically there are 4 different ports generated by Visual Studio:
The four ports are:
iisSettings->iisExpress->applicationUrl (Line 7)
Port: 54732 - (http)
iiSettings->IssExpress->sslPort (Line 8)
Port: 44382 - (https)
profiles->applicationUrl (Line 17)
Port: 7249 - (https)
Port: 5249 - (http)
There are a pair (http and https) for IIS Express and a pair for the service directly (when it runs inside of Visual Studio, I think...?) I am guessing they all different so you don't get any port conflicts when running in IIS Express and locally.
Question
And what range rules do these ports follow for generation?
Details (ignorable)
I am creating my own template, and I want to make sure I understand the ranges for each port number so I don't put the ports in an invalid range. The dotnet templating system has a generator for ports, but it requires that I supply a range value for the ports. I am unsure what those ranges should be, or if it even matters.
This is actually more of an OS/Infrastructure question than a Visual Studio question, since ports are how the system will manage communications.
Generally speaking ports < 1024 may be "reserved" for use by "well known" programs. e.g. 80 for http, 443 for https, 21 for ftp etc.
The IANA port list may give you a more complete picture
Safe to say for your Visual Studio template any port between 1025 and 65000 should suffice. It should be up to the end user (developer in this case) to determine if the high range port is already in use by another development project.

Couldn't start dlv dap

When I launch in VSCode dlv dap debug, I get this message:
Couldn't start dlv dap:
Error:timed out while waiting for DAP server to start
I already have launch configurations for the project:
lunch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}",
"showLog": true,
"env": {
"GO111MODULE": "on"
}
}
]
}
and setting.json is :
{
"folders": [
{
"path": "."
}
],
"settings": {
"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
"go.autocompleteUnimportedPackages": true,
"go.gocodePackageLookupMode": "go",
"go.gotoSymbol.includeImports": true,
"go.useCodeSnippetsOnFunctionSuggest": true,
"explorer.confirmDelete": false,
"go.formatTool": "goimports",
"go.docsTool": "gogetdoc",
"go.buildFlags": [],
"explorer.confirmDragAndDrop": false,
"window.zoomLevel": 0.8,
"editor.minimap.enabled": false,
"go.useLanguageServer": true,
"go.delveConfig":{
"debugAdapter":"dlv-dap"
},
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnType": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"gopls": {
"experimentalWorkspaceModule": true,
"usePlaceholders": true, // add parameter placeholders when completing a function
"completionDocumentation": true // for documentation in completion items
}
},
}
The structure of the project is shown in the figure:
This might be happening due to recent updates to VS Code Go extension.
First options is to fix it by running "Go: Install/Update Tools" command from the Command Palette (Linux/Windows: Ctrl+Shift+P, Mac: ⇧+⌘+P).
Then, mark dlv & dlv-dap from the menu, and hit ok to start install/update.
Delve’s native DAP implementation is under active development, so take advantage of the most recent features and bug fixes by using Delve built from its master branch. The Go extension maintains this newest version of Delve separately from the officially released version of dlv and installs it with the name dlv-dap.
Second option, is to use legacy debug adapter. More on this in the link below ...
Check out the full documentation at https://github.com/golang/vscode-go/blob/master/docs/debugging.md
You might have some luck switching the delveConfig to use legacy mode:
"go.delveConfig":{
"debugAdapter":"legacy"
}
My team and I recently began seeing the same issue after updating VSCode. There's a little more info on this setting here: https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#switching-to-legacy-debug-adapter, but I believe root cause (if this does indeed solve your issue) is going to be your version of Golang is not the version targeted by dlv-dap. Anything below Go version 1.15 needs to use legacy mode, and the latest version of the delve debugger happens to skip legacy mode by default now.
I also needed to kill VSCode before this change took effect. According to the dlv-dap docs, you can also force it into legacy mode by switching launch.json's mode to "remote", so there's likely a few (maybe better) ways to resolve this issue.
For macOS users:
brew install delve
Linux/Windows: Ctrl+Shift+P, Mac: ⇧+⌘+P

I want to compile all my *.scss files residing in a folder using web compiler in VS2019

Is it possible to compile all .scss files residing in a folder using web compiler in Visual Studio 2019?
I don't want to specify each and every file. I tried something like this.
[
{
"outputFile": "wwwroot/assets/css/pages/",
"inputFile": "wwwroot/assets/sass/pages/**/*.scss",
"minify": { "enabled": true },
"includeInProject": true,
"options": { "sourceMap": true }
}
]

How to launch an url on F5 when using Kestrel on a specific port?

I have an Asp.Net Core 2.2 application using Kestrel with default settings. I went in the project's debug properties and set the "Launch Browser" setting to the page I want to start with when debugging and "Launch" to "Project". This all works fine but I want Kestrel to use a specific port. I found plenty of example that work for the port (I use the hosting.json way) but all of them seem to disregard the "Launch Browser" setting.
Is there no way to have Visual Studio automatically open a new window/tab with my chosen URL and use a specific port when I debug?
Program.cs
public class Program
{
public static void Main(string[] args)
{
var host = WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
launchSettings.json
{
"profiles": {
"Kestrel": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger"
}
}
}
hosting.json
{
"urls": "https://localhost:44350/;"
}
and if I'm using hosting.json, my main is:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddCommandLine(args)
.AddJsonFile("hosting.json", optional: true)
.Build();
var host = WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseKestrel()
.UseStartup<Startup>()
.Build();
host.Run();
}
In the project's debug properties , you should set the App URL of "Web Server Settings" to the specific port you want , and the "Launch Browser" is default checked.
Or you chould also set the specific port in the launchSettings.json like below:
"MVC2_2Project": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:7001;http://localhost:7000"
}
The setting in launchSettings.json and the project's debug properties is synchronous, you can set it up in one place.

Getting #types to work in Visual Studio 2015 Update 3 with TypeScript 2.1

Everything about TS 2.x #types seems so awesome, but I cannot for the life of me figure out how to get it working correctly!
I have Visual Studio 2015 installed - version 14.0.25431.01 Update 3
I have TypeScript 2.1.4 for Visual Studio 2015 installed, which I got from here
The VS Web project has been set to use TypeScript 2.1 with <TypeScriptToolsVersion>2.1</TypeScriptToolsVersion>
Here's a relevant portion from my packages.json file
"dependencies": {
"angular": "^1.5.9",
"angular-messages": "^1.5.9",
"angular-ui-bootstrap": "^2.3.0",
"angular-ui-router": "^0.3.2",
"moment": "^2.17.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"#types/angular": "^1.5.21",
"#types/angular-ui-bootstrap": "^0.13.36",
"#types/angular-ui-router": "^1.1.35",
"#types/jquery": "^2.0.34",
"#types/node": "^0.0.3",
"#types/signalr": "^2.2.32",
"#types/underscore": "^1.7.36"
}
And here's my full tsconfig.json file
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"sourceMap": true,
"target": "ES5"
},
"typeAcquisition": {
"enable": true
}
}
I've also tried variations with typeRoots and types specified (one, the other, both, neither) inside the compilerOptions, but no luck!
"typeRoots": [
"./node_modules/#types"
],
"types": [
"angular",
"angular-ui-bootstrap",
"angular-ui-router",
"jquery",
"moment",
"signalr",
"underscore"
]
I've cleaned the build, restarted Visual Studio, etc. but no matter what I do I just get build errors like
some-file.ts(8,22): error TS2304: Build:Cannot find name 'angular'.
some-file.ts(12,41): error TS2694: Build:Namespace 'angular' has no exported member 'IScope'.
some-file.ts(12,67): error TS2694: Build:Namespace 'angular' has no exported member 'IRootElementService'.
another-file.ts(26,22): error TS2503: Build:Cannot find namespace 'moment'.
another-file.ts(47,37): error TS2304: Build:Cannot find name 'moment'.
All of the typedefs exist on disk in either node_modules/#types or with the relevant package itself. I have no idea why Visual Studio/TypeScript cannot find these files! I feel like something was either not ready to be released yet, or I'm missing something extremely simple. Please someone point me in the right direction here
If you haven't got this resolved yet try uninstalling the typescript tools from uninstall/install programs (you may have multiple versions like I did) and reinstalling the typescript tools # v2.1.4 via the install package you already have. Double check in visual studio that, that is the version you are using (it should have the details in 'about microsoft visual studio' in the help menu)
Here's my tsconfig in case that helps:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"typeRoots": [
"node_modules/#types"
]
},
"typeAcquisition": {
"enable": true
},
"exclude": [
"jspm_packages"
]
}
This works for any types that export a module but I have still had issues when importing individual typings when they aren't modules (ie just interfaces etc)...
Generally I haven't had to do any import * from x statements for libraries and have been able to just use the name of the module exported directly.

Resources