RicoSuter / NuGetReferenceSwitcher

Visual Studio extension to switch between NuGet and project references.
http://nugetreferenceswitcher.org
Microsoft Public License
208 stars 69 forks source link

NuGetReferenceSwitcher not detecting NuGets when packages folder is /Packages (VS 2017) #32

Open KwalityKoder opened 6 years ago

KwalityKoder commented 6 years ago

I have some NuGet Packages used in two solutions. Solution #1 - all the projects referencing the NuGets are directly under the Solution. NuGetReferenceSwitcher lets me convert the NuGet Refs to local projects.

Solution #2 - all the projects are grouped into folders under the solution. The projects reference the same NuGet packages as Solution #1. This time NuGetReferenceSwitcher doesn't detect the same NuGet refs, so I can't convert the NuGet Refs to local projects.


The issue is in ProjectModel.LoadReference():

        private void LoadReferences()
        {
               :      :     :
                if (vsReference.Path.Contains("/packages/") || vsReference.Path.Contains("\\packages\\"))
                    NuGetReferences.Add(reference);
            }
        }

Our projects in Solution #2 use /Packages not /packages. A ToLower() call would fix this issue.


Can confirm using

if (vsReference.Path.ToLower().Contains("/packages/") || vsReference.Path.ToLower().Contains("\\packages\\"))
   NuGetReferences.Add(reference);

fixes the issue. This may also be the root cause of NuGet references not being detected within projects for other users too.


Obviously instead of just assuming that the NuGet packages folder is called /packages or /Packages, the best approach would be to for NuGetReferenceSwitcher to get the path directly from its definition inside the nuget.config file.

`

{some path here}

`