-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildDotnet.ps1
59 lines (42 loc) · 1.4 KB
/
BuildDotnet.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
$ErrorActionPreference = "Stop"
$apiPath = "Path/To/Api"
$apiPublishPath = "Path/To/Api/bin/Release/netcoreapp3.1/publish"
Write-Output "Building API..."
$process = Start-Process `
-FilePath "dotnet" `
-WorkingDirectory $apiPath `
-ArgumentList "publish -c Release" `
-PassThru
$process.WaitForExit();
if (-not ($apiPublishPath | Test-Path)) {
Write-Output "Build directory doesn't exist"
return
}
Write-Output "Build generated at: $apiPublishPath"
[string]$deleteFiles = Read-Host "Remove .json, .pdb and .config files? [y/n] (y)"
$noOptions = @('n', 'no')
if ($deleteFiles -in $noOptions) {
return
}
Get-ChildItem -Path $apiPublishPath | ForEach-Object {
if ($_.GetType().Name -Eq "DirectoryInfo") {
return
}
if ($_.Name -NotLike "*.json" -And $_.Name -NotLike "*.pdb" -And $_.Name -NotLike "*.config") {
return
}
if ($_.Name -Like "*.deps.json" -Or $_.Name -Like "*.runtimeconfig.json") {
return
}
Remove-Item $_.FullName
}
Write-Output "Files removed with success"
# Discomment this line if you want to open the folder with the build files
# Invoke-Item -Path $apiPublishPath
$apiExeFilePath = $apiPublishPath + "/TestApi.exe"
$apiExecutable = Get-Item $apiExeFilePath
return [pscustomobject]@{
# Returns the current version of the API
version = $apiExecutable[0].VersionInfo.FileVersion
buildPath = $apiPublishPath
}