Asp.NET核心项目失败并显示NETSDK1061:使用Microsoft.NETCore.App版本

时间:2019-10-30 11:14:26

标签: c# asp.net-core

我的一个开源项目刚刚开始无法使用errror进行构建,而以前曾经成功构建(如果我为先前成功的提交触发构建,则仍然会收到此错误?)

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.

此处是完整的构建日志here

csproj看起来像这样:

<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>

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

该如何解决?

2 个答案:

答案 0 :(得分:0)

请尝试从Microsoft.AspNetCore.All包中删除显式版本-该版本应由SDK确定(隐式版本),因为您还使用了TargetLatestRuntimePatch设置。在指定显式元包版本版本时,发生了类似的问题。

此外,您可能希望按照建议将其交换到Microsoft.AspNetCore.App-减少第三方依赖。在此处阅读更多信息:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-2.2

答案 1 :(得分:0)

我已通过将构建服务器环境从VS2017更改为VS2019来解决此问题