2

The complete error is here:

Error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 1.0.0, but with current settings, version 2.2.0 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.

Locally everything looks just fine, but on Azure it does not want to compile. All the proposed solutions that I have found online did not help, including:

- script: dotnet restore
- setting the <RuntimeFrameworkVersion>2.2.104</RuntimeFrameworkVersion> to the version I use.
- setting the <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>

Below is a part of the yaml file:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: 'src/MySolution.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
  - task: NuGetToolInstaller@0
  inputs:
    versionSpec: '4.3.0'
  - task: DotNetCoreInstaller@0
  inputs:
    packageType: 'sdk'
    version: '2.2.104'

- script: dotnet restore $(solution)
- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    msbuildArchitecture: 'x64'

The project file contains the following:

<PropertyGroup>
    <TargetFrameworks>netcoreapp2.2;net45</TargetFrameworks>
    <LangVersion>latest</LangVersion>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
Auguste Leroi
  • 215
  • 1
  • 7

1 Answers1

2

I had the same problem not so long ago and one thing that I noticed was that the nuget version used to restore the packages was fixed to 4.3.0 (I think it was a default suggestion). I tried to use a newer version like this:

- task: NuGetToolInstaller@0
  inputs:
    versionSpec: '>=4.3.0'
    checkLatest: true

After the change, the build was fixed. In the logs I noticed that the version 5.2.0 was being used, although locally I could get only the version 5.1.0 (with 'nuget update -self').

ioan
  • 702
  • 3
  • 10
  • 1
    I tried it and it really works! Thanks, you saved my day! – Auguste Leroi Aug 23 '19 at 10:35
  • If all the projects in the solution are SDK style projects, then you can use `dotnet restore` instead of `nuget restore`. If the SDK version can build your project, restore will work too and you don't have to worry about the version number of yet another component. – zivkan Aug 24 '19 at 13:26
  • I tried what you are suggesting, see my yaml file. The problem is that the SDK cannot build my solution as it targets both .NET Standard and .NET 4.5. – Auguste Leroi Aug 26 '19 at 07:00
  • You sir/madam just saved me hours of fruitless debugging. Highly doubt I would have figured this one out by myself. Thank you! Upgrading my nuget.exe version in the pipeline did the trick – Richard Feb 21 '20 at 07:53