Shorthand to speficy tests to run in dotnet core - .net-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.

Related

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

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.

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

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"
}

How to debug a Deno Typescript code on Windows 10, x64

I 'm trying to debug a Deno project, but I dont know, how to debug this on Windows 10 using the lldb debugger as the documentation says.
The LLDB, on windows 10 seems to be not so easy to install.
///reference path="../../deno.d.ts"
import * as deno from 'deno';
import { color } from 'https://deno.land/x/colors/main.ts';
const s = new Set();
[*] s.add('test')
console.log(s);
[*] <-- a breakpoint
In order to debug with Deno:
Add somewhere in your code a debugger; line of code.
Run with --inspect-brk flag. deno run --inspect-brk ... or deno test --inspect-brk ... to debug tests.
Open chrome://inspect page on Chrome.
On the Remote Target section press to "inspect".
Press the Resume script execution button, the code will pause just in your breakpoint.
Reference: https://aralroca.com/blog/learn-deno-chat-app#debugging
If you use VSCode here is a launch.json I am using.
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Deno",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": ["run", "-A", "--inspect-brk", "index.ts"],
"port": 9229
}
]
}

Using tasks.json in Visual Studio Code to transpile both typescript and sass

I want to transpile both typescript and sass to javascript and css respectively. At The moment running this tasks.json file transpiles my typescript to javascript:
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// args is the HelloWorld program to compile.
"args": ["public/app/boot.ts"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
I only need to specify boot.ts and it transpiles all .ts files to js. It might be because my boot.ts file imports all my ts files. Here is my boot.ts file:
import {bootstrap} from 'angular2/platform/browser'
import {HelloWorld} from './hello_world'
import {TodoApp} from './todo_app'
bootstrap(HelloWorld);
bootstrap(TodoApp);
I would like to add code into the tasks.json file that will transpile the sass to css.
Here is a code snippet of what I could do to only transpile my sass:
{
"version": "0.1.0",
"command": "node-sass",
"isShellCommand": true,
"args": ["styles.scss", "styles.css"]
}
How do I add that code snippet so that it transpiles both the sass and the typescript?
Also, Will I be wanting to add any new sass files to the args array in tasks.json as I create them?
you can't do this with the tsc command. use npm instead.
package.json
{
"scripts": {
"build": "tsc public/app/boot.ts && node-sass styles.scss styles.css"
}
}
tasks.json
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "silent",
"args": ["-s", "run"],
"tasks": [{
"taskName": "build",
"problemMatcher": "$tsc",
"isBuildCommand": true
}]
}
I'm not sure when this feature was added, so it may not of helped the OP. I like this because it's built-in to the IDE. For the OP case they just need to decide which should be completed before the other.
The following snippet allows multiple tasks to be run, one after the other. A pre-build, build, and post-build, when building your project select the "Pre-Build & Build & Post-Build" to run them all. This is still a rather simple chain of tasks, and you could create multiple chains of any length with this technique, but they do tend to clutter up the tasks.json file.
"tasks": [
{
"label": "base",
"detail": "Pre-Build",
"type": "shell",
"command":["echo"],
"args": ["prebuild task"],
},
{
"label": "build",
"detail": "Pre-Build & Build",
"type": "shell",
"command":["echo"],
"args": ["build task"],
"dependsOn":["base"],
},
{
"label": "Post Build",
"detail": "Pre-Build & Build & Post-Build",
"type": "shell",
"command":["echo"],
"args": ["Post build task"],
"dependsOn":["build"],
}
]

Resources