vstest pass pass parameter to "dotnet test" execution - vstest

Description
I want to run a .net core NUnit test with the vstest.console.
This is working fine but I want to pass to the "dotnet test" execution a parameter, in my case "--no-build"
How I can parse this parameter to the dotnet execution? I have not found the right runsettings variable
Steps to reproduce
vstest.console.exe " "project.json" /UseVsixExtensions:true /Settings:settings.runsettings
Expected behavior
["C:\Program Files\dotnet\dotnet.exe" test "project.json" --port 55307 --no-build]
Actual behavior
["C:\Program Files\dotnet\dotnet.exe" test "project.json" --port 55307 ]
Environment
windows 7
project.json
{
"version": "1.0.0-*",
"dependencies": {
"NUnit": "3.5.0",
"dotnet-test-nunit": "3.4.0-beta-3"
},
"testRunner": "nunit",
"frameworks": {
"netcoreapp1.0": {
"imports": "portable-net45+win8",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-*",
"type": "platform"
}
}
}
}
}`

This was the answer from the vstudio develoment team
https://github.com/Microsoft/vstest/issues/383

Related

Mocha test (in Visual Studio/ Resharper) gives different results from 'npm test'

I want to test some JS files that are within a Visual Studio solution.
I've been following https://github.com/MicrosoftDocs/visualstudio-docs/blob/main/docs/javascript/unit-testing-javascript-with-visual-studio.md .
I have a file in /js/Layers.js:
class Layers {
constructor() {
this.xxxLayers = [];
}
}
I have test file in /test/Layers.test.js:
require("./../js/Layers");
describe('Layers class ctor',
function () {
it('should have initialised arrays',
function () {
let sut = new Layers();
expect(true).toBe(true);
});
});
When I run this in Visual Studio (using the Resharper test runner) it passes without raising an error.
My package.json is:
{
"name": "nodejs-web-app1",
"version": "0.0.0",
"description": "NodejsWebApp1",
"main": "server.js",
"author": {
"name": ""
},
"devDependencies": {
"eslint": "^8.21.0"
},
"eslintConfig": {},
"dependencies": {
"mocha": "^10.2.0"
},
"scripts": {
"test": "mocha test"
}
}
When I run npm test I see that the test is run but it does not seem to load the Layers.js file that I wish to test:
$ npm test
> nodejs-web-app1#0.0.0 test
> mocha test
Layers class ctor
1) should have initialised arrays
0 passing (3ms)
1 failing
1) Layers class ctor
should have initialised arrays:
ReferenceError: Layers is not defined
at Context.<anonymous> (test\Layers.test.js:9:27)
at process.processImmediate (node:internal/timers:471:21)
I wonder if Resharper's test runner is filling in a gap that I have missed . Interestingly compared to the advice in https://github.com/MicrosoftDocs/visualstudio-docs/blob/main/docs/javascript/unit-testing-javascript-with-visual-studio.md I cannot see the tests in the VS Test Explorer. only in the Resharper one, although that feels like a different issue. What I want is to be able to run the tests from the command line so I can add it to our CI pipeline.
Can anyone advise?
Thanks.

Typescript build task in VSCode on Windows 10 with Windows Subsystem for Linux

My VSCode settings (workspace settings in my case) are setup to use bash as the default terminal:
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\bash.exe"
}
I need this to be able to debug my app.
My tasks.json looks like that:
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "./tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
So when I try to build my project / run the build task (i.e. Ctrl + B), I get the following error:
> Executing task: tsc -p "c:\PATH_TO_MY_PROJECT\tsconfig.json" <
error TS5058: The specified path does not exist: 'c:\PATH_TO_MY_PROJECT\tsconfig.json'.
The terminal process terminated with exit code: 1
If I disable bash in my settings an use the default Windows terminal, the build works fine.
I remember it working few VSCode updates ago, but it stopped working in the latest VSCode versions. Not sure how that's related.
I tried to fix this for a while, but finally gave up on the built-in Typescript task and instead just used a custom task:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Typescript watch",
"type": "shell",
"command": "tsc --watch",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [
"$tsc"
]
}
]
}

Deploy .Net Core MVC app w/ class library to Ubuntu 16.04:

I wanted to build a simple .net core MVC app with a single class library for data access, to get an idea of what it takes to build/deploy/run Core on Linux. Not nearly as simple as I had hoped!
EDIT: Here's a copy of the solution, if anyone is interested:
https://s3.amazonaws.com/kilonova-public/code/CoreCrossPlatform.zip
I threw together a VirtualBox VM w/ Ubuntu Server 16.04 and installed dotnet core per these instructions:
https://www.microsoft.com/net/core#ubuntu
I installed all the latest, necessary bits on the host (Win10) for VS 2015 and created a solution with an MVC app and single class library called "DataAccess". It's EF Core talking to MySQL using their latest core provider. It all runs flawlessly on the Win10 host when I run/debug it. Pulls up data and looks great.
"dotnet --version" on both the host and the VM gives me:
1.0.0-preview2-003121
However, when I deploy it to the Ubuntu VM, I get the following error on the class library dependency:
Project corecrossplatform (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling corecrossplatform for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/project.json(24,23): error NU1002: The dependency DataAccess does not support framework .NETCoreApp,Version=v1.0.
Compilation failed.
0 Warning(s)
1 Error(s)
Time elapsed 00:00:00.0187782
This happens whether I run "dotnet restore" or "dotnet run". To be perfectly honest, I'm not even sure I'm deploying this thing correctly. Documentation is spotty and I'm making some guesses. I copied everything from the project folder "src\CoreCrossPlatform" (contains bin, Program.cs, appsettings.json, etc.) onto the VM and this is where I'm executing the "dotnet" commands from, in the VM.
The DataAccess .json file:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.0.0",
"MySql.Data.Core": "7.0.4-IR-191",
"MySql.Data.EntityFrameworkCore": "7.0.4-IR-191",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
The MVC project.json:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"DataAccess": "1.0.0-*"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Something to note: When I run the sample project using "dotnet new" and restore, run vis the tutorial link above, it runs fine.
What am I missing? Another side question: What's the best way to publish this type of app to a Linux box? Am I even close on that part?
Thanks much.
EDIT: While kicking this dead horse all afternoon, I compared some notes I found online, related to this "NU1002" error, and the sample project "dotnet new" generates. I tried changing the "framework" section of both project.json files (MVC and classlib) to the following, with no success...same error:
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dnxcore50",
"dotnet5.6",
"portable-net45+win8"
]
}
}
EDIT: Much thanks to goaty: As he pointed out in the comments, copying over the entire solution and building it, results in a successful build. However, I cannot run it without an error. It doesn't seem to restore the MySQL EF Core dependency:
Project CoreCrossPlatformFlat (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling CoreCrossPlatformFlat for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/src/CoreCrossPlatformFlat/project.json(25,52): error NU1001: The dependency MySql.Data.EntityFrameworkCore >= 7.0.4-IR-191 could not be resolved.
Compilation failed.
0 Warning(s)
1 Error(s)
The DataAccess library exists outside of your src/ directory. Therefore the web project could not find the reference.
I recommend this structure
src/
|---DataAccess/
|---CoreCrossPlatform/
Hope that helps :)

Can't deploy ASP.net core RC2 targeting net451 or net46 to Azure Web App

I can't seem to be able to deploy my asp.net core RC2 app to Azure when I target the net451 or net46 framework.
When I try to reach my application I get the following error
The specified CGI application encountered an error and the server terminated the process.
Everything works when I deploy to my local IIS.
The Azure logger gives me
Failed to start process with commandline '%LAUNCHER_PATH% %LAUNCHER_ARGS%', Error Code = '0x80070002'.
I tried replacing %LAUNCHER_PATH% for dotnet and %LAUNCHER_ARGS% for myapp.exe in the web.config but still the same error occur.
Here is my project.json
{
"dependencies": {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net46": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Thanks
It seems that updating my web.config to specify the processPath did the trick.
I also had to delete the previous publish attempts for it to work properly.
<aspNetCore processPath=".\myapp.exe" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout"/>
With the same symptoms I checked the logs as #Pawel suggested.
The logs contained FileNotFoundException which was resolved by adding two dependencies to project.json.
"dependencies": {
...
"System.IO.FileSystem.Watcher": "4.0.0-rc2-24027",
"System.IO.FileSystem": "4.0.1-rc2-24027"
},
The issue is reported here
Azure doesn't support net461 and use better net451.
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
Publishing SkyIsTheLimit for .NETFramework,Version=v4.5.1/win7-x64

Can I chain npm configuration entries?

Use of the npm config section is simple, and cool, but I've run into one restriction with it: a config entry does not get expanded, so one cannot chain them, nor even access non-config values s.a. package version within the config.
Sample:
{
"name": "myproj",
"version": "0.1.2",
"//": "Here, '$npm_package_version' is not expanded",
"config": {
"target": "dist/myproj-$npm_package_version.js"
},
"scripts": {
"echo": "echo $npm_package_config_target",
}
}
This gives:
dist/myproj-$npm_package_version.js
instead of:
dist/myproj-0.1.2.js
Is there anything I can do about it? Chaining values like this is a useful feature - I'm surprised nom doesn't do it. Is there a reason not to?
References:
Node.js: How to setup different variables for prod and staging
How to use npm as a build tool
There's a few of ways this could be handled.
The simplest way is probably just to eval the string
{
"name": "myproj",
"version": "0.1.2",
"config": {
"target": "dist/myproj-$npm_package_version.js"
},
"scripts": {
"echo": "eval echo $npm_package_config_target"
}
}
If you're not comfortable with eval then you could either manually concat the string within the script:
{
"name": "myproj",
"version": "0.1.2",
"config": {
"target_prefix": "dist/myproj-",
"target_suffix": ".js"
},
"scripts": {
"echo": "echo $npm_package_config_target_prefix$npm_package_version$npm_package_config_target_suffix",
}
}
Or you could do away with using npms config and write a quick script instead, which can be composed with others:
{
"name": "myproj",
"version": "0.1.2",
"scripts": {
"config:target": "echo dist/myproj-$npm_package_version.js",
"echo": "echo $(npm run config:target)"
}
}

Resources