Skip to content

Commit ae8b2c2

Browse files
Added VSCode debugging (for MvcSandbox) & code analysis support (dotnet#29486)
* Added VSCode debugging support for MvcSandbox * Added ignored vscode folders * 1. Convered some more projects. 2. Added env variable for TargetFramework and used it in launch.json file rather than hardcoding TFW. * Addressed PR feedback. 1. Removed extensions.json 2. Updated BuildFromSource.md for Vscode instructions. 3. Added launch settings for BasicTestApp. * Addressed PR feedback!
1 parent 79b419c commit ae8b2c2

21 files changed

+470
-21
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ obj/
77
.packages/
88
.tools/
99
.vs/
10-
.vscode/
1110
node_modules/
1211
BenchmarkDotNet.Artifacts/
1312
.gradle/

.vscode/extensions.json

-7
This file was deleted.

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
"processId": "${command:pickProcess}"
1515
}
1616
]
17-
}
17+
}

docs/BuildFromSource.md

+24-12
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Visual Studio 2019 (16.8) is required to build the repo locally. If you don't ha
5353
> You can do so by running the `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser` command
5454
> in PowerShell. For more information on execution policies, you can read the [execution policy docs](https://docs.microsoft.com/powershell/module/microsoft.powershell.security/set-executionpolicy).
5555
56-
The [global.json](/global.json) file specifies the minimum requirements needed to build using `msbuild`. The [eng/scripts/vs.json](/eng/scripts/vs.json) file provides a description of the components needed to build within VS. If you plan on developing in Visual Studio, you will need to have these components installed.
56+
The [global.json](/global.json) file specifies the minimum requirements needed to build using `msbuild`. The [eng/scripts/vs.json](/eng/scripts/vs.json) file provides a description of the components needed to build within VS. If you plan on developing in Visual Studio, you will need to have these components installed.
5757

5858
> :bulb: The `InstallVisualStudio.ps1` script mentioned above reads from the `vs.json` file to determine what components to install.
5959
@@ -95,6 +95,14 @@ The build should find any JDK 11 or newer installation on the machine as long as
9595

9696
This repo contains a Selenium-based tests require a version of Chrome to be installed. Download and install it from <https://www.google.com/chrome>.
9797

98+
#### Visual Studio Code Extension
99+
100+
The following extensions are recommended when developing in the ASP.NET Core repository with Visual Studio Code.
101+
102+
- [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp)
103+
104+
- [EditorConfig](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig)
105+
98106
#### WiX (Optional)
99107

100108
If you plan on working with the Windows installers defined in [src/Installers/Windows](../src/Installers/Windows), you will need to install the WiX toolkit from <https://wixtoolset.org/releases/>.
@@ -155,9 +163,11 @@ Studio because those projects are not listed in AspNetCore.sln.
155163
This will download the required tools and restore all projects inside the repository. At that point, you should be able
156164
to open the .sln file or one of the project specific .slnf files to work on the projects you care about.
157165

158-
> :bulb: Pro tip: you will also want to run this command after pulling large sets of changes. On the main
159-
> branch, we regularly update the versions of .NET Core SDK required to build the repo.
160-
> You will need to restart Visual Studio every time we update the .NET Core SDK.
166+
167+
> :bulb: Pro tip: you will also want to run this command after pulling large sets of changes. On the main
168+
> branch, we regularly update the versions of .NET Core SDK required to build the repo.
169+
> You will need to restart Visual Studio every time we update the .NET Core SDK.
170+
161171

162172
> :bulb: Rerunning the above command or, perhaps, the quicker `.\build.cmd -noBuildNative -noBuildManaged` may be
163173
> necessary after switching branches, especially if the `$(DefaultNetCoreTargetFramework)` value changes.
@@ -195,6 +205,8 @@ These principles guide how we create and manage .slnf files:
195205
Before opening the project in Visual Studio Code, you will need to make sure that you have built the project.
196206
You can find more info on this in the "Building on command-line" section below.
197207

208+
To open specific folder inside Visual studio code, you have to open it with `startvscode.cmd` file. Ths will setup neccessary environment variables and will open given directory in Visual Studio Code.
209+
198210
Using Visual Studio Code with this repo requires setting environment variables on command line first.
199211
Use these command to launch VS Code with the right settings.
200212

@@ -216,7 +228,7 @@ code .
216228
```
217229

218230
> :bulb: Note that if you are using the "Remote-WSL" extension in VSCode, the environment is not supplied
219-
> to the process in WSL. You can workaround this by explicitly setting the environment variables
231+
> to the process in WSL. You can workaround this by explicitly setting the environment variables
220232
> in `~/.vscode-server/server-env-setup`.
221233
> See <https://code.visualstudio.com/docs/remote/wsl#_advanced-environment-setup-script> for details.
222234
@@ -302,11 +314,11 @@ Additional properties can be added as an argument in the form `/property:$name=$
302314

303315
Common properties include:
304316

305-
Property | Description
306-
-------------------------|-------------------------------------------------------------------------------------------------------------
307-
Configuration | `Debug` or `Release`. Default = `Debug`.
308-
TargetArchitecture | The CPU architecture to build for (x64, x86, arm, arm64).
309-
TargetOsName | The base runtime identifier to build for (win, linux, osx, linux-musl).
317+
| Property | Description |
318+
| ------------------ | ----------------------------------------------------------------------- |
319+
| Configuration | `Debug` or `Release`. Default = `Debug`. |
320+
| TargetArchitecture | The CPU architecture to build for (x64, x86, arm, arm64). |
321+
| TargetOsName | The base runtime identifier to build for (win, linux, osx, linux-musl). |
310322

311323
### Resx files
312324

@@ -325,7 +337,7 @@ Building installers does not run as part of `build.cmd` run without parameters,
325337
.\build.cmd -buildInstallers
326338
```
327339

328-
*Note*: Additional build steps listed above aren't necessary on Linux or macOS.
340+
_Note_: Additional build steps listed above aren't necessary on Linux or macOS.
329341

330342
- Run the installers produced in `artifacts/installers/{Debug, Release}/` for your platform.
331343
- Add a NuGet.Config to your project directory with the following content:
@@ -341,7 +353,7 @@ Building installers does not run as part of `build.cmd` run without parameters,
341353
</configuration>
342354
```
343355

344-
*NOTE: This NuGet.Config should be with your application unless you want nightly packages to potentially start being restored for other apps on the machine.*
356+
_NOTE: This NuGet.Config should be with your application unless you want nightly packages to potentially start being restored for other apps on the machine._
345357

346358
- Update the versions on `PackageReference` items in your .csproj project file to point to the version from your local build.
347359

omnisharp.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"RoslynExtensionsOptions": {
3+
"enableAnalyzersSupport": true
4+
},
5+
"FormattingOptions": {
6+
"enableEditorConfigSupport": true
7+
},
8+
"RenameOptions": {
9+
"RenameInComments": true,
10+
"RenameOverloads": true,
11+
"RenameInStrings": true
12+
},
13+
"msbuild": {
14+
"MSBuildSDKsPath": ".\\.dotnet",
15+
"EnablePackageAutoRestore": true,
16+
"loadProjectsOnDemand": true
17+
},
18+
"fileOptions": {
19+
"systemExcludeSearchPatterns": [
20+
"**/node_modules/**/*",
21+
"**/bin/**/*",
22+
"**/obj/**/*",
23+
"**/node_modules/**/*"
24+
],
25+
"excludeSearchPatterns": []
26+
}
27+
}

