RicoSuter/NuGetReferenceSwitcher

NuGetReferenceSwitcher throws if it encounters a new style PackageReference in a csproj

KwalityKoder opened this issue · 0 comments

`<ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="8.0.3" />

causes any other Nuget Refs to be skipped in a project due to throwing an exception.


Fix (which worked for me) is to add an extra line of code to ensure vsReference.Path is not null or empty before checking to see if its value contains /packages.

    private void LoadReferences()
    {
        References = new ExtendedObservableCollection<ReferenceModel>();
        NuGetReferences = new ExtendedObservableCollection<ReferenceModel>();

        foreach (var vsReference in _vsProject.References.OfType<Reference>())
        {
            var reference = new ReferenceModel(vsReference);
            References.Add(reference);

            if (!string.IsNullOrWhiteSpace(vsReference.Path))       // fix
            {
                if (vsReference.Path.ToLower().Contains("/packages/") || vsReference.Path.ToLower().Contains("\\packages\\"))
                    NuGetReferences.Add(reference);
            }
        }
    }