首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何解决创建独立部署时Azure Devops管道中的目标问题

如何解决创建独立部署时Azure Devops管道中的目标问题
EN

Stack Overflow用户
提问于 2021-02-16 08:57:55
回答 2查看 2K关注 0票数 1

由于Azure AppServices不再(不再)支持.NET Core2.1上与框架相关的部署,我们目前正在发布我们的.NET Core2.1WebAPI的自动包含的win-x64版本。

我试图在Yaml中为CI/CD设置Azure管道,并将其部署到Azure App部署槽中。

我想要解决的问题是这条错误消息:project.assets.json‘没有“netcoreapp2.1/win10-x64”的目标

代码语言:javascript
运行
复制
/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文件:

代码语言:javascript
运行
复制
# 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文件:

代码语言:javascript
运行
复制
<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    **<RuntimeIdentifiers>win10-x64;win-x64</RuntimeIdentifiers>**

and

<PlatformTarget>x64</PlatformTarget>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-02-19 10:44:07

我工作的时候出了一些问题。最重要的是,当管道在另一个分支上运行时,我所做的所有改变都被推到了开发分支。我对管道(也包括Git)的缺乏经验是造成这种情况的主要原因。我的印象是,YAML中的trigger行指向存储库进行恢复和发布。

我终于让它按照以下步骤工作了。正如Edward提到的,我试图通过命令行在本地计算机上恢复和发布。这些也给了我一些我需要修复的错误。类似于将这一行添加到所有(30+)引用的csproj文件中:

代码语言:javascript
运行
复制
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>

然后将此配置添加到webproject csproj:

代码语言:javascript
运行
复制
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>

那么我的最后一个YAML文件是:

代码语言:javascript
运行
复制
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'

我改变了/补充了几件重要的事情:

  • 显式告诉使用.NET Core2.1.*
  • 将-runtime参数添加到还原命令中

凝聚

虽然我学习了一些Pluralsight课程、YouTube视频和博客,但我还是读了Microsoft /MSDN。在使用Visual用户界面发布时,切换到命令行确实是一个很大的区别。我们需要看更多的信仰者。提示:认真阅读这些错误消息提供的urls,它们确实包含足够的信息来解决您的问题。至少这是我学到的。

票数 0
EN

Stack Overflow用户

发布于 2021-02-17 06:24:23

请从项目中删除obj和bin文件夹。而且,您的<TargetFramework>文件中的.csproj是单数的。请尝试添加一个"s“,然后它变成"TargetFrameworks",看看它是否有效。

代码语言:javascript
运行
复制
  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.1</TargetFrameworks>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

您可以参考此线程获得更多可能的解决方案。

顺便说一句,在微软-托管Windows2019代理(安装VisualStudioEnterprise2019)和本地机器之间有不同的构建环境,您可以尝试使用自托管Windows代理来构建您的项目,而不需要额外的环境准备步骤。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66221325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档