Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xunit Namespace Could not be Found in Visual Studio Code

I'm using Visual Studio Code for a .NET Core Project. I have an ASP.NET Core Project for which i want to create a separate unit tests project, i created a sub folder and ran

dotnet new xunit
dotnet restore

When i tried to run it from the cli "dotnet build" "dotnet run" it ran successfully, however in visual studio, it says that it can't find the namespace Xunit

enter image description here enter image description here

This is very strange because Visual Studio code has worked fine for me so far, it never had problem with dependencies, it only has this problem with Xunit.

Anyone familiar with this issue?

like image 385
areller Avatar asked Jul 16 '17 11:07

areller


2 Answers

I had the same issue. It was solved by typing "Restart Omnisharp" in the Command Palette.

like image 67
Claus Hemberg Jørgensen Avatar answered Sep 26 '22 01:09

Claus Hemberg Jørgensen


I tried opening the test project directly with vscode (instead of opening the root project that contains the test project in a sub folder) and now vscode recognizes Xunit.

I then opened the root project with vscode again, added Xunit to the root project's csproj file, ran "dotnet restore" in the root project and now Xunit is recognized in the test project.

The thing is that vscode (or is it Omnisharp? i'm not sure) probably looks only at the root csproj file and ignores any csproj file that happens to be in a sub folder.

like image 22
areller Avatar answered Sep 24 '22 01:09

areller