TarkaDaal TarkaDaal - 1 year ago 123
ASP.NET (C#) Question

Unit testing ASP .NET Core project with CLR 4.6.1 libraries

I am having a hell of a time building an ASP .NET Core project running on CLR 4.6.1. It uses legacy CLR 4.6.1 libraries, which has been a massive problem. Because the .NET Core VS tooling can't deal with building the project properly, I've had to write build scripts that fix it up - the result being that VS can't build a working version of the project.

With this in mind, how can I unit test this? Ideally, I want a standalone test runner that can load a pre-compiled project, to avoid the test tooling having to build my main project.

I've tried both MSTest (it can't see the references to the SUT), and Xunit using

dotnet test
(which tries to build the project).

As requested, my (slightly sanitised)

"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "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",
"System.Configuration.Abstractions": "1.0.0"

"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"

"frameworks": {
"net461": {
"dependencies": {
"MyLib.Common": {
"target": "project"
"MyLib.Integration": {
"target": "project"
"MyLib.Functions": {
"target": "project"
"MyLib.Numbers": {
"target": "project"

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true

"publishOptions": {
"include": [

"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]

Answer Source

I can't submit a comment due to reputation, have you tried the NUnit Test Runner? It comes as a standalone console application and takes the compiled test DLL name as a parameter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download