NETSDK1061:使用Microsoft.NETCore.App版本1.0.0恢复项目,但使用当前设置,将使用版本2.0.9

问题描述 投票:9回答:5

我正在开发一个移动应用程序并使用MS App Center for CI。昨天单元测试项目无法在App Center中构建,但出现以下错误。我无法在任何开发人员计算机上重新创建此问题,此错误仅在App Center中出现。

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.

他们的付费支持只是提供基础,清理项目,回滚我的最后一次提交等。有人在App Center之前遇到过这个问题吗?

c# .net xamarin visual-studio-app-center
5个回答
15
投票

您需要设置相同的发布和构建运行时

<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.Json.csproj" />
  </ItemGroup>
</Project>

7
投票

如果使用Azure DevOps,请不要编辑项目文件。使用“dotnet restore”(https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core?view=azure-devops)代替Nuget恢复:

替换这个:

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

有了这个:

- script: dotnet restore

1
投票

尝试添加<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>to你的<PropertyGroup>标签。示例:

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
  </PropertyGroup>

0
投票

我在Visual Studio 2019上,this answer让我走上了正确的道路,我的程序是:

  • 从我的机器上卸载所有Microsoft .NET Core SDK实例。
  • 重启电脑。
  • SDK安装最新版本的here

0
投票

我在Visual Studio 2019上。当我第二次尝试将项目发布为自包含时,我遇到了这个问题。

我为摆脱这个错误所做的是:

  • 将部署模式更改为Framework Dependent
  • 发布项目
  • 将其更改回自包含状态并再次发布

它似乎是由一些错误的缓存引起的,可以通过切换到不同的部署模式来清除。

© www.soinside.com 2019 - 2024. All rights reserved.