Sean Kelly
Sean Kelly

Reputation: 991

How to ensure that dotnet projects are restored with the same settings?

I've added an Xunit testing project to my latest project, configured with Azure pipelines. All of my tests pass, but since I've added XUnit the VSBuild triggers:

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

I've tried making manual changes to the .csproj files and restoring, cleaning the solution but I just can't seem to figure out what is causing the disconnect.

I three .csproj files in my solution. I'm not sure how to go about resolving their difference. Any help would be greatly appreciated because this is my personal project for the next month or two and I'd like to get the CI handled early

Proj 1 -- Class Library:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    <OutputType>Library</OutputType>
  </PropertyGroup>

</Project>

Proj 2 -- XUnit:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="xunit" Version="2.4.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\PlisskenLibrary\PlisskenLibrary.csproj" />
  </ItemGroup>

</Project>

Start up project -- Console project:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{D75CE556-EDB3-40ED-B836-168DAA5F12A7}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>Plissken</RootNamespace>
    <AssemblyName>Plissken</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Repl.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\PlisskenLibrary\PlisskenLibrary.csproj">
      <Project>{ebca8a6a-abae-4a43-b43e-672cb9feafad}</Project>
      <Name>PlisskenLibrary</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

And finally my azure pipeline yml file

trigger:
- master

pool:
  vmImage: 'windows-latest'

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

steps:
- task: NuGetToolInstaller@0

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

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

Upvotes: 0

Views: 1130

Answers (2)

Sean Kelly
Sean Kelly

Reputation: 991

So the problem turned out to be that I created the console app with the .NET Framework instead of using the .NET Core console app. I replaced the old console app with the .NET core app and all of my problems have gone away.

From now on and forever more, I shall use dotnet new console instead of using the GUI because I'm far less prone to make a mistake. Good times.

Upvotes: 1

Leo Liu
Leo Liu

Reputation: 76770

How to ensure that dotnet projects are restored with the same settings?

According to the build log you provided, you are using nuget.exe 4.3.0 to restore the packages. But it seems Nuget.exe 4.3.0 stopped restoring correctly when .Net core SDK 2.2.* is installed.

So, to resolve this issue, please try to use Nuget.exe 4.4.1.

Besides, if above not resolve this issue, you can check if the answer in following thread give you some help:

The project was restored using Microsoft.NETCore.App version 2.1.0, but with current settings, version 2.1.0-rtm-26515-03 would be used instead

Add TargetLatestRuntimePatch attribute in .csproj file:

<PropertyGroup>
  <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>

Or

set RuntimeFrameworkVersion and RuntimeIdentifier in .csproj file:

 <PropertyGroup>
   <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
   <PlatformTarget>AnyCPU</PlatformTarget>
   <RuntimeIdentifier>win-x64</RuntimeIdentifier>
 </PropertyGroup>

Hope this helps.

Upvotes: 0

Related Questions