AWS Serverless how to use "sam local start-api" to debug .net core 3.1 applications - aws-serverless

I would like to start serverless application locally and then debug it using Visual Studio. I see command line arguments --debug-port, --debugger-path, --debug-args and --debug-function, but no example of how these can be used for .net core.

This is what I'm using for Visual Studio Code. I'm on Windows using dotnetcore3.1.
Firstly, I had to download the Linux vsdbg debug files (yes, Linux, as these files will be mounted in the SAM docker container)
https://vsdebugger.azureedge.net/vsdbg-17-0-10712-2/vsdbg-linux-x64.tar.gz
Unzip them into a folder, e.g. C:\vsdbg
I have a task to launch SAM. My tasks.json looks like:
{
"version": "2.0.0",
"tasks": [{
"label": "sam local api",
"type": "shell",
"command": "sam",
"args": [
"local",
"start-api",
"-d", "5858",
"--template", "${workspaceFolder}/template.yaml",
"--debugger-path", "C:\\vsdbg",
"--warm-containers", "EAGER"
],
}]
}
IMPORTANT:
** --debugger-path points to the linux debug files folder. the sam cli will mount the files for you.
** I had to use --warm-containers EAGER to keep the container from closing after every request
launch.json looks like this:
{
"name": "sam local api attach",
"type": "coreclr",
"processName": "dotnet",
"request": "attach",
"pipeTransport": {
"pipeCwd": "${workspaceFolder}",
"pipeProgram": "powershell",
"pipeArgs": [
"-c",
"docker exec -i $(docker ps -q -f publish=5858) ${debuggerCommand}"
],
"debuggerPath": "/tmp/lambci_debug_files/vsdbg",
"quoteArgs": false
},
"sourceFileMap": {
"/var/task": "${workspaceFolder}"
}
},
This bit: $(docker ps -q -f publish=5858) gets the id of your docker container by filtering on the port that you're using.
This took quite a bit of fiddling to get working, I'm surprised it's not easier or at least some decent documentation on it.

Related

Shorthand to speficy tests to run in dotnet core

I am aware of the --filter option to select the tests to run in dotnet core from the command line. For instance:
dotnet test --filter FullyQualifiedName!~IntegrationTests
What I am looking for is a way to do something like this?
dotnet test --onlyUnitTests
Where --onlyUnitTests would defined by the user in a settings file of some sort. Something like:
{
"onlyUnitTests": "--filter FullyQualifiedName\!~IntegrationTests"
}
Is this possible?
The closer a I got is adding a task in the file tasks.json
"tasks": [
{
"label": "Run Unit Tests",
"command": "dotnet",
"type": "shell",
"args": [
"test",
"--filter",
"FullyQualifiedName\!~IntegrationTests"],
"problemMatcher": []
},
Now if I do Ctrl+Shift+P -> Run Tasks -> Run Unit Tests all my unit tests get executed.

How to enable x11 forwarding in vscode integrated terminal?

X11 forwarding working fine in ubuntu's terminal. but if I try to run any GUI from a remote in my VSCode terminal, it shows : cannot connect to X server.
Any suggestions?
I found a solution using the menubar run and run without debugging option.
Just we need to configure the launch.json file and open a terminal from the client pc with this command ssh -Y -i ~/.ssh/Key.pem username#server.
In my case launch.json looks like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"args": ["--target", "dataset", "--output", "dataset_softmax", "--nChannel", "32", "--minLabels", "8", "--filetype", "png"],
"console": "integratedTerminal",
"env": {
"DISPLAY": "localhost:10.0"
},
}
]
}

MSBUILD : error MSB1008: Only one project can be specified. Switch: Release