src/Antiforgery/startvscode.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO OFF
2+
3+
%~dp0..\..\startvscode.cmd %~dp0

src/Azure/.vscode/launch.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "AzureAppServicesHostingStartupSample",
6+
"type": "coreclr",
7+
"preLaunchTask": "AzureAppServicesHostingStartupSample-build",
8+
"request": "launch",
9+
"program": "${workspaceFolder}/../../artifacts/bin/AzureAppServicesHostingStartupSample/Debug/${env:TARGET}/AzureAppServicesHostingStartupSample.dll",
10+
"args": [],
11+
"cwd": "${workspaceFolder}",
12+
"stopAtEntry": false,
13+
"serverReadyAction": {
14+
"action": "openExternally",
15+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
16+
},
17+
"env": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
},
20+
},
21+
]
22+
}

src/Azure/.vscode/tasks.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "AzureAppServicesHostingStartupSample-build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/samples/AzureAppServicesHostingStartupSample/AzureAppServicesHostingStartupSample.csproj"
11+
],
12+
"problemMatcher": "$msCompile",
13+
"group": {
14+
"kind": "build",
15+
"isDefault": true
16+
}
17+
}
18+
]
19+
}

src/Azure/startvscode.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO OFF
2+
3+
%~dp0..\..\startvscode.cmd %~dp0

src/Caching/startvscode.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO OFF
2+
3+
%~dp0..\..\startvscode.cmd %~dp0

src/Components/.vscode/launch.json

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "BlazorServerApp",
6+
"type": "coreclr",
7+
"preLaunchTask": "BlazorServerApp-build",
8+
"request": "launch",
9+
"program": "${workspaceFolder}/../../artifacts/bin/BlazorServerApp/Debug/${env:TARGET}/BlazorServerApp.dll",
10+
"args": [],
11+
"cwd": "${workspaceFolder}",
12+
"stopAtEntry": false,
13+
"serverReadyAction": {
14+
"action": "openExternally",
15+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
16+
},
17+
"env": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
},
20+
},
21+
{
22+
"name": "IgnitorSample",
23+
"type": "coreclr",
24+
"preLaunchTask": "IgnitorSample-build",
25+
"request": "launch",
26+
"program": "${workspaceFolder}/../../artifacts/bin/IgnitorSample/Debug/${env:TARGET}/IgnitorSample.dll",
27+
"args": [],
28+
"cwd": "${workspaceFolder}",
29+
"stopAtEntry": false,
30+
"serverReadyAction": {
31+
"action": "openExternally",
32+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
33+
},
34+
"env": {
35+
"ASPNETCORE_ENVIRONMENT": "Development"
36+
},
37+
},
38+
{
39+
"name": "BasicTestApp",
40+
"type": "coreclr",
41+
"preLaunchTask": "BasicTestApp-build",
42+
"request": "launch",
43+
"program": "${workspaceFolder}/../../artifacts/bin/BasicTestApp/Debug/${env:TARGET}/BasicTestApp.dll",
44+
"args": [],
45+
"cwd": "${workspaceFolder}",
46+
"stopAtEntry": false,
47+
"serverReadyAction": {
48+
"action": "openExternally",
49+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
50+
},
51+
"env": {
52+
"ASPNETCORE_ENVIRONMENT": "Development"
53+
},
54+
}
55+
]
56+
}

