7

I'm trying to install an update through NuGet:

Microsoft.AspNetCore.Mvc 1.1.2 --> 2.0.4

However, the update never succeeds as it is rolled back after encountering the following conflict:

Version conflict detected for Microsoft.CodeAnalysis.CSharp. Reference the package directly from the project to resolve this issue.


Web -> Microsoft.AspNetCore.Mvc 2.0.4 -> Microsoft.AspNetCore.Mvc.RazorPages 2.0.4 -> 
Microsoft.AspNetCore.Mvc.Razor 2.0.4 -> Microsoft.CodeAnalysis.CSharp (>= 2.3.1) 

Web -> Microsoft.VisualStudio.Web.CodeGeneration.Design 1.1.0 -> 
Microsoft.VisualStudio.Web.CodeGeneration.Utils 1.1.0 ->
 Microsoft.CodeAnalysis.CSharp.Workspaces 1.3.0 -> 
Microsoft.CodeAnalysis.CSharp (= 1.3.0).

So from what I understand from this, Microsoft.CodeAnalysis.CSharp is the culprit since Microsoft.AspNetCore.Mvc has dependencies that require it to be at least v2.3.1 while Microsoft.VisualStudio.Web.CodeGeneration.Design also has dependencies which requires it to be v1.3.0

I'm not sure how to solve this. It does say Reference the package directly from the project to resolve this issue but I don't really understand what this means and how to do it.

Force444
  • 3,321
  • 9
  • 39
  • 77

2 Answers2

7

If you add the dependency package directly (add the NuGet package Microsoft.CodeAnalysis.CSharp to your project in this case) Visual Studio will use the version of the directly referenced package rather than the versions specified in the dependencies of your other packages. In this way you have specified how to resolve the conflict by installing a specific version of the dependency.

You add this reference as you would any other NuGet package: in VisualStudio right-click on project -> "Manage NuGet Packages..." search for Microsoft.CodeAnalysis.CSharp and install it.

Don
  • 71
  • 4
0

If you have "packages" directory for project where all Nugets is restored, then there is PowerShell script to quickly check multiple Nuget version conflicts:

$dir = "C:\packages"
$nugets = Get-ChildItem -Path $dir -Directory | ?{ $_.PSIsContainer } | ForEach-Object { $_.Name }
$nCount = $nugets.Count

Write-Host "Found $nCount nuggets in '$dir' direcotry"

$nugetObjects = $nugets | %{ [pscustomobject]@{ Name = $_ -replace '\.([0-9]).*([0-9])$'; Version = $_ -replace '^([A-Za-z]).*([A-Za-z])\.' }} | Group-Object "Name"

$conflicts = $nugetObjects | Where-Object {$_.Count -gt 1}
if ($conflicts.Count -gt 0) {
    Write-Host "Found Nuget multiuple versions"
    $conflicts
}
else {
    Write-Host "Jey - Not found any Nuget version conflicts"
}
Drasius
  • 825
  • 1
  • 11
  • 26