tfsbuild - Powershell: The specified path, or filename, or both, are too long - Directory Excludes -
we’ve been running script fine previously, we’ve been getting issues (see below error) our config transform step our tfs build.
$servicefiles = get-childitem $localworkspace -recurse | {$_.extension -eq ".exe"}
we switched using gulp compile our css , js has given “node_modules” folder. looks it’s trying crawl these folders , gets directory length limit. i’ve tried various suggestions i’ve found googling , other related questions on so, none seem working me, it’s still hitting same error (and assume isn’t excluding these folders)
this example of modified version i've tried using exclude folders
$excludeddirectories = @("*node_modules*", "*packages*", "*common*"); write-verbose $localworkspace # services config types (service configs named same assmebly .exe) $servicefiles = get-childitem $localworkspace -recurse -exclude $excludeddirectories | ?{$_.extension -eq ".exe" -and $_.fullname -notmatch '*node_modules*' }
i've tried variations on based on other questions , answers, solution evades me. i've read few sources -exclude
doesn't work lot of people in situations, tried solution of clause exclude folder (i want exclude multiple, tried node_modules see if past that, other folders aren't deep)
i want exclude node_modules directory, along couple of others don't need checked transform. appreciated, thank you.
unfortunately, -exclude
parameter won't exclude directories before enumerating files. still errors out. need exclude them earlier that.
if directories exist @ top level, can enumerate top level directories, exclude ones don't want, , examine contents inside remaining directories. this:
$excludeddirectories = @("node_modules", "packages", "common") $servicefiles = get-childitem $localworkspace -exclude $excludeddirectories | % { get-childitem $_ -recurse } | ? {$_.extension -eq ".exe" }
also, can make bit simpler using -include
:
$servicefiles = get-childitem $localworkspace -exclude $excludeddirectories | % { get-childitem $_ -recurse -include "*.exe" }
notice did. removed top level -recurse
, filtered out directories. used -recurse
on remaining children of top-most parent, giving files we're looking for.
if directories need filter out appear deep in hierarchy or @ multiple levels, you'll have write own recursive traversal function:
function get-childitemrecursiveexclude( [parameter(mandatory=$true)][string[]]$path, [parameter(mandatory=$true)][string[]]$excludeddirnames ) { $immediatechildren = get-childitem $path -exclude $excludeddirnames foreach ($c in $immediatechildren) { # uncaptured output returned $c if (test-path $c -pathtype container) { get-childitemrecursiveexclude $c $excludeddirnames } } } $servicefiles = get-childitemrecursiveexclude $localworkspace @("node_modules", "packages", "common") | ? { $_.extension -eq ".exe" }
overall, basic idea have keep powershell traversing down node_modules
in first place. npm creates deep hierarchies surpass old limits on path lengths. (i'm not clear why .net still enforces them, though of underlying windows api no longer does. example, robocopy , several third party runtimes, node, don't bother them.)
Comments
Post a Comment