0

I'm trying to build a solution after attempting to update some packages via the nuget manager in Visual Studio 2019 and I ended up on this error:

error : NETSDK1061: The project was restored using Microsoft.AspNetCore.All version 2.0.5, but with current settings, version 2.0.4 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. 

I checked this answer on SO but I don't really see how the solution given there can help me out:

You need to set the same publish and building runtimes

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion> --> fix publishing issues
    <PlatformTarget>AnyCPU</PlatformTarget> --> fix publishing issues
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Update="Microsoft.NETCore.App" Version="2.1.0" /> --> fix building issues
    <ProjectReference Include="..\PublicSonar.Monitor.Persistent.Json\PublicSonar.Monitor.Persistent.J> son.csproj" />
  </ItemGroup>
</Project>

The full dotnet build log:

λ dotnet build
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 40.89 ms for C:\Users\eperret\Desktop\KYC\KYC.Utils\KYC.Utils.csproj.
  Restore completed in 40.89 ms for C:\Users\eperret\Desktop\KYC\KYC.Core.DAL\KYC.Core.DAL.csproj.
  Restore completed in 80.13 ms for C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj.
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : warning NU1603: KYC.Core depends on Microsoft.AspNetCore.All (>= 2.0.4) but Microsoft.AspNetCore.All 2.0.4 was not found. An approximate best match of Microsoft.AspNetCore.All 2.0.5 was resolved.
  Restore completed in 66.57 ms for C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj.
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(153,5): warning NETSDK1071: A PackageReference to 'Microsoft.AspNetCore.All' specified a Version of `2.0.4`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs [C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj]
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : warning NU1603: KYC.Core depends on Microsoft.AspNetCore.All (>= 2.0.4) but Microsoft.AspNetCore.All 2.0.4 was not found. An approximate best match of Microsoft.AspNetCore.All 2.0.5 was resolved.
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : error : NETSDK1061: The project was restored using Microsoft.AspNetCore.All version 2.0.5, but with current settings, version 2.0.4 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection.

Build FAILED.

C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : warning NU1603: KYC.Core depends on Microsoft.AspNetCore.All (>= 2.0.4) but Microsoft.AspNetCore.All 2.0.4 was not found. An approximate best match of Microsoft.AspNetCore.All 2.0.5 was resolved.
C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(153,5): warning NETSDK1071: A PackageReference to 'Microsoft.AspNetCore.All' specified a Version of `2.0.4`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs [C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj]
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : warning NU1603: KYC.Core depends on Microsoft.AspNetCore.All (>= 2.0.4) but Microsoft.AspNetCore.All 2.0.4 was not found. An approximate best match of Microsoft.AspNetCore.All 2.0.5 was resolved.
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : error : NETSDK1061: The project was restored using Microsoft.AspNetCore.All version 2.0.5, but with current settings, version 2.0.4 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection.
    3 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.52

My KYC.Core contains:

  <ItemGroup>
    <PackageReference Include="bootstrap" Version="4.3.1" />
    <PackageReference Include="Bootstrap.Datepicker" Version="1.8.0.1" />
    <PackageReference Include="jQuery" Version="3.3.1" />
    <PackageReference Include="jQuery.UI.Combined" Version="1.12.1" />
    <PackageReference Include="jQuery.Validation" Version="1.17.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.4" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.4" />
    <PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
    <PackageReference Include="Microsoft.Extensions.Localization" Version="2.1.1" />
    <PackageReference Include="Microsoft.jQuery.Unobtrusive.Ajax" Version="3.2.5" />
    <PackageReference Include="Microsoft.jQuery.Unobtrusive.Validation" Version="3.2.11" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="2.0.3" />
    <PackageReference Include="RazorEngine.Core.NetCore" Version="4.5.0-rc1" />
    <PackageReference Include="RestSharp" Version="106.6.9" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
    <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
    <PackageReference Include="Serilog.Sinks.ElasticSearch" Version="7.1.0" />
  </ItemGroup>

[EDIT]

I tried to remove the version of <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.4" />, but does not really help:

