NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 252 forks source link

VS 2017. References are not updated properly for a csproj files. #6242

Open ievgennaida opened 6 years ago

ievgennaida commented 6 years ago

Nuget.exe that added to a solution folder: 4.3.0.4168 Version from the visual studio information window: NuGet Package Manager 4.4.0 Package Manager Console Host Version 4.4.1.4633

.NetFramework project.

We have a solution with 100+csproj projects. When we do an update 2-3 random projects are not updated properly:

`

..\..\packages\A.Contracts.2.4.214.0\lib\net35\A.Contracts.dll
</Reference>`

Visual studio enterprise 2017 version 15.4.5

Operating System: Windows 10 Enterprise 64-bit (10.0, Build 10586) (10586.th2_release_sec.160527-1834) Processor: Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz (8 CPUs), ~2.5GHz Memory: 16384MB RAM. Available OS Memory: 16262MB RAM

Also I had windows reinstalled and visual studio installed from scratch.

See the full issue description: https://github.com/NuGet/Home/issues/5996#issuecomment-335292092

It was closed because of an old visual studio and nuget version. But now I have visual studio 2017 and problem still happens!

Update:

Nuget.exe was tested. Check was added for a MSBuildProjectSystem to catch whether versions are different:

  public Task AddReferenceAsync(string referencePath)
        {
            var fullPath = PathUtility.GetAbsolutePath(ProjectFullPath, referencePath);
            var relativePath = PathUtility.GetRelativePath(Project.FullPath, fullPath);
            var assemblyFileName = Path.GetFileNameWithoutExtension(fullPath);

            try
            {
                // using full qualified assembly name for strong named assemblies
                var assemblyName = AssemblyName.GetAssemblyName(fullPath);
                assemblyFileName = assemblyName.FullName;
            }
            catch (Exception)
            {
                //ignore exception if we weren't able to get assembly strong name, we'll still use assembly file name to add reference
            }

            var match1 = Regex.Match(relativePath, @"[0-9]+\.[0-9]+\.[0-9]+");
            var match2 = Regex.Match(assemblyFileName, @"[0-9]+\.[0-9]+\.[0-9]+");
            if (match1.Success && match2.Success)
            {
                if(match1.Value != match2.Value)
                {
                    // BREAKPOINT
                }
            }
            else
            {
                // BREAKPOINT
            }

            Project.AddItem(
                "Reference",
                assemblyFileName,
                new[] { new KeyValuePair<string, string>("HintPath", relativePath),
                        new KeyValuePair<string, string>("Private", "True")});

            return Task.FromResult(0);
        }

And I cannot catch it now. And it looks like it is not possible scenario when those has different versions here. But I have this issue sometimes (they do update with visual studio UI client). So I am really confused now. I Will try to update my packages more and debug this.

rohit21agrawal commented 6 years ago

@ievgennaida thanks for reporting this. we'll look into this very soon. Please tell us the version of Visual Studio by going to Help -> About Microsoft Visual Studio.

And also , mention your correct NuGet version by looking at the version displayed when you open Package Manager Console (Tools -> NuGet Package Manager -> Package Manager Console )

ievgennaida commented 6 years ago

Package Manager Console Host Version 4.4.1.4633

vlobrigo commented 6 years ago

I have the same issue with Visual Studio Enterprise 2017 15.5.6.

formiaczek commented 6 years ago

NuGet version 4.6.2.5055 still has this.

This problem is described well here, too:

https://stackoverflow.com/questions/45088790/why-are-c-sharp-references-added-differently-between-nuget-and-visual-studio

And this is exactly what I can see / reproduce every time.

johannescolmsee commented 5 years ago

A few observations that I found out during coming up with hacky ways to workaround this issue - the basic idea was - hey, lets remove all references, then reinstall to force VS to update (reinsert) all references:

randy-torres commented 5 years ago

Hi! Is there any update on fixing this? This is still happening on VS2017 Enterprise.

rcholic commented 5 years ago

I also ran into this problem a few days back, and there's no solution yet(?) thanks

SkyZero1228 commented 5 years ago

is there any update on fixing this? this is also happening on VS2019

FJ-BBD commented 4 years ago

still happening in 2020. package manager adds processorArchitecture=MSIL" exe adds PublicKeyToken=null

ievgennaida commented 4 years ago

I remember that during the update it was often reproducible. I think that the key to reproducing the issue is to create a big heavy project with a lot of small packages. After the update, I always had few packages broken.

formiaczek commented 4 years ago

One more observation to add: for C++ and C# projects (at least - maybe other languages too?) - this is benign, and if one can live with it (when consistent, e.g. have say all nuget updates made the same way so that version-control doesn't show these flipping back and forth).

mohammada72 commented 2 years ago

This problem is still exists on VS2019 and Nuget.exe 5.11.0. Please do something. Thanks.