gpt4 book ai didi

.net-core - AzureDevOps - 无法作为单个文件发布

转载 作者:行者123 更新时间:2023-12-04 10:02:33 25 4
gpt4 key购买 nike

编辑:请参阅文章末尾的工作 yaml。

我正在尝试将 .NET Core 3.1 控制台应用程序发布为单个文件,但我似乎无法通过 Azure Devops Pipelines 取得成功:

自包含与否,发布结果总是一堆 dll 而不是我的可执行文件。

在我的计算机上作为单个发布正常工作(使用我在下面的 yaml 中设置的参数从 VS 或 .NET Core CLI 发布)

这是负责构建的 yaml:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- feature/linux

pool:
vmImage: 'ubuntu-latest'

steps:
- task: UseDotNet@2
displayName: 'Use .Net Core sdk 3.1.x'
inputs:
version: 3.1.x

- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: './Project/Project.csproj'
feedsToUse: config
nugetConfigPath: ./NuGet/NuGet.Config

- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
projects: './Project/Project.csproj'
arguments: '-o $(build.artifactstagingdirectory) -r linux-x64 -c Release -f netcoreapp3.1 -p:PublishSingleFile=true -p:SelfContained=false'

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'

解决方案:

我很笨,只是忘记了 dotnet publish 下的命令部分.. 结果命令默认是 build。请注意,您还需要指定

publishWebProjects: false

对于控制台项目,请参阅完整的工作 yaml:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- feature/linux

pool:
vmImage: 'ubuntu-latest'

steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/Project.csproj'
feedsToUse: config
nugetConfigPath: ./NuGet/NuGet.Config

- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/Project.csproj'
modifyOutputPath: true
arguments: '-o $(build.artifactstagingdirectory) -r linux-x64 -c Release -f netcoreapp3.1 -p:PublishSingleFile=true -p:SelfContained=false'

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
artifactName: 'drop'
PathtoPublish: '$(build.artifactstagingdirectory)'

欢迎任何帮助:)

最佳答案

如果相同的命令在本地和远程服务器上产生不同的结果,那将是非常奇怪的。你用同一个SDK,没有任何意义。问题出在管道的其他地方。我会建议以下解决方案。

1) 尝试在发布构建工件时明确说明要发布哪个文件夹,它似乎正在尝试发布 linux-x64 文件夹(一个文件夹以上)。喜欢:

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
artifactName: 'drop'
PathtoPublish: '$(build.artifactstagingdirectory)'

2) 尝试将 PublishSingleFile 改为 zipAfterPublish。喜欢:

- task: DotNetCoreCLI@2
displayName: Publish
inputs:
command: publish
modifyOutputPath: true
arguments: '--configuration $(BuildConfiguration) --output "$(build.artifactstagingdirectory)"'
zipAfterPublish: true

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
projects: './Project/Project.csproj'
artifactName: 'drop'
PathtoPublish: '$(build.artifactstagingdirectory)'

希望对你有帮助

更新的答案

您需要在发布任务中指定命令,如命令:publish。

yaml 为我工作是:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- feature/linux

pool:
vmImage: 'ubuntu-latest'

steps:
- task: DotNetCoreCLI@2
displayName: 'Restore Nuget Packages'
inputs:
command: 'restore'
projects: './Project/Project.csproj'
feedsToUse: config
nugetConfigPath: ./NuGet/NuGet.Config

- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: publish
modifyOutputPath: true
arguments: '--configuration Release --output "$(build.artifactstagingdirectory)"'
zipAfterPublish: true

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
artifactName: 'drop'
PathtoPublish: '$(build.artifactstagingdirectory)'

通过在发布任务中明确添加发布命令,我确认创建了一个 zip 文件作为工件。

关于.net-core - AzureDevOps - 无法作为单个文件发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61756858/

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