我正在开发一个移动应用程序并使用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之前遇到过这个问题吗?
您需要设置相同的发布和构建运行时
<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>
如果使用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
尝试添加<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
to你的<PropertyGroup>
标签。示例:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
我在Visual Studio 2019上,this answer让我走上了正确的道路,我的程序是:
Microsoft .NET Core SDK
实例。SDK
安装最新版本的here。我在Visual Studio 2019上。当我第二次尝试将项目发布为自包含时,我遇到了这个问题。
我为摆脱这个错误所做的是:
它似乎是由一些错误的缓存引起的,可以通过切换到不同的部署模式来清除。