WinForms应用Azure DevOps构建管道无产物,需ZIP打包解决方案
Hey there, let's get your WinForms app's build artifacts showing up and packaged as a ZIP! The root issue right now is that your pipeline builds the project but doesn't move the output files into the $(build.artifactstagingdirectory) folder (the default location PublishBuildArtifacts looks for). Here's how to adjust your YAML to fix this:
Step 1: Update Pipeline to Package & Publish Build Output
We'll add a task to bundle your build output into a ZIP, then publish that ZIP as the artifact. Here's the revised YAML:
trigger: - master pool: vmImage: 'windows-latest' variables: solution: '**/*.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' ScmBuildProject: 'DemoAppForAzurePipeLine' # Optional: Unique ZIP filename with build ID for version tracking zipFileName: 'WinFormsApp_Build_$(Build.BuildId).zip' steps: - task: NuGetToolInstaller@1 - task: NuGetCommand@2 inputs: restoreSolution: '$(solution)' - task: VSBuild@1 inputs: solution: '$(solution)' platform: '$(buildPlatform)' configuration: '$(buildConfiguration)' # Explicitly set output path to avoid ambiguity msbuildArgs: '/p:OutputPath=$(System.DefaultWorkingDirectory)/$(ScmBuildProject)/bin/$(buildConfiguration)' - task: VSTest@2 inputs: platform: '$(buildPlatform)' configuration: '$(buildConfiguration)' # New task: Package build output into a ZIP - task: ArchiveFiles@2 displayName: 'Archive Build Output' inputs: rootFolderOrFile: '$(System.DefaultWorkingDirectory)/$(ScmBuildProject)/bin/$(buildConfiguration)' includeRootFolder: false # Set to true if you want the project folder inside the ZIP archiveType: 'zip' archiveFile: '$(build.artifactstagingdirectory)/$(zipFileName)' replaceExistingArchive: true # Publish the ZIP as the build artifact - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: WinFormsBuild' inputs: PathtoPublish: '$(build.artifactstagingdirectory)' ArtifactName: '$(ScmBuildProject)_Build' condition: succeededOrFailed()
Key Changes Explained
- Explicit Output Path: The
msbuildArgsin VSBuild ensures we know exactly where the build output lives (avoids confusion with default paths that might vary by project setup). - ArchiveFiles Task: This takes all your WinForms app's compiled files (EXE, DLLs, configs, etc.) from the
bin/Releasefolder and packages them into a ZIP directly in the artifact staging directory. - Unique ZIP Naming: Using
$(Build.BuildId)guarantees each build gets a distinct ZIP file, making it easier to track versions later. - Descriptive Artifact Name: Renamed the artifact to something clear, but you can tweak
$(ScmBuildProject)_Buildto match your preference.
Alternative: Publish Raw Files (No ZIP)
If you'd rather upload uncompressed files instead of a ZIP, replace the ArchiveFiles task with this CopyFiles task:
- task: CopyFiles@2 displayName: 'Copy Build Output to Artifact Staging Directory' inputs: SourceFolder: '$(System.DefaultWorkingDirectory)/$(ScmBuildProject)/bin/$(buildConfiguration)' Contents: '**/*' TargetFolder: '$(build.artifactstagingdirectory)'
You can also enable the "Zip published artifacts" toggle in the PublishBuildArtifacts task settings if you want Azure DevOps to auto-ZIP the raw files for you.
Run the adjusted pipeline, and you'll see your ZIP (or raw files) in the Artifacts tab once the build finishes!
内容的提问来源于stack exchange,提问作者Pankaj Kumar

