1

I'm using xUnit for implementing tests. I used to install the xUnit Visual Studio runner, xunit.runner.visualstudio nuget package to run tests using the VS GUI.

Below is are xUnit-related branches of the dependency tree in VS. You can clearly see the xUnit VS runner has no dependencies:

xUnit dependencies for a net472 project

Visual Studio is suddenly asking me to install the Microsoft.NET.Test.Sdk nuget in order to run tests in the GUI. Anyone knows why?

Note:

  • I have been using VS 2019 for over a year frequently updating asap. The problem occurred only yesterday. I'm on v16.7.2 now.
Bahaa
  • 1,577
  • 18
  • 31
  • Probably because xunit runner for VS requires it? – Pavel Anikhouski Sep 07 '20 at 18:15
  • It's been working without it for years. No changes in code or dependencies were introduced, only updates of VS itself. – Bahaa Sep 07 '20 at 18:42
  • Did you install the `xunit.runner.visualstudio 2.4.1`? If not, you should update the package to use `2.4.1` version. – Mr Qian Sep 08 '20 at 02:45
  • Also, what is your old vs version and did it a `net core 3.1` project? – Mr Qian Sep 08 '20 at 03:02
  • Yes. I have `xunit.runner.visualstudio` v2.4.1. The project is a .net framework project – Bahaa Sep 08 '20 at 06:50
  • Actually, there is a xunit project template in VS2019 and the default template contains the nuget package `Microsoft.NET.Test.Sdk`. Besides, the mainstream xunit projects are all based on `net core` rather than `net framework`. Also, I wonder what is your previous vs version. Perhaps there is a big gap between them. Since the latest VS IDE, it actually require that nuget package and your project is net framework, the nuget `xunit.runner.visualstudio 2.4.1` will not install that dependency `Microsoft.NET.Test.Sdk` unless your project is based on `net core` . So the error arises. – Mr Qian Sep 08 '20 at 08:25
  • The latest VS2019 needs that package and the default project template contains that. Also, please try to create a new net core xunit test projest in VS2019 and you can migrate your old project into the new one to get the latest,easy way to avoid this. Besides, I have updated my answer and you can check it. – Mr Qian Sep 08 '20 at 08:26
  • Thanks for the info about the difference between `xunit.runner.visualstudio` for various target frameworks. Though not answering the question. I assures me I had no missing dependencies the whole time. I think it's VS, which started to ask for it explicitly. – Bahaa Sep 08 '20 at 08:48
  • Actually, vs has required this nuget package on the latest version. For your updated issue, enter your csproj file, change your target framework to `netcoreapp3.1`. Use like this `netcoreapp3.1`. Then rebuild your project, I think you will see the dependency under it. – Mr Qian Sep 09 '20 at 05:50
  • Or not change the target framework and then directly install that required nuget package `Microsoft.NET.Test.Sdk` directly. I have updated my answer. – Mr Qian Sep 09 '20 at 05:59

1 Answers1

9

During xunit.runner.visualstudio version <=2.4.1, it already contains a dependency Microsoft.NET.Test.Sdk, and the later version 2.4.2 and 2.4.3 has removed such dependency Microsoft.NET.Test.Sdk.

also, not sure whether the issue is caused by the update of VS which requires such package recently. And from the default xunit template project, it contains the package Microsoft.NET.Test.Sdk by default. So I think VS requires this package.

Maybe in some specific cases, no error will be reported without this package, but there will be no accidental errors in the follow-up, so install this package.

Besides, not sure whether you have install the xunit.runner.visualstudio version <= 2.4.1 which already has such package, and then update this package later during the VS Update.

Suggestion

1), try to reinstall xunit.runner.visualstudio nuget package, first uninstall it and then install the version 2.4.1.

Then, close VS Instance, delete .vs hidden folder under the solution folder, bin and obj folder.

2) try to change the target framework version of your project(it will install any default nuget packages based on the target framework version).

Right-click on your project Properties-->Application--> change target framework to anyone else first and then change it back to the original one.

enter image description here

In addition, if these do not work, you should share a sample of your project with us and provide more detailed info so that it will help us troubleshoot the issue more quickly.

Update 1

For your updated issue, or you could install the nuget package Microsoft.NET.Test.Sdk directly on your project.

Or change your project target framework to net core.

Use this in csproj file:

<TargetFramework>netcoreapp3.1</TargetFramework>

Then, rebuild your project and you can see the dependency under it.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • 1
    This should be marked as accepted, adding the `Microsoft.NET.Test.Sdk` did the trick for me. – TJ L Jan 19 '21 at 21:30
  • I had tried installing the package as the error suggests doing, but that did not help. Changing the target framework did the trick, though. Thank you so much! – James R. Sep 17 '21 at 17:51