I am trying to publish my code onto a linux server by using
dotnet publish –-configuration Release
in the terminal command line. This should create a folder in bin/release/publish with all of the files ready to be deployed onto the server.
however, I get an error message which says
"MSBUILD : error MSB1008: Only one project can be specified. Switch: Release" and nothing gets published to the bin folder.
I have created a settings.json folder in the vscode folder
{
"deploy.reloaded": {
"packages": [
{
"name": "Version 1.0.0",
"description": "Package version 1.0.0",
"files": [
"Schedule.API/bin/Release/netcoreapp3.0/publish/**"
]
}
],
"targets": [
{
"type": "sftp",
"name": "Linux",
"description": "SFTP folder",
"host": "192.168.0.152", "port": 22,
"user": "webuser", "password": "password",
"dir": "/var/www/schedule",
"mappings": {
"Schedule.API/bin/Release/netcoreapp3.0/publish/**": "/"
}
}
]
}
}
You seem to have a copy/paste error in the first dash here:
dotnet publish –-configuration Release
The first dash is – (U+2013 : EN DASH). It should be a plain dash - (U+002D : HYPHEN-MINUS), like the second one. This should work:
dotnet publish --configuration Release

Fresh install of Trellis by Roots on Ubuntu & VituralBox is missing composer.json under /srv/www/website.com/current

This is the error message I got when I first run 'vagrant provision' (after command 'vagrant up' blocked in 'Mounting NFS shared folders...') under the trellis directory:
TASK [wordpress-install : Install Dependencies with Composer] ******************
System info:
Ansible 2.9.11; Vagrant 2.2.9; Linux
Trellis version (per changelog): "Removes ID from Lets Encrypt bundled certificate and make filename stable"
---------------------------------------------------
Composer could not find a composer.json file in /srv/www/example.com/current
To initialize a project, please create a composer.json file
as described in the https://getcomposer.org/ "Getting Started"
section failed: [default] (item=example.com) =>
{
"ansible_loop_var": "item",
"changed": false,
"item": {
"key": "example.com",
"value": {
"admin_email": "admin#example.test",
"cache": {
"enabled": false
},
"local_path": "../site",
"multisite": {
"enabled": false
},
"site_hosts": [
{
"canonical": "example.test",
"redirects": [
"www.example.test"
]
}
],
"ssl": {
"enabled": false,
"provider": "self-signed"
}
}
},
"stdout": "Composer could not find a composer.json file in /srv/www/example.com/current\nTo initialize a project, please create a composer.json file as described in the https://getcomposer.org/ \"Getting Started\" section\n",
"stdout_lines": [
"Composer could not find a composer.json file in /srv/www/example.com/current",
"To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ \"Getting Started\" section"
]
}
PLAY RECAP *********************************************************************
default : ok=125 changed=83 unreachable=0 failed=1 skipped=34 rescued=0 ignored=0
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
How do I fix this? Where to find the right composer.json for Trellis, Bedrock, and Sage for local development on Linux?
Ubuntu 19.10

Issue using VSCode tasks with dotnet run

I have two projects in a parent folder:
parentFolder
| webApiFolder
| testsFolder
Using the terminal, I need to pass the --project parameter to dotnet run. As such, I figure it'd be easier to just create a task and run the task instead. However, I can't get the task to work.
Task:
{
"label": "run api",
"command": "dotnet",
"type": "process",
"args": [
"run",
"--project ${workspaceFolder}\\WebApi\\mercury-ms-auth.csproj"
],
"problemMatcher": "$msCompile"
}
Output:
> Executing task: C:\Program Files\dotnet\dotnet.exe run --project G:\Git_CS\mercury-ms-auth\WebApi\mercury-ms-auth.csproj <
Couldn't find a project to run. Ensure a project exists in g:\Git_CS\mercury-ms-auth, or pass the path to the project using --project.
The terminal process terminated with exit code: 1
However, if I run dotnet run --project G:\Git_CS\mercury-ms-auth\WebApi\mercury-ms-auth.csproj, that launches the project perfectly.
Similarly, my test and code coverage task works perfectly:
{
"label": "test with code coverage",
"command": "dotnet",
"type": "process",
"args": [
"test",
"${workspaceFolder}/Tests/Tests.csproj",
"/p:CollectCoverage=true",
"/p:CoverletOutputFormat=cobertura"
],
"problemMatcher": "$msCompile"
}
One solution is to "type": "shell" and pass through the whole command.
{
"label": "run api",
"command": "dotnet run --project ${workspaceFolder}\\WebApi",
"type": "shell",
"problemMatcher": "$msCompile"
}

Resources