23

I tried to add my solution to the local repository by selecting File|Add to Source Control, but I got the following message.

Source Control - Git
The current solution has projects that are located outside the solution folder.These projects will not be source controlled in Git repository.To add all the projects to a single Git repository please consolidate all projects under a single folder.

However, all of my projects are within my solution folder. The only thing I'm uncertain about is that I added a NuGet package to one of my projects and I don't see that anywhere. It appears as the following in the project's csproj file.

<ItemGroup>
  <PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
</ItemGroup>

Does anyone know if that could cause this error? I was able to click OK and it created the local repository, but I want to put it on GitHub and so I'd like to figure out what the issue is.

As an additional question, when adding a solution like this to GitHub, would I normally include any packages like this? I expected a packages folder but I didn't get one.

Here's a screenshot of the solution:

enter image description here

And here's my solution file:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28922.388
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toxic", "Toxic\Toxic.csproj", "{DEAAC3F5-B48F-4601-ADC7-ECFE1519A841}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toxic.Desktop", "Toxic.Desktop\Toxic.Desktop.csproj", "{A4EAA8D5-C085-4960-A871-74F68F6F9BC7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Toxic.Web",    "Toxic.Web\Toxic.Web.csproj", "{49E8312B-506E-4AC1-8524-37BB601EC889}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToxicTests", "ToxicTests\ToxicTests.csproj", "{131B2077-A4C2-48EA-A1E1-8CA1A38097BD}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {DEAAC3F5-B48F-4601-ADC7-ECFE1519A841}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {DEAAC3F5-B48F-4601-ADC7-ECFE1519A841}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {DEAAC3F5-B48F-4601-ADC7-ECFE1519A841}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {DEAAC3F5-B48F-4601-ADC7-ECFE1519A841}.Release|Any CPU.Build.0 = Release|Any CPU
        {A4EAA8D5-C085-4960-A871-74F68F6F9BC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {A4EAA8D5-C085-4960-A871-74F68F6F9BC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {A4EAA8D5-C085-4960-A871-74F68F6F9BC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {A4EAA8D5-C085-4960-A871-74F68F6F9BC7}.Release|Any CPU.Build.0 = Release|Any CPU
        {49E8312B-506E-4AC1-8524-37BB601EC889}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {49E8312B-506E-4AC1-8524-37BB601EC889}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {49E8312B-506E-4AC1-8524-37BB601EC889}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {49E8312B-506E-4AC1-8524-37BB601EC889}.Release|Any CPU.Build.0 = Release|Any CPU
        {131B2077-A4C2-48EA-A1E1-8CA1A38097BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {131B2077-A4C2-48EA-A1E1-8CA1A38097BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {131B2077-A4C2-48EA-A1E1-8CA1A38097BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {131B2077-A4C2-48EA-A1E1-8CA1A38097BD}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {2076F481-A5C7-4132-874E-47767C93475D}
    EndGlobalSection
EndGlobal

UPDATE:

It seems I now get this message every time I add a new project to Source Control. There seems to be something fundamentally going on here as I do not think I am referencing any external files, and I think my solution files show that. Note that even though I get this message, it still adds the solution to source control and everything seems to be working okay.

I do not have a command-line GIT program and would really prefer not to install anything else if there's any way to see what's going on without it.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
  • It might be due to some file which might be outside the solution folder. Could you verify, you do not have any files outside project/solution folder by checking csproj files. – Dipen Shah Jul 08 '19 at 19:34
  • If everything seems fine it might just be some corrupted file. Remove all git related files and then reopen solution and try adding it to source control. – Dipen Shah Jul 08 '19 at 19:37
  • @DipenShah: I don't see anything like that. The only exception are the package references, which have no path. Note that I did find that it might only be happening on solutions that contain an MS Test (Core) project. But again, the only references that aren't in the folder appear to be the package references. – Jonathan Wood Jul 08 '19 at 19:38
  • @DipenShah: As I added in my update, this appears to be happening every time I add a solution to source control. These are different solutions. So the issue is more systemic than that. – Jonathan Wood Jul 08 '19 at 19:39
  • I found a similar article here..! wonder if this would help. - https://social.msdn.microsoft.com/Forums/vstudio/en-US/48f7cd1f-9f61-4c14-af4a-715ae54d19dc/the-current-solution-has-projects-that-are-located-outside-the-solution-folder-so-i-cant-add?forum=visualstudiogeneral – Ganesh Tiwari Jul 15 '19 at 14:34

7 Answers7

13

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.

dmcquiggin
  • 3,230
  • 24
  • 37
  • I'm using the current version of Visual Studio (and have probably updated once or twice since posting this question) -- no preview. I'm using the default *repos* folder for my projects. It seems like it might have something to do with adding .NET Core test projects (my main project is a .NET Standard class library). Using a command line doesn't give me peace of mind. So I think I'm looking for a more solid reason to install that. – Jonathan Wood Jul 10 '19 at 21:53
  • I am using .Net Core Tests projects, with .Net Standard class libraries, and so far, I have not noticed any correlation. This is with various versions of .Net Core, including stable and latest preview. Interestingly, I have zero problems with VS Code, which in theory is using the same Git provider. The mystery deepens... – dmcquiggin Jul 11 '19 at 08:23
  • Please see updated answer; the issue does seem to be specific to .Net Core Test Projects. – dmcquiggin Jul 16 '19 at 05:40
  • Yes, I've found it to be related to .NET Core test projects. I need more time to go over what you posted, but seems to be the best answer so far and the bounty is expiring so I've marked your answer as the correct one. Thanks. – Jonathan Wood Jul 16 '19 at 05:46
  • I am facing the same issue. Dotnet Core 2.2 with MS Test project – s k Sep 20 '19 at 10:07
  • 3
    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
  • While its true that yes your ez git tool doesnt cause an issue it doesnt allow the posting to devops only github how does one configure it for dev ops. – c-sharp-and-swiftui-devni Dec 26 '19 at 17:51
4

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

1

Double-check in command-line by going to the root folder of your Git repository, and type:

git status

Do check that your solution file does show up in the list of files to be added.
Otherwise, that means the Git repository is in one folder, while the solution and its projects are in another path entirely.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Do I have to install additional software to be able to access the git command line? – Jonathan Wood Jun 09 '19 at 15:49
  • @JonathanWood Git for Windows: https://git-scm.com/download/win, as illustrated in https://learn.microsoft.com/en-us/azure/devops/repos/git/share-your-code-in-git-cmdline?view=azure-devops#download-and-install-git. – VonC Jun 09 '19 at 16:06
1

I was facing the same issue and I solved it using GitTools extension . I have the following structure for my git repository:

enter image description here

In my case, I just wanted to track the files in the src folder. However, my project solution files are found in the bin folder. So, everytime that I tried to create the repository using the File|Add to Source Control or simple clicking on the git icon:

enter image description here

I got your message:

“ Source Control - Git The current solution has projects that are located outside the solution folder.These projects will not be source controlled in Git repository. To add all the projects to a single Git repository please consolidate all projects under a single folder.”

Which I understood that because my source files in the src folder are linked to my project solution but they are not found in the project solution folder (i.e. \bin) they cannot be added to the source control using “Source Control – Git”. Probably, I understood the message in the wrong way, but my solution works.

Just let's try to double-check the path to the solution folder:

1) Right click project solution -> open folder in file explorer

enter image description here

2) And we can see that my project solution folder (i.e. bin folder) does not contain the src folder that I want to track. So, VS git is complaining about it.

enter image description here

So, I solved the problem by installing: a) Tools -> Extensions and Updates -> Git tools

enter image description here

Note: You will probably need to restart Visual Studio.

b) After the installation, you will have another menu: Git Tools

enter image description here

c) Just select: Git ini and you will have your new repository. You will not notice any particular change.

enter image description here

d) You can go again to the GitTools -> GitBash and just type Git Status to test:

enter image description here

Notice that the git repository was created in the /projects/DRRsiddonOri3/bin folder which contains the project solution.

The price to pay is that you will have to commit using Git Bash from the GitTools menu(i.e. manually from Git Bash), if it bothers you.

However, I was not able to add /src folders because it is out of the git repostiroty (/projects/DRRsiddonOri3/bin).

In my case, I needed to create the git repository in /projects/DRRsiddonOri3/

So, I follow this path: GitTools->GitBash and change the directory from /projects/DRRsiddonOri3/bin (project solution) to /projects/DRRsiddonOri3/ and create the repository

enter image description here

Test: Windows 10 Visual Studio Community 2017 Version 15.9.6

jorge
  • 364
  • 3
  • 8
0

This was happened with me a few months ago (on Visual Studio 2017). And following solved the issue :

  1. Close Visual Studio
  2. Delete .git folder (which is hidden by default)
  3. Open Visual Studio. Add the solution to source control

Don't forget to check in case there is any .git folder in the project root folder.

Note : You'll loose the historical data.

Sukhi
  • 13,261
  • 7
  • 36
  • 53
0

Delete .vs folder in the solution folder.

This solved it in my case. Reason for the problem in my case may have been that I had moved the whole Solution folder to another location (one level up). I assume some of the old paths were still lingering in the .vs cache. (Be sure to close Visual Studio before deleting this folder.)

Erik Bongers
  • 416
  • 2
  • 10
0

Also in VS 2022 after installing NuGet package before first commit. I created local Git repo , then in the output pane toggled Show output from: Source - Control Git

This revealed Your solution contains files outside the solution folder which will not be managed by Git: C:\Users\golfer\.nuget\packages\microsoft.azure.cosmos\3.31.2...

I was was expecting Nuget packages to be installed in the project subfolder, instead they were installed in the global packages cache

Having established this, I can safely ignore the error.

https://learn.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders

golfalot
  • 956
  • 12
  • 22