-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.ps1
More file actions
108 lines (96 loc) 路 3.85 KB
/
Copy pathBuild.ps1
File metadata and controls
108 lines (96 loc) 路 3.85 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
<#
.SYNOPSIS
Build the project
.DESCRIPTION
Build the project and copy the DLL to the Module directory.
.PARAMETER Configuration
The configuration of the build (`Debug` or `Release`) [Default: `Debug`]
.PARAMETER TargetFramework
The target framework of the build (`net8.0`, `net9.0` or `net10.0`) [Default: `net9.0`]
.PARAMETER Clean
If specified, cleans the project before building.
.EXAMPLE
./Build.ps1
Run the build script to build the project (in debug configuration) and copy the DLL to the Module directory.
.EXAMPLE
./Build.ps1 -Configuration Release -Clean
Clean and build the project in release configuration.
#>
[CmdletBinding(DefaultParameterSetName = 'Build')]
param(
# The configuration of the build (`Debug` or `Release`) [Default: `Debug`]
[Parameter(ParameterSetName = 'Build')]
[ValidateSet('Debug', 'Release')]
[string] $Configuration = 'Debug',
# The target framework of the build (`net8.0`, `net9.0` or `net10.0`) [Default: `net9.0`]
[ValidateSet("net8.0", "net9.0", "net10.0")]
[ValidateNotNullOrEmpty()]
[string] $TargetFramework = "net9.0",
# Clean the project before building
[switch] $Clean
)
# Path to the Predictor project
$Project = Join-Path $PSScriptRoot "Predictor" "PSFavoritePredictor.csproj"
# Clean the project if the -Clean switch is specified
if ($Clean) {
Write-Host "Cleaning project ($Configuration)..."
dotnet clean $Project -c $Configuration -f $TargetFramework
}
# Build the Predictor DLL
Write-Host "Building project ($Configuration)..."
try {
dotnet build $Project -c $Configuration -f $TargetFramework
}
catch {
Write-Error "Build failed: $($_.Exception.Message)"
exit 1
}
# Items to copy to the Module directory
$Items = @(
@{
Source = Join-Path $PSScriptRoot "Predictor" "bin" $Configuration $TargetFramework "PSFavoritePredictor.dll"
Destination = Join-Path $PSScriptRoot "Module" "Library" "PSFavoritePredictor.dll"
},
@{
Source = Join-Path $PSScriptRoot "README.md"
Destination = Join-Path $PSScriptRoot "Module" "README.md"
},
@{
Source = Join-Path $PSScriptRoot "LICENSE"
Destination = Join-Path $PSScriptRoot "Module" "LICENSE"
}
)
# Copy items with Error Handling
foreach ($item in $Items) {
try {
# Ensure the destination directory exists
$destDir = Split-Path -Path $item.Destination -Parent
if (!(Test-Path -Path $destDir)) {
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
Write-Verbose "Created directory: $destDir"
}
# If the destination file already exists, remove it before copying the new file
if (Test-Path -Path $item.Destination) {
Remove-Item -Path $item.Destination -Force
}
# Copy the file to the destination
Copy-Item -Path $item.Source -Destination $item.Destination -Force
Write-Output "Copied $($item.Source) to $($item.Destination)"
}
catch {
$msg = $_.Exception.Message
# Specific handling for the locked DLL issue vs other errors
if ($item.Destination -like "*PSFavoritePredictor.dll" -and ($msg -like "*used by another process*" -or $msg -like "*Access to the path*denied*")) {
Write-Host ""
Write-Host "CRITICAL ERROR: Access Denied to PSFavoritePredictor.dll" -ForegroundColor Red
Write-Host "The DLL is likely locked because the module is loaded in an active PowerShell session." -ForegroundColor Yellow
Write-Host "To fix this, please close all PowerShell windows and try again." -ForegroundColor Yellow
Write-Host ""
}
else {
Write-Error "Failed to copy $($item.Source) to $($item.Destination): $msg"
}
exit 1
}
}
Write-Host "Build and Copy completed successfully!" -ForegroundColor Green