Home: VS 2017. References are not updated properly for a csproj files.

Created on 1 Dec 2017  路  11Comments  路  Source: NuGet/Home

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:

<Reference Include="A.Contracts, Version=2.4.211.0, Culture=neutral, PublicKeyToken=a, processorArchitecture=MSIL"> <HintPath>..\..\packages\A.Contracts.2.4.214.0\lib\net35\A.Contracts.dll</HintPath> </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.

Update Icebox VS.Client Packages.Config

Most helpful comment

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

All 11 comments

@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 )

Package Manager Console Host Version 4.4.1.4633

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

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.

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:

  • "Get-Package | Uninstall-Package -Force" does remove every reference except the wrong ones
  • if you remove all the references by some regex-magic, then reinstall everything (from the still intact package references) - guess what - the problematic DLL's are not installed at all!
  • if a project has a problem, it will always have a problem it seems. Silverlight seems to be affected very much (all projects??), but a lot of other projects too.

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

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

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

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

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.

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).

Was this page helpful?
0 / 5 - 0 ratings