简体   繁体   中英

Asp.NET core project fails with NETSDK1061: The project was restored using Microsoft.NETCore.App version

One of my open source projects has just started failing to build with the errror, when previously it used to build successfully (if I trigger a build for a previously successful commit, I still get this error )

C:\projects\formfactory\FormFactory.AspNetCore.Example\FormFactory.AspNetCore.Example.csproj: error: NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.2.4, but with current settings, version 2.2.1 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.

Full build log here here

The csproj looks like this:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>FormFactory.AspNetCore.Example</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>FormFactory.AspNetCore.Example</PackageId>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>

    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
  </PropertyGroup>

  <ItemGroup>
    <None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\FormFactory\FormFactory.csproj" />
    <ProjectReference Include="..\FormFactory.AspNetCore\FormFactory.AspNetCore.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.0" />
  </ItemGroup>

  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <Exec Command="bower install" />
    <Exec Command="dotnet bundle" />
  </Target>

  <ItemGroup>
    <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
  </ItemGroup>

</Project>

from https://github.com/mcintyre321/FormFactory/blob/master/FormFactory.AspNetCore.Example/FormFactory.AspNetCore.Example.csproj

What do I need to do to fix this?

Try removing explicit version from Microsoft.AspNetCore.All package - the version should be determined by the SDK (implicit version), as you're also using TargetLatestRuntimePatch setting. Had similar issues caused when specifying explicit metapackage version version.

Also, you might want to consider swapping it to Microsoft.AspNetCore.App as it is recommended - less 3rd party dependencies. Read more here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-2.2

I've fixed this by changing my build server environment from VS2017 to VS2019

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM