-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.ps1
More file actions
166 lines (136 loc) · 4.62 KB
/
Build.ps1
File metadata and controls
166 lines (136 loc) · 4.62 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
param
(
[String]$CommitID,
[String]$Configuration = "Release",
[Switch]$Clean,
[Switch]$Help,
[Switch]$Test,
[Switch]$UseFullCommitID,
[String]$Version
)
$work = $pwd
$csprojPaths = @("Process.Extensions\Process.Extensions.csproj", "Process.Extensions.Tests\Process.Extensions.Tests.csproj")
$vcxprojPaths = @("Process.Extensions.Tests.Client\Process.Extensions.Tests.Client.vcxproj", "Process.Extensions.Tests.Client.DllExport\Process.Extensions.Tests.Client.DllExport.vcxproj")
$buildPaths = @("Process.Extensions\bin\")
$patchVersion = ".github\workflows\Patch-Version.ps1"
$vswhere = "Tools\vswhere.exe"
$dependencies = @($patchVersion, $vswhere)
if ($Help)
{
echo "Process.Extensions Build Script"
echo ""
echo "Usage:"
echo "-CommitID [id] - set the commit ID to use from GitHub for the version number."
echo "-Configuration [name] - build Process.Extensions with a specific configuration."
echo "-Clean - cleans the solution before building Process.Extensions."
echo "-Help - display help."
echo "-Test - run tests after building Process.Extensions."
echo "-UseFullCommitID - use the full 40 character commit ID for the version number."
echo "-Version [major].[minor].[revision] - set the version number for this build of Process.Extensions."
exit
}
# Check for dependencies.
foreach ($dependency in $dependencies)
{
$resolved = [System.IO.Path]::Combine($work, $dependency)
if (![System.IO.File]::Exists($resolved))
{
echo "Failed to locate build dependency: ${dependency}"
exit -1
}
}
# Check if the .NET SDK is installed.
if (!(Get-Command -Name dotnet -ErrorAction SilentlyContinue))
{
echo ".NET SDK is required to build Process.Extensions."
echo "You can install the required .NET SDK for Windows from here: https://dotnet.microsoft.com/en-us/download/dotnet/8.0"
exit -1
}
$vs = & "${vswhere}" -nologo -latest -prerelease -property installationPath
$msbuild = [System.IO.Path]::Combine($vs, "MSBuild\Current\Bin\MSBuild.exe")
if (![System.IO.File]::Exists($msbuild))
{
echo "Failed to locate MSBuild."
echo "Ensure that you have Visual Studio installed with the ""Desktop development with C++"" workload."
exit -1
}
function PatchVersionInformation([String]$commitID, [Boolean]$useFullCommitID, [String]$version)
{
# Patch the version number for all projects.
if (![System.String]::IsNullOrEmpty($version))
{
foreach ($project in [System.IO.Directory]::EnumerateFiles($work, "*.csproj", [System.IO.SearchOption]::AllDirectories))
{
& "${patchVersion}" -CommitID $commitID -ProjectPath "${project}" -Version $version
}
}
else
{
PatchVersionInformation "" $false "1.0.0"
}
}
function CheckMSBuildExitCode([String]$path, [Int32]$exitCode)
{
if ($exitCode -eq 0)
{
return
}
echo "Failed to build project (${exitCode}): ${path}"
exit $exitCode
}
foreach ($csprojPath in $csprojPaths)
{
if (!$Test -and $csprojPath.Contains("Test"))
{
continue
}
if ($Clean)
{
dotnet clean "${csprojPath}"
echo ""
}
# Patch version number before building.
PatchVersionInformation $CommitID $UseFullCommitID $Version
dotnet build "${csprojPath}" /p:Configuration="${Configuration}"
$exitCode = $LASTEXITCODE
# Restore default version number.
PatchVersionInformation "" $false "1.0.0"
CheckMSBuildExitCode $csprojPath $exitCode
}
foreach ($vcxprojPath in $vcxprojPaths)
{
if (!$Test)
{
continue
}
if ($Clean)
{
& "${msbuild}" "${vcxprojPath}" /t:Clean
echo ""
}
# Build test projects for both platforms to run tests native and on WoW64.
& "${msbuild}" "${vcxprojPath}" /p:Configuration="${Configuration}" /p:Platform="Win32"
CheckMSBuildExitCode $csprojPath $LASTEXITCODE
echo ""
& "${msbuild}" "${vcxprojPath}" /p:Configuration="${Configuration}" /p:Platform="x64"
CheckMSBuildExitCode $csprojPath $LASTEXITCODE
echo ""
}
if (!$Test)
{
exit
}
$testProgramDir = [System.IO.Path]::Combine($work, "Process.Extensions.Tests\bin\${Configuration}\net8.0")
$testProgram = [System.IO.Path]::Combine($testProgramDir, "Process.Extensions.Tests.exe")
if (![System.IO.File]::Exists($testProgram))
{
echo "Failed to locate test program..."
echo "It may have failed to build and cannot be tested."
exit -1
}
$testProcess = Start-Process -FilePath "${testProgram}" -WorkingDirectory "${testProgramDir}" -NoNewWindow -PassThru -Wait
if ($testProcess.ExitCode -ne 0)
{
exit $testProcess.ExitCode
}
exit 0