Xunit: Adding a project reference to my test project yields error CS0246: The type or namespace name 'Xunit' could not be found

Created on 22 Sep 2017  路  3Comments  路  Source: xunit/xunit

Code is here:
https://github.com/SurferJeffAtGoogle/csharp-docs-samples/tree/core/AuthSample/AuthTest

Running dotnet test in this directory works nicely:

> dotnet test
Build started, please wait...
Build completed.

Test run for C:\Users\rennie\gitrepos\dotnet-docs-samples\AuthSample\AuthTest\bin\Debug\netcoreapp2.0\AuthTest.d
ll(.NETCoreApp,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 15.3.0-preview-20170628-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
[xUnit.net 00:00:00.8725763]   Discovering: AuthTest
[xUnit.net 00:00:00.9823183]   Discovered:  AuthTest
[xUnit.net 00:00:01.0368701]   Starting:    AuthTest
[xUnit.net 00:00:01.2316710]   Finished:    AuthTest

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 2.4182 Seconds

Until I try to add a project reference to the .csproj:

  <ItemGroup>
    <ProjectReference Include="..\AuthSample.csproj" />
  </ItemGroup>

Then, I get this error:

> dotnet test
Build started, please wait...
AuthTest\UnitTest1.cs(2,7): error CS0246: The type or namespace name 'Xunit' could not be found (are you missing
 a using directive or an assembly reference?) [C:\Users\rennie\gitrepos\dotnet-docs-samples\AuthSample\AuthSampl
e.csproj]
AuthTest\UnitTest1.cs(8,10): error CS0246: The type or namespace name 'FactAttribute' could not be found (are yo
u missing a using directive or an assembly reference?) [C:\Users\rennie\gitrepos\dotnet-docs-samples\AuthSample\
AuthSample.csproj]
AuthTest\UnitTest1.cs(8,10): error CS0246: The type or namespace name 'Fact' could not be found (are you missing
 a using directive or an assembly reference?) [C:\Users\rennie\gitrepos\dotnet-docs-samples\AuthSample\AuthSampl
e.csproj]
By Design / Won't Fix

Most helpful comment

When I add the project reference, I get build failures:

pre-fix

The problem is that your projects are nested. If you make AuthSample and AuthTest peer folders, then everything works as expected.

All 3 comments

When I add the project reference, I get build failures:

pre-fix

The problem is that your projects are nested. If you make AuthSample and AuthTest peer folders, then everything works as expected.

Stumbled here with this same problem, solution worked for me. Thanks.

Thanks for the help!

Was this page helpful?
0 / 5 - 0 ratings