错误NU1107版本冲突检测到Microsoft.CodeAnalysis.Common

时间:2018-11-29 16:20:08

标签: c# nuget nuget-package asp.net-core-2.1

将测试项目从.NET Core 2.0升级到2.1之后,我开始在构建过程中遇到以下错误:

Error       Package restore failed. Rolling back package changes for 'Api.Tests'.

Error   NU1107  Version conflict detected for Microsoft.CodeAnalysis.Common. Install/reference Microsoft.CodeAnalysis.Common 2.8.2 directly to project Api.Tests to resolve this issue. 
    Api.Tests -> Api -> Microsoft.CodeAnalysis.Common (>= 2.8.2) 
    Api.Tests -> Microsoft.AspNetCore.Mvc 2.0.3 -> Microsoft.AspNetCore.Mvc.Localization 2.0.3 -> Microsoft.AspNetCore.Mvc.Razor 2.0.3 -> Microsoft.CodeAnalysis.CSharp 2.3.1 -> Microsoft.CodeAnalysis.Common (= 2.3.1).   Api.Tests

Error   NU1107  Version conflict detected for Microsoft.CodeAnalysis.Common. Install/reference Microsoft.CodeAnalysis.Common 2.8.2 directly to project Api.Tests to resolve this issue. 
    Api.Tests -> Api -> Microsoft.CodeAnalysis.Common (>= 2.8.2) 
    Api.Tests -> Microsoft.AspNetCore.Mvc 2.2.0-preview3-35497 -> Microsoft.AspNetCore.Mvc.Localization 2.2.0-preview3-35497 -> Microsoft.AspNetCore.Mvc.Razor 2.2.0-preview3-35497 -> Microsoft.CodeAnalysis.CSharp 2.8.0 -> Microsoft.CodeAnalysis.Common (= 2.8.0).  Api.Tests

我尝试直接在项目中安装Microsoft.CodeAnalysis.Common 2.8.2,但出现以下错误:

Restoring packages for Api.Tests.csproj...
NU1608: Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.CSharp 2.3.1 requires Microsoft.CodeAnalysis.Common (= 2.3.1) but version Microsoft.CodeAnalysis.Common 2.8.2 was resolved.
NU1608: Detected package version outside of dependency constraint: Microsoft.CodeAnalysis.Workspaces.Common 2.3.1 requires Microsoft.CodeAnalysis.Common (= 2.3.1) but version Microsoft.CodeAnalysis.Common 2.8.2 was resolved.
Install-Package : NU1605: Detected package downgrade: Microsoft.AspNetCore.Mvc from 2.2.0-preview3-35497 to 2.0.3. Reference the package directly from the project to select a different version. 
Api.Tests -> Services -> CommStack.Conference.Web.Api.Client 1.0.0-CI-20181128-112729 -> CommStack.Web.Api.Client.Common 1.0.0-CI-20181128-112729 -> Microsoft.AspNetCore.Mvc (>= 2.2.0-preview3-35497) 
Api.Tests -> Microsoft.AspNetCore.Mvc (>= 2.0.3)
At line:1 char:1
+ Install-Package Microsoft.CodeAnalysis.Common -Version 2.8.2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Install-Package : Package restore failed. Rolling back package changes for 'Api.Tests'.
At line:1 char:1
+ Install-Package Microsoft.CodeAnalysis.Common -Version 2.8.2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

关于如何解决此问题的任何建议?

1 个答案:

答案 0 :(得分:1)

要解决此问题,您必须明确安装两者之一

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.*" />

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.*" />

取决于您在API项目中使用的软件包。