-
Notifications
You must be signed in to change notification settings - Fork 18
Start debug command fails to start c# ASP.NET app for multiple reasons #54
Description
There are several problems that were preventing the start_debugging command from working on an C# ASP.NET project.
Problem 1 - Comment removal breaks JSON parsing
The problem is that if you have a URL (or any other value with double-forward slashes // in it) this regex will break the JSON parsing because it removes the rest of the line after the double-forward slashes leaving the string value with no close-quote.
Removing comments is done via a simple regex:
| let cleanJson = launchJsonContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ''); |
I replaced it with jsonc-parser and it seems to resolve the issue. This is the same lib that vscode itself uses to parse launch.json
This will affect any launch.json that has URLs in it, or double-forward-slashes for any use other than comments. It may be the same root cause as #11 #22 #39 but I'm not making any assumptions since I didn't see a launch.json mentioned in those issues.
Problem 2 - Language detection assumes .csproj is Python
The language detection code doesn't handle C# project file extension, so if the MCP sends a .csproj file, it defaults to Python and tries to launch the Python debugger.
Personally, I would rather it errored out when it can't determine the language than default to Python, but that's a different topic...
Problem 3 - Not running configured launch settings if coreclr detected
Currently when it detects coreclr, it doesn't use the launch.json configuration instead it's hardcoded to use the testing.debugCurrentFile command.
I'm not sure why this was done because it was part of a fairly big commit with a very short description "fix multi file issue" ac9c4c2
Either way, removing the special case seems to fix letting the MCP start debugging .NET projects.
Solution
The solution is to fix parsing launch.json, running .csproj and debugging coreclr (.net) projects.
I've attached a PR #55 with these solutions applied. I know there have been other attempts to resolve parts of this issue (i.e., #23) but I'm combining them together here because I think you need all of them to make this fully work for .NET web projects.
Hope this helps! I look forward to your thoughts and comments on these problems! Thank you!