Reputation: 3622
I have Visual Studio 2019 installed but I prefer to use VS Code. After hours of research, I'm confused as to what I can debug and what I cannot.
I have the C# extension installed.
I created a launch.json and tasks.json.
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "clr",
"request": "launch",
"preLaunchTask": "build",
"program": "{path-to-my-project}.dll",
"args": [],
"cwd": "{myNameSpace}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
},
"logging": {
"moduleLoad": false
}
},
{
"name": ".NET Core Attach",
"type": "clr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
Are these instructions only for console applications?
https://github.com/OmniSharp/omnisharp-vscode/wiki/Desktop-.NET-Framework
I also found this:
How can we debug ASP.NET MVC web application in Visual Studio Code?
But it seems like the configuration.program
needs to point to an EXE. Whereas my application generates a DLL.
How can I debug a .NET MVC (non-core) web application with VS Code?
Solution
I followed ruslan.gilmutdinov answer below and it's working! It wasn't as complicated as I thought it would be.
Upvotes: 3
Views: 2510
Reputation: 1317
Let's assume your .NET Framework web application is called MyWebApp
and you want to debug it on port 5521
. This is how you can set up debugging in VSCode:
Add OmniSharp extension to VSCode.
Add following things to the PATH environment variable:
msbuild: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
iisexpress: C:\Program Files\IIS Express\
chrome: C:\Program Files (x86)\Google\Chrome\Application
cd MyWebApp
msbuild MyWebApp.sln -m
.vs\MyWebApp\config\applicationhost.config
and set up your <site>
:<sites>
<site name="MyWebApp" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="W:\Projects\NET\MyWebApp\MyWebApp" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:5521:localhost" />
</bindings>
</site>
<siteDefaults>
<!-- To enable logging, please change the below attribute "enabled" to "true" -->
<logFile logFormat="W3C" directory="%AppData%\Microsoft\IISExpressLogs" enabled="false" />
<traceFailedRequestsLogging directory="%AppData%\Microsoft" enabled="false" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
(pay attention to the values of attributes bindingInformation
and physicalPath
)
.csproj
file. In VSCode, open up MyWebApp/MyWebApp.csproj
. Look for this section and this is where you will be making some changes:<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>false</Optimize>
</PropertyGroup>
Ensure that the Optimize
is set to false and set the debug option to "portable":
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
</PropertyGroup>
launch.json
and tasks.json
to .vscode
directory:tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "msbuild",
"command": "msbuild.exe",
"type": "shell",
"args": [
"/p:Configuration=Debug",
"/t:build",
"-m"
],
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
"label": "iisStart",
"type": "shell",
"dependsOn": "msbuild",
"command": "Start-Process",
"args": ["iisexpress.exe", "/config:${workspaceFolder}\\.vs\\MyWebApp\\config\\applicationhost.config /site:MyWebApp"],
"presentation": {
"reveal": "silent",
}
},
{
"label": "iisStop",
"type": "shell",
"command": "Stop-Process",
"args": ["-Name", "iisexpress"]
},
]
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "pwa-chrome",
"webRoot": "${workspaceFolder}",
"runtimeArgs": [
"http://localhost:5521/",
"--new-window",
"--remote-debugging-port=9222"
]
},
{
"name": "Attach to Chrome",
"port": 9222,
"request": "attach",
"type": "pwa-chrome",
"webRoot": "${workspaceFolder}"
},
{
"name": "Start WebApp",
"type": "clr",
"request": "attach",
"processName": "iisexpress",
"preLaunchTask": "iisStart",
"postDebugTask": "iisStop",
},
],
"compounds":[
{
"name": "Launch & Attach Chrome",
"configurations": ["Launch Chrome", "Attach to Chrome"]
}
]
}
You will get the following options for debugging in VSCode:
Now all you have to do is to launch Start WebApp
and then Launch & Attach Chrome
.
Happy debugging!
Upvotes: 3
Reputation: 17
You can simply click the debug buttun on the vscode
Then click create a launch.json file
After that, it will ask for the runtime. Select .NET for that and select your startup project. then you can see the launch.json file in your project path. Now add debug points wherever you want and press f5
Upvotes: 0