Skip to content

Commit

Permalink
Adds .NET Core Remote Debug Exploration (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmoran authored Jul 1, 2022
1 parent 61f2a1d commit 4c2ce23
Show file tree
Hide file tree
Showing 35 changed files with 37,759 additions and 0 deletions.
68 changes: 68 additions & 0 deletions dotnet-core-debug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# .NET Remote Debugging

Visual Studio Code can be configured to attach a remote debugging session into
a running container via `docker exec`. Presumably, this functionality could be
extended to work with Visual Studio and `kubectl exec`. These pieces of the
puzzle remain to be validated.

Contained in this exploration is a working prototype of the VSCode support for
debugging a .NET Core application built using buildpacks. This exploration
includes a simple buildpack that includes the `vsdbg` debugger in the
application container and includes extra flags and settings that enable remote
debugging of .NET Core applications in containers.

An RFC covering these buildpack features is [already
submitted](https://github.com/paketo-buildpacks/rfcs/pull/213) to the Paketo
project.

## Build the app

```
pack build debug-app \
--path ./app \
--buildpack ./buildpack \
--buildpack paketo-buildpacks/dotnet-core \
--env ASPNETCORE_ENVIRONMENT=Development \
--env BPE_ASPNETCORE_ENVIRONMENT=Development \
--env BP_DOTNET_PUBLISH_FLAGS="--configuration Debug"
```

## Setup VSCode

1. Add `.vscode/launch.json` to app source directory

```json
{
"configurations": [
{
"name": ".NET Core Docker Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeProgram": "docker",
"pipeArgs": [ "exec", "-i", "<container id>" ],
"debuggerPath": "/cnb/lifecycle/launcher vsdbg",
"pipeCwd": "${workspaceRoot}",
"quoteArgs": false
},
"sourceFileMap": {
"/workspace": "${workspaceRoot}"
}
}
]
}
```

2. Install Microsoft C# Extension

## Start debugging

1. Run the app with `docker run -p 8080:8080 debug-app`
2. Open a browser window to `http://localhost:8080`
3. Update `<container id>` field in `launch.json` with actual container id
4. Add a breakpoint in `Controllers/WeatherForecastController.cs`
5. Click on the "Fetch data" link
6. Wait for the editor to load the breakpoint
7. Confirm that VSCode opens the `Controllers/WeatherForecastController.cs`
file and stops at the line with a breakpoint
234 changes: 234 additions & 0 deletions dotnet-core-debug/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

.vscode/

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
bin/
Bin/
obj/
Obj/

# Visual Studio 2015 cache/options directory
.vs/
/wwwroot/dist/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Microsoft Azure ApplicationInsights config file
ApplicationInsights.config

# Windows Store app package directory
AppPackages/
BundleArtifacts/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
orleans.codegen.cs

/node_modules

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe

# FAKE - F# Make
.fake/
21 changes: 21 additions & 0 deletions dotnet-core-debug/app/ClientApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Loading

0 comments on commit 4c2ce23

Please sign in to comment.