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 reverting Project files back to their original state (VS 2017) #33

Open KwalityKoder opened 6 years ago

KwalityKoder commented 6 years ago

Within a Project, if I use NuGetReferenceSwitcher to switch from a NuGet to a Project Reference for NuGet Package X, and then use NuGetReferenceSwitcher to revert back to the NuGet reference, the .csproj file has an extra line added immediately following the <ItemGroup> ,<Reference Include="X"> nodes as follows:

<SpecificVersion>False</SpecificVersion>

I would expect the csproj file to remain completely unchanged after reverting back to the original NuGet package reference.


Coding fix was to modify ProjectModel.AddReference() to reset the SpecificVersion flag to true.

                // ReSharper disable once SuspiciousTypeConversion.Global
                if (_vsProject.References.Add(assemblyPath) is Reference4 reference)
                {
                    reference.SpecificVersion = true;
                }

where Reference4 is a new Interface I created following the instructions here

Setting the properties of a reference programmatically