-
Notifications
You must be signed in to change notification settings - Fork 1
/
BuildTools.ps1
132 lines (110 loc) · 5.54 KB
/
BuildTools.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#======================================================
# Modified from Markus Scholtes, DEVK 2016
# Create EXEs in sub-Dir "ToolsEXE"
#======================================================
# USAGE/SYNTAX:
# ps2exe.ps1 -inputFile script.ps1 -outputFile script.exe -elevated -title 'Nielsen Product Support' -version '1.0.0.0' -verbose -noConsole
#
# NOTE1: Run Flag -runtime20 on Windows 10, cause runtime issue of BitsTransfer not loading properly.
# NOTE2: Run Flag -elevated on PS2, might cause runtime issues.
# Target Folder of Tool Scripts
#---------------------------------------
$pShellVer = $PSVersionTable.PSVersion.Major
$SCRIPTROOT = Split-Path $SCRIPT:MyInvocation.MyCommand.Path -parent
$Build20 = 1
$Build40 = 1
$BuildEXE = 1
$BuildCMD = 0
# $Verbose = 1
$Ext = "*.ps1"
$PS2EXE = "$SCRIPTROOT\ps2exe.ps1"
$SRCRelPath = "Scripts\"
$EXE20RelPath = "ToolsEXE-PS2"
$EXE40RelPath = "ToolsEXE-PS4"
$SRCPath = "$SCRIPTROOT\$SRCRelPath"
$EXE20Path = "$SCRIPTROOT\$EXE20RelPath"
$EXE40Path = "$SCRIPTROOT\$EXE40RelPath"
# Tool Info/Versions
#---------------------------------------
$myTitle = "TLS Support"
$myCompany = ""
$myProduct = "TLS Protocol Upgrade"
$myVersion = "1.0.0"
# $myIcon = "$SRCPath\icon.ico"
# Write Out Paths
#---------------------------------------
Write-Host ""
Write-Host ">>> Build Root : $SCRIPTROOT"
Write-Host ">>> PS2EXE Root : $PS2EXE"
Write-Host ">>> Source Path : $SRCPath"
Write-Host ">>> EXEPS2 Path : $EXE20Path"
Write-Host ">>> EXEPS4 Path : $EXE40Path"
Write-Host ""
# Clear Old Build Files
#---------------------------------------
if ($Build20) { Remove-Item -path "$EXE20Path\*" }
if ($Build40) { Remove-Item -path "$EXE40Path\*" }
# List PS1 Files and Convert Them
#---------------------------------------
$srcFiles = Get-ChildItem "$SRCPATH\$Ext"
foreach ($srcFile in $srcFiles){
# Write-Host ">>> Source File : $($srcFile.Replace($SCRIPTROOT,''))"
if ($Build20) {
$exe20File = "$EXE20Path\$($srcFile.Name.Replace('.ps1','.exe'))"
$cmd20File = "$EXE20Path\$($srcFile.Name.Replace('.ps1','-CMD.exe'))"
if ($BuildEXE) {
Write-Host ">>> EXE 20 File : $($exe20File.Replace($SCRIPTROOT,''))"
."$PS2EXE" -inputFile "$srcFile" -outputFile "$exe20File" -noConsole -runtime20 -elevated -title $myTitle -company $myCompany -product $myProduct -version $myVersion -iconFile $myIcon
}
if ($BuildCMD) {
Write-Host ">>> CMD 20 File : $($cmd20File.Replace($SCRIPTROOT,''))"
."$PS2EXE" -inputFile "$srcFile" -outputFile "$cmd20File" -runtime20 -elevated -title $myTitle -company $myCompany -product $myProduct -version $myVersion -iconFile $myIcon
}
}
if ($Build40) {
$exe40File = "$EXE40Path\$($srcFile.Name.Replace('.ps1','.exe'))"
$cmd40File = "$EXE40Path\$($srcFile.Name.Replace('.ps1','-CMD.exe'))"
if ($BuildEXE) {
Write-Host ">>> EXE 40 File : $($exe40File.Replace($SCRIPTROOT,''))"
."$PS2EXE" -inputFile "$srcFile" -outputFile "$exe40File" -noConsole -elevated -title $myTitle -company $myCompany -product $myProduct -version $myVersion -iconFile $myIcon
}
if ($BuildCMD) {
Write-Host ">>> CMD 40 File : $($cmd40File.Replace($SCRIPTROOT,''))"
."$PS2EXE" -inputFile "$srcFile" -outputFile "$cmd40File" -elevated -title $myTitle -company $myCompany -product $myProduct -version $myVersion -iconFile $myIcon
}
}
}
Write-Host "Build Completed!"
# $NULL = Read-Host "Press enter to exit"
# Usage:
#
# powershell.exe -command &'.\ps2exe.ps1' [-inputFile] '<file_name>' [-outputFile] '<file_name>'
# [-verbose] [-debug] [-runtime20|-runtime30|-runtime40] [-lcid <id>] [-x86|-x64] [-Sta|-Mta]
# [-noConsole] [-iconFile '<file_name>'] [-elevated]
# [-title '<title-string>'] [-description '<description-string>'] [-company '<company-string>']
# [-product '<product-string>'] [-copyright '<copyright-string>'] [-version '<version-string>']
#
# inputFile = powerShell script that you want to convert to EXE
# outputFile = destination EXE file name
# verbose = output verbose informations - if any
# debug = generate debug informations for output file
# runtime20 = this switch forces PS2EXE to create a config file for the generated EXE that contains the
# supported .NET Framework versions"" setting for .NET Framework 2.0 for PowerShell 2.0
# runtime30 = this switch forces PS2EXE to create a config file for the generated EXE that contains the
# supported .NET Framework versions"" setting for .NET Framework 4.0 for PowerShell 3.0
# runtime40 = this switch forces PS2EXE to create a config file for the generated EXE that contains the
# supported .NET Framework versions"" setting for .NET Framework 4.0 for PowerShell 4.0
# lcid = location ID for the compiled EXE. Current user culture if not specified.
# x86 = compile for 32-bit runtime only
# x64 = compile for 64-bit runtime only
# sta = Single Thread Apartment Mode
# mta = Multi Thread Apartment Mode
# noConsole = the resulting EXE file will be a Windows Forms app without a console window.
# iconFile = icon for the compiled EXE
# elevated = include manifest to request admin privileges
# title = title to include in assembly information
# description = description to include in assembly information
# company = company name to include in assembly information
# product = product name to include in assembly information
# copyright = copyright to include in assembly information
# version = version to include in assembly information