I am trying to delete several setting files that are part of a project (Build Action: Content) after the project is dotnet published
in a pipeline step. The YAML below makes the files remain in the output folder as they are part of the ZIP, as far as I understand:
...
# Publish projects
- task: DotNetCoreCLI@2
displayName: 'Publish projects'
inputs:
command: 'publish'
projects: '$(mainProject)'
publishWebProjects: false
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
verbosityRestore: Detailed
verbosityPack: Detailed
workingDirectory: '$(workingDirectory)'
# Delete settings files
- task: DeleteFiles@1
displayName: 'Delete settings files'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)'
Contents: |
**/appsettings*.json
**/appconfig*.json
log4net*.config
RemoveSourceFolder: true
# Save artefact
- task: PublishBuildArtifacts@1
displayName: 'Save artefact'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
I understand that the three files are copied to the output folder because they are marked as Content
. I need that to be able to build and debug locally too.
I also know I am setting zipAfterPublish: true
in the dotnet publish
step, as I want the artefact to be drop.zip
.
I use an Ubuntu container, so I do not have ZIP to use a task ArchiveFiles@2
.
What is the simplest way to delete the files after publish
and before `pushing the artefact file?
Consider:
Using PublishPipelineArtifact@1 instead of PublishBuildArtifacts@1 for better performance (recommended by Microsoft)
Using the .artifactignore file to control which files will be published as pipeline artifacts.
Using the CopyToPublishDirectory MSBuild attribute to control which items are copied to the publish directory.