Visual Studio 2019 suddenly requires nuget Microsoft.NET.Test.Sdk to run xUnit unit-tests
Asked Answered
C

1

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.
Coagulate answered 7/9, 2020 at 16:25 Comment(10)
Probably because xunit runner for VS requires it?Citizen
It's been working without it for years. No changes in code or dependencies were introduced, only updates of VS itself.Coagulate
Did you install the xunit.runner.visualstudio 2.4.1? If not, you should update the package to use 2.4.1 version.Leitmotiv
Also, what is your old vs version and did it a net core 3.1 project?Leitmotiv
Yes. I have xunit.runner.visualstudio v2.4.1. The project is a .net framework projectCoagulate
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.Leitmotiv
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.Leitmotiv
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.Coagulate
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 <TargetFramework>netcoreapp3.1</TargetFramework>. Then rebuild your project, I think you will see the dependency under it.Leitmotiv
Or not change the target framework and then directly install that required nuget package Microsoft.NET.Test.Sdk directly. I have updated my answer.Leitmotiv
L
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.

Leitmotiv answered 8/9, 2020 at 3:32 Comment(2)
This should be marked as accepted, adding the Microsoft.NET.Test.Sdk did the trick for me.Feodora
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!Actuary

© 2022 - 2024 — McMap. All rights reserved.