我正在尝试通过NuGet安装更新:
Microsoft.AspNetCore.Mvc 1.1.2 --> 2.0.4
但是,更新永远不会成功,因为它在遇到以下冲突后回滚:
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).
所以根据我的理解,Microsoft.CodeAnalysis.CSharp
是罪魁祸首,因为Microsoft.AspNetCore.Mvc
有依赖性要求它至少是v2.3.1
而Microsoft.VisualStudio.Web.CodeGeneration.Design
也有依赖性要求它是v1.3.0
我不知道如何解决这个问题。它确实说Reference the package directly from the project to resolve this issue
,但我真的不明白这意味着什么以及如何做到这一点。
如果直接添加依赖包(在这种情况下将NuGet包Microsoft.CodeAnalysis.CSharp
添加到项目中),Visual Studio将使用直接引用的包的版本,而不是其他包的依赖项中指定的版本。通过这种方式,您已指定了如何通过安装特定版本的依赖项来解决冲突。
您可以像添加任何其他NuGet包一样添加此引用:在VisualStudio中右键单击项目 - >“管理NuGet包...”搜索Microsoft.CodeAnalysis.CSharp
并安装它。
如果您有恢复所有Nugets的项目的“packages”目录,那么有PowerShell脚本可以快速检查多个Nuget版本冲突:
$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"
}