src/Components/.vscode/tasks.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "BlazorServerApp-build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/Samples/BlazorServerApp/BlazorServerApp.csproj"
11+
],
12+
"problemMatcher": "$msCompile",
13+
"group": {
14+
"kind": "build",
15+
"isDefault": true
16+
}
17+
},
18+
{
19+
"label": "IgnitorSample-build",
20+
"command": "dotnet",
21+
"type": "process",
22+
"args": [
23+
"build",
24+
"${workspaceFolder}/Samples/IgnitorSample/IgnitorSample.csproj"
25+
],
26+
"problemMatcher": "$msCompile",
27+
"group": {
28+
"kind": "build",
29+
"isDefault": true
30+
}
31+
},
32+
{
33+
"label": "BasicTestApp-build",
34+
"command": "dotnet",
35+
"type": "process",
36+
"args": [
37+
"build",
38+
"${workspaceFolder}/test/testassets/BasicTestApp/BasicTestApp.csproj"
39+
],
40+
"problemMatcher": "$msCompile",
41+
"group": {
42+
"kind": "build",
43+
"isDefault": true
44+
}
45+
}
46+
]
47+
}

src/Components/startvscode.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO OFF
2+
3+
%~dp0..\..\startvscode.cmd %~dp0
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "CustomEncryptorSample",
6+
"type": "coreclr",
7+
"preLaunchTask": "CustomEncryptorSample-build",
8+
"request": "launch",
9+
"program": "${workspaceFolder}/../../artifacts/bin/CustomEncryptorSample/Debug/${env:TARGET}/CustomEncryptorSample.dll",
10+
"args": [],
11+
"cwd": "${workspaceFolder}",
12+
"stopAtEntry": false,
13+
"serverReadyAction": {
14+
"action": "openExternally",
15+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
16+
},
17+
"env": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
},
20+
},
21+
{
22+
"name": "EntityFrameworkCoreSample",
23+
"type": "coreclr",
24+
"preLaunchTask": "EntityFrameworkCoreSample-build",
25+
"request": "launch",
26+
"program": "${workspaceFolder}/../../artifacts/bin/EntityFrameworkCoreSample/Debug/${env:TARGET}/EntityFrameworkCoreSample.dll",
27+
"args": [],
28+
"cwd": "${workspaceFolder}",
29+
"stopAtEntry": false,
30+
"serverReadyAction": {
31+
"action": "openExternally",
32+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
33+
},
34+
"env": {
35+
"ASPNETCORE_ENVIRONMENT": "Development"
36+
},
37+
},
38+
{
39+
"name": "KeyManagementSample",
40+
"type": "coreclr",
41+
"preLaunchTask": "KeyManagementSample-build",
42+
"request": "launch",
43+
"program": "${workspaceFolder}/../../artifacts/bin/KeyManagementSample/Debug/${env:TARGET}/KeyManagementSample.dll",
44+
"args": [],
45+
"cwd": "${workspaceFolder}",
46+
"stopAtEntry": false,
47+
"serverReadyAction": {
48+
"action": "openExternally",
49+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
50+
},
51+
"env": {
52+
"ASPNETCORE_ENVIRONMENT": "Development"
53+
},
54+
},
55+
{
56+
"name": "NonDISample",
57+
"type": "coreclr",
58+
"preLaunchTask": "NonDISample-build",
59+
"request": "launch",
60+
"program": "${workspaceFolder}/../../artifacts/bin/NonDISample/Debug/${env:TARGET}/NonDISample.dll",
61+
"args": [],
62+
"cwd": "${workspaceFolder}",
63+
"stopAtEntry": false,
64+
"serverReadyAction": {
65+
"action": "openExternally",
66+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
67+
},
68+
"env": {
69+
"ASPNETCORE_ENVIRONMENT": "Development"
70+
},
71+
},
72+
{
73+
"name": "Redis",
74+
"type": "coreclr",
75+
"preLaunchTask": "Redis-build",
76+
"request": "launch",
77+
"program": "${workspaceFolder}/../../artifacts/bin/Redis/Debug/${env:TARGET}/Redis.dll",
78+
"args": [],
79+
"cwd": "${workspaceFolder}",
80+
"stopAtEntry": false,
81+
"serverReadyAction": {
82+
"action": "openExternally",
83+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
84+
},
85+
"env": {
86+
"ASPNETCORE_ENVIRONMENT": "Development"
87+
},
88+
}
89+
]
90+
}

0 commit comments

Comments
 (0)