NETSDK1061:使用Microsoft.NETCore.App版本1.0.0还原了该项目,但在当前设置下,将改用版本2.0.9

时间:2018-12-11 09:07:22

标签: c# .net xamarin visual-studio-app-center

我正在开发移动应用程序,并使用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上遇到过此问题吗?

10 个答案:

答案 0 :(得分:12)

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

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

答案 1 :(得分:5)

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

答案 2 :(得分:2)

将此添加到.csproj

<PropertyGroup>
<RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>
</PropertyGroup>

答案 3 :(得分:1)

我遇到了这个问题,因为我有一个不再存在的裸体资源。删除有问题的nuget源后,我恢复了项目,一切正常。

我通过命令行恢复了项目:

dotnet restore

答案 4 :(得分:0)

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

  • 从计算机上卸载Microsoft .NET Core SDK的所有实例。
  • 重新启动计算机。
  • here安装了SDK的最新版本。

答案 5 :(得分:0)

我正在使用Visual Studio2019。当我第二次尝试将项目发布为“自包含”时,遇到了此问题。

我为消除此错误所做的事情是:

  • 将部署模式更改为框架相关
  • 发布项目
  • 将其更改回“自包含”并再次发布

这似乎是由于某些错误的缓存所致,可以通过切换到其他部署模式来清除它。

答案 6 :(得分:0)

尝试将<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>添加到您的<PropertyGroup>标记中。示例:

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

答案 7 :(得分:0)

还要检查我在这里建议的解决方案(Using Azure Pipelines with multi targeting projects I get error NETSDK1061),也许它也对您有用:

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

答案 8 :(得分:0)

为我解决了这个问题,是通过更改msvc中的参数来更新用于还原的默认NuGet程序包缓存'C:\ Users \ .nuget \ packages':

工具>选项> NuGet程序包管理器>程序包还原>允许NuGet下载丢失的程序包并在Visual Studio中构建期间自动检查丢失的程序包。

答案 9 :(得分:0)

在Azure Devops中进行构建时遇到了这个问题,其他答案都无法解决。我的构建和发布步骤已经具有匹配的--runtime选项。

对我来说,解决方法是将以下内容添加到.csproj文件中(用适合您的部署方案的RuntimeIdentifier替换为正确的文件):

  <PropertyGroup>
      ...
      <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>