0

I'm trying to run some NUnit tests written in Visual Studio on the command line using NUnit console. The tests are built using .NET 4.5.

To run them, I'm typing:

nunit3-console mytests.dll

And I keep getting a pop-up which tells me "an application on your PC needs the following Windows feature: .NET Framework 3.5 (includes .NET 2.0 and 3.0).

I've tried forcing NUnit to use 4.5 by saying

nunit3-console /framework:net-4.5 mytests.dll

But I get the same thing.

I tried installing .NET 3.5, but it can't be installed (I guess because I don't need it as I already have 4.5).

The tests run fine when run from Visual Studio using ReSharper or in the NUnit GUI...

I've created a really simple solution (tried with .NET 4 and .NET 4.5) which has a NuGet reference to NUnit 2.6.4 and one class (below):

[TestFixture]
public class Class1
{
    [Test]
    public void MyTest()
    {
        Assert.Pass();
    }
}

I still get the same error.

How can I fix this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rozza
  • 927
  • 2
  • 11
  • 24
  • How did you install NUnit console, using the MSI or via NuGet? We haven't seen this before, so would like to understand what the issue is. – Rob Prouse Oct 10 '17 at 13:34
  • I installed the console using the msi but the nunit referenced in the solution is installed using nuget... – rozza Oct 10 '17 at 13:47
  • Can you try the NuGet version of the console? I want to see if this is an MSI issue. – Rob Prouse Oct 10 '17 at 14:00
  • Brilliant - works perfectly using the NuGet version :-D thank you! – rozza Oct 10 '17 at 14:09

1 Answers1

1

That executable itself (nunit3-console) must have been produced by C# compiler to target .NET Framework 2.x/3.x (for the so called compatibility). Thus, when it runs on a pure .NET Framework 4.x Windows, you see the other compatibility feature by Microsoft, where it always prompts and asks to install .NET Framework 3.x (you must do that via Programs | Add/Remove Windows feature). Both of them are ridiculous as people should rarely use .NET Framework 2.x/3.x (though Microsoft will keep supporting .NET Framework 3.x as part of Windows).

To get rid of that prompt, you can enable .NET Framework 3.5 (which also gives you the bits to compile against .NET Framework 2.x/3.x). Or you modify its nunit3-console.exe.config file to use <supportedRuntime> to force .NET 4.x is used to load this executable.

I guess the NuGet version contains a proper .exe.config, while the MSI version not. You can analyze further for sure.

Lex Li
  • 60,503
  • 9
  • 116
  • 147