由于Azure AppServices不再(不再)支持.NET Core2.1上与框架相关的部署,我们目前正在发布我们的.NET Core2.1WebAPI的自动包含的win-x64版本。
我试图在Yaml中为CI/CD设置Azure管道,并将其部署到Azure App部署槽中。
我想要解决的问题是这条错误消息:project.assets.json‘没有“netcoreapp2.1/win10-x64”的目标
/usr/bin/dotnet publish /home/vsts/work/1/s/MyApp.WebApi/MyApp.WebApi.csproj --configuration Release -f netcoreapp2.1 -r win10-x64 --self-contained true --no-restore --output /home/vsts/work/1/a/MyApp.WebApi
Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/share/dotnet/sdk/5.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1047: Assets file '/home/vsts/work/1/s/MyApp.WebApi/obj/project.assets.json' doesn't have a target for 'netcoreapp2.1/win10-x64'. Ensure that restore has run and that you have included 'netcoreapp2.1' in the TargetFrameworks for your project. You may also need to include 'win10-x64' in your project's RuntimeIdentifiers. [/home/vsts/work/1/s/MyApp.WebApi/MyApp.WebApi.csproj]
##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1
这是我的yaml文件:
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- develop
pool:
vmImage: 'ubuntu-20.04'
variables:
buildConfiguration: 'Release'
buildPlatform: x64
steps:
- task: DotNetCoreCLI@2
displayName: dotnet restore
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'config'
nugetConfigPath: './NuGet.config'
externalFeedCredentials: 'Hangfire Pro'
- task: DotNetCoreCLI@2
displayName: dotnet publish
inputs:
command: 'publish'
publishWebProjects: true
feedsToUse: 'config'
nugetConfigPath: './NuGet.config'
externalFeedCredentials: 'Hangfire Pro'
arguments: '--configuration $(BuildConfiguration) -f netcoreapp2.1 -r win10-x64 --self-contained true --no-restore --output $(build.artifactstagingdirectory)'
# this code takes all the files in $(Build.ArtifactStagingDirectory) and uploads them as an artifact of your build.
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'MyAppWebApi'
我尝试通过添加以下内容来修改CSPROJ文件:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
**<RuntimeIdentifiers>win10-x64;win-x64</RuntimeIdentifiers>**
and
<PlatformTarget>x64</PlatformTarget>
发布于 2021-02-19 10:44:07
我工作的时候出了一些问题。最重要的是,当管道在另一个分支上运行时,我所做的所有改变都被推到了开发分支。我对管道(也包括Git)的缺乏经验是造成这种情况的主要原因。我的印象是,YAML中的trigger
行指向存储库进行恢复和发布。
我终于让它按照以下步骤工作了。正如Edward提到的,我试图通过命令行在本地计算机上恢复和发布。这些也给了我一些我需要修复的错误。类似于将这一行添加到所有(30+)引用的csproj文件中:
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
然后将此配置添加到webproject csproj:
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
那么我的最后一个YAML文件是:
trigger:
- develop
pool:
vmImage: 'windows-2019'
variables:
buildConfiguration: 'Release'
buildPlatform: x64
steps:
- task: UseDotNet@2
displayName: 'Use .Net Core sdk 2.1.x'
inputs:
version: 2.1.x
- task: DotNetCoreCLI@2
displayName: dotnet restore
inputs:
command: 'restore'
projects: '**/*.csproj'
arguments: '-r win-x64'
feedsToUse: 'config'
nugetConfigPath: './NuGet.config'
externalFeedCredentials: 'Hangfire Pro'
- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: 'test'
projects: '**/*[Tt]ests/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
testRunTitle: 'dotnet test 2'
- task: DotNetCoreCLI@2
displayName: dotnet publish
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) -r win-x64 --self-contained true --no-restore --output $(build.artifactstagingdirectory)'
# this code takes all the files in $(Build.ArtifactStagingDirectory) and uploads them as an artifact of your build.
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'MyAppWebApi'
我改变了/补充了几件重要的事情:
凝聚
虽然我学习了一些Pluralsight课程、YouTube视频和博客,但我还是读了Microsoft /MSDN。在使用Visual用户界面发布时,切换到命令行确实是一个很大的区别。我们需要看更多的信仰者。提示:认真阅读这些错误消息提供的urls,它们确实包含足够的信息来解决您的问题。至少这是我学到的。
发布于 2021-02-17 06:24:23
请从项目中删除obj和bin文件夹。而且,您的<TargetFramework>
文件中的.csproj是单数的。请尝试添加一个"s“,然后它变成"TargetFrameworks"
,看看它是否有效。
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
您可以参考此线程获得更多可能的解决方案。
顺便说一句,在微软-托管Windows2019代理(安装VisualStudioEnterprise2019)和本地机器之间有不同的构建环境,您可以尝试使用自托管Windows代理来构建您的项目,而不需要额外的环境准备步骤。
https://stackoverflow.com/questions/66221325
复制相似问题