gpt4 book ai didi

azure - 创建独立部署时如何解决 Azure Devops Pipeline 中的目标问题

转载 作者:行者123 更新时间:2023-12-03 00:22:25 26 4
gpt4 key购买 nike

由于 Azure AppServices(不再)支持 x64 上的 .NET Core 2.1 以及依赖于框架的部署,因此我们目前正在发布 .NET Core 2.1 Web API 的独立 win-x64 版本。

我正在尝试在 Yaml 中设置 Azure Pipeline 以用于 CI/CD 目的,并将其部署到 Azure 应用服务部署槽。

我试图解决的问题是这个错误消息: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>

最佳答案

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

  <PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

可以引用这个thread了解更多可能的解决方案。

顺便说一句,Microsoft-hosted Windows-2019 agents之间有不同的构建环境(安装 Visual Studio Enterprise 2019)和本地计算机,您可以尝试使用 self-hosted Windows agents无需额外的环境准备步骤即可构建您的项目。

关于azure - 创建独立部署时如何解决 Azure Devops Pipeline 中的目标问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66221325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com