TFS drop, exclude obj folder using minimatch pattern

拈花ヽ惹草 提交于 2019-11-29 03:55:46

In VSTS there are two kinds of pattern matching for URLs that are built-in to the SDKs. Most tasks nowadays use the Minimatch pattern as described in Matt's answer. However, some use the pattern that was used by the 1.x Agent's Powershell SDK. That format is still available in the 2.x Agent's Powershell SDK by the way.

So that means there are 4 kinds of tasks:

  • 1.x agent - Powershell SDK
  • 2.x agent - Node SDK
  • 2.x agent - Powershell 1 Backwards compatibility
  • 2.x agent - Powershell 3 SDK - Using find-files
  • 2.x agent - Powershell 3 SDK - Using find-match

The ones in bold don't Minimatch, but the format documented in the VSTS-Task-SDK's find-files method.

The original question was posted in 2015, at which point in time the 2.x agent wasn't yet around. In that case, the pattern would, in all likelihood, be:

 **\bin\$(BuildConfiguration)\**\*;-:**\obj\**

The -: excludes the items from the ones in front of it.

According to Microsoft's documentation, here is a list of file matching patterns you can use. The most important rules are:

Match with ?

  • ? matches any single character within a file or directory name (zero or one times).

Match with * or +

  • * or + matches zero or more characters within a file or directory name.

Match with @ sign

  • @ matches exactly once.

Match with Brackets (, ) and |

  • If you're using brackets with | it is treated as a logical OR, e.g. *(hello|world) means "Zero or more occurrances of hello or world"

Match with Double-asterisk **

  • ** recursive wildcard. For example, /hello/**/* matches all descendants of /hello.

Exclude patterns with !

  • Leading ! changes the meaning of an include pattern to exclude. Interleaved exclude patterns are supported.

Character sets with [ and ]

  • [] matches a set or range of characters within a file or directory name.

Comments with #

  • Patterns that begin with # are treated as comments.

Escaping

  • Wrapping special characters in [] can be used to escape literal glob characters in a file name. For example the literal file name hello[a-z] can be escaped as hello[[]a-z].

Example

The following expressions can be used in the Contents field of the "Copy Files" build step to create a deployment package for a web project:

**\?(.config|.dll|*.sitemap)
**\?(.exe|.dll|.pdb|.xml|*.resx)
**\?(.js|.css|.html|.aspx|.ascx|.asax|.Master|.cshtml|*.map)
**\?(.gif|.png|.jpg|.ico|*.pdf)

Note: You might need to add more extensions, depending on the needs of your project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!