Xunit namespace not found in Visual Studio Code

I am using Visual Studio Code for .NET Core Project. I have a basic ASP.NET project for which I want to create a separate modules project, I created a subfolder and ran

dotnet new xunit
dotnet restore

      

When I tried to run it from the "dotnet build" cli "dotnet run" it worked successfully, however in visual studio it says it cannot find the Xunit namespace

enter image description here enter image description here

This is very strange because the Visual Studio Code has worked for me so far, it never had dependency problems, it only has this Xunit problem.

Anyone familiar with this problem?

+3


source to share


2 answers


I tried to open the test project directly with vscode (instead of opening the root project containing the test project in a subfolder) and now vscode recognizes Xunit.

Then I reopened the root project with vscode, added Xunit to the root project's csproj file, ran a "dotnet" restore on the root project, and now Xunit is recognized in the test project.



The thing is, vscode (or is it Omnisharp? I'm not sure) probably only looks at the root csproj file and ignores any csproj file that is in a subfolder.

+3


source


I had the same problem. This was solved by entering "Restart Omnisharp" in the Command Palette.



+6


source







All Articles