Solution has projects that are located outside the solution folder

For anyone who experienced this right after adding a xUnit .Net Core test project, the solution/workaround is in a comment from tintow on the excellent answer from dmcquiggin:

I was facing the same problem and found a fairly simple workaround. As dmcquiggen pointed out, this is related to MS Test. I found that by simply unloading the MS Test project before checking in resolved this problem and the test project is still checked into source control. Then just reload the MS Test project and it appears to work as normal. Maybe the underlying test package is not included but thats not a problem for me. – Tintow Oct 11 '19 at 11:59


Please see Update below

Judging by the Visual Studio version number in your Solution File, I will assume you are using Visual Studio 2019, a relatively recent release (possibly a Preview version).

These are my observations:

  1. I am using Visual Studio Enterprise 16.20 (Preview 3.0), and also Visual Studio Enterprise 16.1.6 (Release).

  2. In either version of Visual Studio, if I create a solution under a custom directory, in my case, I use c:\Code\Projects, I receive exactly the same warning when attempting to Add a new Solution to Source Control, and selecting the version of Git that was installed with VS. Note that I have many Solutions and Directories under this location.

  3. If I use the extension Easy Git Integration tools, which in my configuration is using Tortoise Git as its underlying Git service, I do not get this warning message.

  4. If I OK the warning message, all files are successfully included in a subsequent Git Commit, and a valid .gitignore file is created. This includes successfully creating and pushing to GitHub, with all valid files.

  5. If I create the solution in the Visual Studio default of c:/username/source/repos, I do not receive a warning from either Preview or Release versions of Visual Studio. Note that I do not have any other Solutions or Directories under this location.

I would suggest you

a) Verify that there is not a git repository in a parent folder; this has sometimes confused Visual Studio - you will find references to this issue going back several years. This could well be your problem.

b) For peace of mind, use Git from a command line. Tortoise Git also has integration with Visual Studio.

If you could provide some more information about Visual Studio and Git versions, path hierarchy, whether it is a new Solution, it might help us pinpoint the issue.

UPDATE:

I have also experienced the same issue with .Net Core 2.2 projects, and after a long night with coffee, I can reproduce this.

With an MS Test Project:

a) The Test Project is the only one in the solution.

b) The following shows the contents of the Project File. Test Project file, showing References

c) Attempting to Add The Solution To Source Control i.e. Visual Studio default Git plugin, displays the message regarding source file tree:

Error Message from Git provider

d) Switching the source control to a third-party plugin, EZ-Git, allows the Git repository to be created without any issue.

EZ Git successfully creates repo

e) I reverted back to an archived version from a zip file, with no Git integration, and removed individual packages to isolate the cause; the result of this is that when the following line is removed, Visual Studio's default Git will successfully create a repository, with no error message.

<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />

f) The issues appears to be how Visual Studio handles the dlls of the MSTest.TestAdaptor, which by default are treated as if they are part of the Project, yet they are located outside the Solution folder structure, in the c:/Users/username/.nuget directory.

g) Adding ExcludeAssets to the MSTest.TestAdaptor will remove the error message, but, fairly obviously, it breaks the Visual Studio Test Runner.

<PackageReference Include="MSTest.TestAdapter" Version="1.4.0">
  <ExcludeAssets>all</ExcludeAssets>
</PackageReference>

It may be possible to find a combination of IncludeAssets, ExcludeAssets, and PrivateAssets to allow both proper functioning of Visual Studio Git, and Test Runner.

h) NOTE: The behaviour as detailed above also applies to xUnit, i.e.

<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />

Which indicates that the issue is related to dependencies around Visual Studio and the Microsoft TestPlatform.