powershell - Compress sourcecode excluding binaries -


i want write script our build server (windows machine).

one part extracting binaries , deleting debugging files. have code already.

the second part getting sourcefiles of project (wpf) , compress it, excluding /bin/ , /obj/ folders.

what i've got far is:

# # , zip sourcefiles #  # relevant folders , files [string[]]$folderexcludes = @('*bin*', '*obj*')  $folders = get-childitem -directory -recurse -exclude $folderexcludes | %{      $allowed = $true     foreach ($exclude in $folderexcludes) {          if ((split-path $_.fullname -parent) -ilike $exclude) {              $allowed = $false             break         }     }     if ($allowed) {         $_     } }  [string[]]$fileexcludes = @('*.git*', 'sonar-project.properties')  $files = $folders | get-childitem -file | %{     $allowed = $true      foreach ($exclude in $fileexcludes) {          if ($_.name -ilike $exclude) {              $allowed = $false             break         }     }     if ($allowed) {         $_.fullname     } }  $files 

the list of files contains files want zip. when do

set-alias sz "$env:programfiles\7-zip\7z.exe" $files | %{ sz -mx=9 "$sourcepath\$artifactpath.zip" $_ } 

it gets files , places them root.

when try zip folders, 7zip takes folders, includes bin , obj , includes hidden .git folders (which don't tend release source code).

so how can compress source file without bin/obj folders , without breaking filepaths insidde zip?

btw tried delete folders, after build process , after copying binaries export-folder, powershell seems hold files can't delete @ time :(

a more stupid idea copying of , deleting bin , obj folders there.. seems inefficient.

and don't need use 7zip. i'm fine winzip or else. wanted compress sourcecode.

see answer on superuser: https://superuser.com/a/97347/440614

set-alias sz "$env:programfiles\7-zip\7z.exe" sz -mx=9 "$sourcepath\$artifactpath.zip" foldertoarchive\ -mx0 -xr!bin -xr!obj -xr!.git, -xr!sonar-project.properties 

...may need tweaking, should give start.


Comments