I am trying to get away from using MsBuild scrips in my CD pipeline and I am having trouble replicating a specific target from my MsBuild script.
Here is the operation that I would like to perform in Powershell…
(gist since msbuild xml does not display here)
With this being the content of source
C:\staging\source\bin
C:\staging\source\content
C:\staging\source\config.xml
C:\staging\source\test.js
C:\staging\source\bin\release
C:\staging\source\bin\file1.txt
C:\staging\source\bin\file2.xml
C:\staging\source\bin\release\file3.cs
C:\staging\source\bin\release\file4.xml
C:\staging\source\content\page1.txt
C:\staging\source\content\page2.txt
The result in the destination folder should be this
C:\staging\destination\content
C:\staging\destination\content\page1.txt
C:\staging\destination\content\page2.txt
My first attempt was to use Get-ChildItem and Where-Object -notin but that was very slow and didn’t give me the same result as my MsBuild target.
$exclude = Get-Content "C:\staging\.exclude" $dest = "C:\staging\destination" $source = "C:\staging\source" $paths = $exclude | select @{Name = "FullExcludePath" ; Expression = { $source+$_ } } $itemsToExclude = $paths | foreach-object { gci $_.FullExcludePath -Recurse } gci $source -Recurse | Where-Object { $_ -notin $itemsToExclude }
My robocopy attempt… (still didn’t give me expected result)
$exclude = Get-Content "C:\staging\.exclude" $dest = "C:\staging\destination" $source = "C:\staging\source" $paths = $exclude | select @{Name = "FullExcludePath" ; Expression = { $source+$_ } } robocopy $source $dest "/s" "/xf" $paths
the content of .exclude is
\*.* \bin\**\*.*
The actual source folder is only 200mB but there are thousands of nested files and folders. I suspect this is why my Get-ChildItem was so slow.
Any help here would be greatly appreciated.
-T