编辑:请参见帖子末尾的工作yaml。
我试图将一个 .NET Core 3.1 Console App 发布为单个文件,然而我似乎无法通过 Azure Devops Pipelines 成功。
无论是否自带,发布结果总是一堆dll,而不仅仅是我的可执行文件。
在我的电脑上以单项罚款的方式发布就可以了(从VS或.NET Core CLI发布,我在下面的yaml中设置了参数)。
这是负责构建的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。像:3)尝试将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)'
希望能帮到你...
更新答案
你需要在发布任务中指定命令,比如命令:发布。
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)'
通过在发布任务中加入明确的发布命令 我确认了一个压缩文件被创建为人工制品。
我已经测试了你的.yml文件,日志显示为 dotnet build
不 dotnet publish
. 你可以试试下面的代码。
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
projects: '**/*.csproj'
arguments: '--configuration Release --output "$(build.artifactstagingdirectory)"'
modifyOutputPath: true
zipAfterPublish: true
Or
- task: DotNetCoreCLI@2
inputs:
command: 'custom'
projects: '**/*.csproj'
custom: 'publish'
arguments: '--configuration Release --output $(build.artifactstagingdirectory)'