c# - DeleteFiles 任务从匹配列表中排除单个文件

标签 c# azure-devops azure-pipelines

我正在尝试设置DeleteFiles 任务来删除除特定文件之外的所有以“ab”开头的DLL 文件。

例如,如果我有:

abfile.one.dll
abfile.two.dll
abotherfile.dll
System.Stuff.dll (there are 20-30 of these that need to be included)
abdontdeleteme.dll

我期望生成的文件:

System.Stuff.dll
abdontdeleteme.dll

我尝试了很多不同的配置,但没有一个有效。我认为最有意义的配置是:

  - task: DeleteFiles@1
    displayName: 'Cleanup Assemblies'
    inputs:
      sourceFolder: ${{parameters.theDirectoryToCleanup}}
      contents: ab*.dll !abdontdeleteme.dll

此配置不执行任何操作。将 System.Debug 设置为 true 并查看我看到的输出:

##[debug]pattern: 'D:/a/1/b/api/bin/ab*.dll !abdontdeleteme.dll'
##[debug]applying include pattern against original list
##[debug]0 matches
##[debug]0 final results

我也尝试过使用ab*.dll,它有效,但删除了我关心的一个DLL。有没有办法从匹配列表中排除特定文件?

编辑

根据评论中的建议,我尝试了以下方法以获得相同的结果(没有删除文件):

- task: DeleteFiles@1
    displayName: 'Cleanup Assemblies'
    inputs:
      sourceFolder: ${{parameters.theDirectoryToCleanup}}
      contents:
        ab*.dll 
        !abdontdeleteme.dll

编辑2

我尝试了以下方法:

- task: DeleteFiles@1
    displayName: 'Cleanup Assemblies'
    inputs:
      sourceFolder: ${{parameters.theDirectoryToCleanup}}
      contents: |
        ab*.dll 
        !(abdontdeleteme.dll)

这将删除除“abdontdeleteme.dl”之外的所有内容

- task: DeleteFiles@1
    displayName: 'Cleanup Assemblies'
    inputs:
      sourceFolder: ${{parameters.theDirectoryToCleanup}}
      contents:
        ab*.dll 
        !(abdontdeleteme.dll)

这再次与任何内容匹配,并且没有任何内容被删除。

最佳答案

经过多次挫折后,我放弃并使用 Powershell,因为它可以做我想做的事情。这不是最好的解决方案,但它可以工作,因为其他一些步骤仍然需要 Windows 镜像。有效的代码是:

- task: PowerShell@2
      displayName: "Cleanup Web Services"
      inputs:
        targetType: 'inline'
        script: Remove-Item "path\to\my\stuff\*" -Include "ab*.dll" -Exclude "abdontdeleteme.dll"

关于c# - DeleteFiles 任务从匹配列表中排除单个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60062251/

相关文章:

c# - 为什么我的repositoryPath 在 Azure DevOps/TFS 中被忽略?

visual-studio-2013 - 我在 Visual Studio 2013 中有一个现有的解决方案。如何将它导入我的 VS Online 工作区?

c# - 我可以使用 GetHashCode 跟踪对象标识吗?

c# - 从 C# 中的 void 方法返回错误消息

c# - 统一: Knockback my player

c# - 在 .net 中有很好的解释和示例的控制/依赖注入(inject)的反转?

azure-devops - Azure Devops - Nuget Package 从 .NET Core 3.1 迁移到 .NET 5 的兼容性问题

azure-devops - Azure Pipelines 计划每月仅运行几天

AzureML 在管道之间传递数据而不保存数据

azure-devops - 使用多个框架时 .Net 5 的 Azure Devops 构建失败