我想为我们的构建服务器(windows机器)编写一个脚本。压缩不包含二进制文件的源代码
一部分是提取二进制文件并删除所有调试文件。我已经有了这个代码。
第二部分是获取项目的源文件(WPF)并压缩它,不包括/ bin /和/ obj /文件夹。
到目前为止,我已经得到了什么是:
#
# Get and zip Sourcefiles
#
# Get relevant folders and 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
的文件列表中包含了我要压缩所有文件。但是当我做
set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
$Files | %{ sz a -mx=9 "$SourcePath\$ArtifactPath.zip" $_ }
它获取所有文件并将它们放入根目录。
当我尝试压缩文件夹时,7zip会占用所有文件夹,包括bin和obj,并包含隐藏的.git文件夹(我们不倾向于使用源代码发布)。
那么我如何压缩没有bin/obj文件夹的源文件,并且不会破坏zip文件中的文件路径?
顺便说一句我试图删除文件夹,在构建过程后复制二进制文件到他们的出口文件夹之后,但在PowerShell中似乎举行的文件,所以我不能在那个时候:(
删除一个更愚蠢的想法是复制所有这些,并删除bin和obj文件夹..但它似乎是非常低效的。
而且我不需要使用7zip。我完全用winzip或其他任何东西。只想压缩源代码。
您使用哪个版本的PS。 PS 5本地支持使用compress-archive和expand-archive cmdlet进行zip归档。 – autosvet
是的,我使用PS 5(Windows 10,还没有1607)。除了命令,compress-archive是否有用? – ecth