λ dotnet build
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 39.63 ms for C:\Users\eperret\Desktop\KYC\KYC.Core.DAL\KYC.Core.DAL.csproj.
  Restore completed in 37.36 ms for C:\Users\eperret\Desktop\KYC\KYC.Utils\KYC.Utils.csproj.
  Restore completed in 73.48 ms for C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj.
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : error NU1107: Version conflict detected for Microsoft.CodeAnalysis.CSharp. Install/reference Microsoft.CodeAnalysis.CSharp 2.8.0 directly to project KYC.Core to resolve this issue.
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : error NU1107:  KYC.Core -> Microsoft.AspNetCore.Mvc 2.2.0 -> Microsoft.AspNetCore.Mvc.Razor.Extensions 2.2.0 -> Microsoft.CodeAnalysis.Razor 2.2.0 -> Microsoft.CodeAnalysis.CSharp (>= 2.8.0)
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : error NU1107:  KYC.Core -> RazorEngine.Core.NetCore 4.5.0-rc1 -> Microsoft.CodeAnalysis 2.3.2 -> Microsoft.CodeAnalysis.CSharp.Workspaces 2.3.2 -> Microsoft.CodeAnalysis.CSharp (= 2.3.2).
  Restore failed in 1.19 sec for C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj.

Build FAILED.

C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : error NU1107: Version conflict detected for Microsoft.CodeAnalysis.CSharp. Install/reference Microsoft.CodeAnalysis.CSharp 2.8.0 directly to project KYC.Core to resolve this issue.
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : error NU1107:  KYC.Core -> Microsoft.AspNetCore.Mvc 2.2.0 -> Microsoft.AspNetCore.Mvc.Razor.Extensions 2.2.0 -> Microsoft.CodeAnalysis.Razor 2.2.0 -> Microsoft.CodeAnalysis.CSharp (>= 2.8.0)
C:\Users\eperret\Desktop\KYC\KYC.Core\KYC.Core.csproj : error NU1107:  KYC.Core -> RazorEngine.Core.NetCore 4.5.0-rc1 -> Microsoft.CodeAnalysis 2.3.2 -> Microsoft.CodeAnalysis.CSharp.Workspaces 2.3.2 -> Microsoft.CodeAnalysis.CSharp (= 2.3.2).
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.41
Natalie Perret
  • 5,403
  • 4
  • 40
  • 82

1 Answers1

0

Ok my trick has been to uninstall pretty much everything until the solution does not compile anymore cause I suspected a few packages to be completely useless (I inherited from some legacy). Then I just reinstalled the packages just needed to build solution which worked that time.

  <ItemGroup>
    <PackageReference Include="bootstrap" Version="4.3.1" />
    <PackageReference Include="Bootstrap.Datepicker" Version="1.8.0.1" />
    <PackageReference Include="jQuery" Version="3.3.1" />
    <PackageReference Include="jQuery.UI.Combined" Version="1.12.1" />
    <PackageReference Include="jQuery.Validation" Version="1.17.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.All" />
    <PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
    <PackageReference Include="Microsoft.jQuery.Unobtrusive.Ajax" Version="3.2.6" />
    <PackageReference Include="Microsoft.jQuery.Unobtrusive.Validation" Version="3.2.11" />
    <PackageReference Include="RazorEngine.NetCore" Version="2.2.2" />
    <PackageReference Include="RestSharp" Version="106.6.9" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
    <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
    <PackageReference Include="Serilog.Sinks.ElasticSearch" Version="7.1.0" />
  </ItemGroup>

The issue lied in those packages

  • Microsoft.VisualStudio.Web.CodeGeneration.Design: not needed
  • Microsoft.VisualStudio.Web.CodeGeneration.Utils: not needed
  • RazorEngine.Core.NetCore: and use RazorEngine.NetCore instead
  • Microsoft.AspNetCore.All: no need to indicate the version, use latest
  • Microsoft.AspNetCore: upgrade to 2.2.0
Natalie Perret
  • 5,403
  • 4
  • 40
  • 82