forked from pnp/powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild-Debug.ps1
191 lines (169 loc) · 7.55 KB
/
Build-Debug.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#Requires -PSEdition Core
Param(
[Parameter(Mandatory = $false,
ValueFromPipeline = $false)]
[switch]
$NoIncremental,
[Parameter(Mandatory = $false,
ValueFromPipeline = $false)]
[switch]
$Force,
[Parameter(Mandatory = $false,
ValueFromPipeline = $false)]
[switch]
$LocalPnPFramework,
[Parameter(Mandatory = $false,
ValueFromPipeline = $false)]
[switch]
$LocalPnPCore
)
$localPnPCoreSdkPathValue = $env:PnPCoreSdkPath
$localPnPFrameworkPathValue = $env:PnPFrameworkPath
$env:PnPCoreSdkPath = ""
$env:PnPFrameworkPath = ""
$versionFileContents = Get-Content "$PSScriptRoot/../version.json" -Raw | ConvertFrom-Json
if ($versionFileContents.Version.Contains("%")) {
$versionString = $versionFileContents.Version.Replace("%", "0");
$versionObject = [System.Management.Automation.SemanticVersion]::Parse($versionString)
$buildVersion = $versionObject.Patch;
}
else {
$versionObject = [System.Management.Automation.SemanticVersion]::Parse($versionFileContents.Version)
$buildVersion = $versionObject.Patch + 1;
}
# $versionFileContents = Get-Content "$PSScriptRoot/../version.txt" -Raw
# if ($versionFileContents.Contains("%")) {
# $versionString = $versionFileContents.Replace("%", "0");
# $versionObject = [System.Management.Automation.SemanticVersion]::Parse($versionString)
# $buildVersion = $versionObject.Patch;
# }
# else {
# $versionObject = [System.Management.Automation.SemanticVersion]::Parse($versionFileContents)
# $buildVersion = $versionObject.Patch + 1;
# }
$configuration = "net8.0"
$version = "$($versionObject.Major).$($versionObject.Minor).$buildVersion"
Write-Host "Building PnP.PowerShell version $version-debug" -ForegroundColor Yellow
$buildCmd = "dotnet build `"$PSScriptRoot/../src/Commands/PnP.PowerShell.csproj`"" + "--nologo --configuration Debug -p:VersionPrefix=$version -p:VersionSuffix=debug";
if ($NoIncremental) {
$buildCmd += " --no-incremental";
}
if ($Force) {
$buildCmd += " --force"
}
if ($LocalPnPFramework) {
# Check if available
$pnpFrameworkAssembly = Join-Path $PSScriptRoot -ChildPath "..\..\pnpframework\src\lib\PnP.Framework\bin\Debug\netstandard2.0\PnP.Framework.dll"
$pnpFrameworkAssembly = [System.IO.Path]::GetFullPath($pnpFrameworkAssembly)
if (Test-Path $pnpFrameworkAssembly -PathType Leaf) {
$buildCmd += " -p:PnPFrameworkPath=`"..\..\..\pnpframework\src\lib\`""
}
else {
$localFolder = Join-Path $PSScriptRoot -ChildPath "..\..\pnpframework"
$localFolder = [System.IO.Path]::GetFullPath($localFolder)
Write-Error -Message "Please make sure you have a local copy of the PnP.Framework repository installed at $localFolder"
}
}
if ($LocalPnPCore) {
# Check if available
$pnpCoreAssembly = Join-Path $PSScriptRoot -ChildPath "..\..\pnpcore\src\sdk\PnP.Core\bin\Debug\netstandard2.0\PnP.Core.dll"
$pnpCoreAssembly = [System.IO.Path]::GetFullPath($pnpCoreAssembly)
if (Test-Path $pnpCoreAssembly -PathType Leaf) {
$buildCmd += " -p:PnPCoreSdkPath=`"..\..\..\pnpcore\src\sdk\`""
}
else {
$localFolder = Join-Path $PSScriptRoot -ChildPath "..\..\pnpcore"
$localFolder = [System.IO.Path]::GetFullPath($localFolder)
Write-Error -Message "Please make sure you have a local copy of the PnP.Core repository installed at $localFolder"
}
}
Write-Host "Executing $buildCmd" -ForegroundColor Yellow
Invoke-Expression $buildCmd
if ($LASTEXITCODE -eq 0) {
$documentsFolder = [environment]::getfolderpath("mydocuments");
if ($IsLinux -or $isMacOS) {
$destinationFolder = "$HOME/.local/share/powershell/Modules/PnP.PowerShell"
}
else {
$destinationFolder = "$documentsFolder/PowerShell/Modules/PnP.PowerShell"
}
$corePath = "$destinationFolder/Core"
$commonPath = "$destinationFolder/Common"
$assemblyExceptions = @("System.Memory.dll");
Try {
# Module folder there?
if (Test-Path $destinationFolder) {
# Yes, empty it. Do it per folder as that seems the only way to delete the PS modules from a ODB synced folder
Remove-Item $destinationFolder\common\* -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $destinationFolder\core\* -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $destinationFolder\framework\* -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $destinationFolder\* -Recurse -Force -ErrorAction SilentlyContinue
}
# No, create it
Write-Host "Creating target folders: $destinationFolder" -ForegroundColor Yellow
New-Item -Path $destinationFolder -ItemType Directory -Force | Out-Null
New-Item -Path "$destinationFolder\Core" -ItemType Directory -Force | Out-Null
New-Item -Path "$destinationFolder\Common" -ItemType Directory -Force | Out-Null
Write-Host "Copying files to $destinationFolder" -ForegroundColor Yellow
$commonFiles = [System.Collections.Generic.Hashset[string]]::new()
Copy-Item -Path "$PSScriptRoot/../resources/*.ps1xml" -Destination "$destinationFolder"
Get-ChildItem -Path "$PSScriptRoot/../src/ALC/bin/Debug/net8.0" | Where-Object { $_.Extension -in '.dll', '.pdb' } | Foreach-Object { if (!$assemblyExceptions.Contains($_.Name)) { [void]$commonFiles.Add($_.Name) }; Copy-Item -LiteralPath $_.FullName -Destination $commonPath }
Get-ChildItem -Path "$PSScriptRoot/../src/Commands/bin/Debug/$configuration" | Where-Object { $_.Extension -in '.dll', '.pdb' -and -not $commonFiles.Contains($_.Name) } | Foreach-Object { Copy-Item -LiteralPath $_.FullName -Destination $corePath }
}
Catch {
Write-Error "Cannot copy files to $destinationFolder. Maybe a PowerShell session is still using the module or PS modules are hosted in a OneDrive synced location. In the latter case, manually delete $destinationFolder and try again."
exit 1
}
Try {
Write-Host "Generating PnP.PowerShell.psd1" -ForegroundColor Yellow
# Load the Module in a new PowerShell session
$scriptBlock = {
$documentsFolder = [environment]::getfolderpath("mydocuments");
if ($IsLinux) {
$destinationFolder = "$documentsFolder/.local/share/powershell/Modules/PnP.PowerShell"
}
elseif ($IsMacOS) {
$destinationFolder = "~/.local/share/powershell/Modules/PnP.PowerShell"
}
else {
$destinationFolder = "$documentsFolder/PowerShell/Modules/PnP.PowerShell"
}
Write-Host "Importing dotnet core version of assembly"
Import-Module -Name "$destinationFolder/Core/PnP.PowerShell.dll" -DisableNameChecking
$cmdlets = get-command -Module PnP.PowerShell | ForEach-Object { "`"$_`"" }
$cmdlets -Join ","
}
$cmdletsString = Start-ThreadJob -ScriptBlock $scriptBlock | Receive-Job -Wait
$manifest = "@{
NestedModules = 'Core/PnP.PowerShell.dll'
ModuleVersion = '$version'
Description = 'Microsoft 365 Patterns and Practices PowerShell Cmdlets'
GUID = '0b0430ce-d799-4f3b-a565-f0dca1f31e17'
Author = 'Microsoft 365 Patterns and Practices'
CompanyName = 'Microsoft 365 Patterns and Practices'
CompatiblePSEditions = @('Core')
PowerShellVersion = '7.4.4'
ProcessorArchitecture = 'None'
FunctionsToExport = '*'
CmdletsToExport = @($cmdletsString)
VariablesToExport = '*'
AliasesToExport = '*'
FormatsToProcess = 'PnP.PowerShell.Format.ps1xml'
PrivateData = @{
PSData = @{
Prerelease = 'debug'
ProjectUri = 'https://aka.ms/sppnp'
IconUri = 'https://raw.githubusercontent.com/pnp/media/40e7cd8952a9347ea44e5572bb0e49622a102a12/parker/ms/300w/parker-ms-300.png'
}
}
}"
$manifest | Out-File "$destinationFolder/PnP.PowerShell.psd1"
}
Catch {
Write-Host "Error: Cannot generate PnP.PowerShell.psd1. Maybe a PowerShell session is still using the module?"
exit 1
}
Write-Host "`n`n Build and provisioning succeeded`n Version: $version" -ForegroundColor Green
}
$env:PnPCoreSdkPath = $localPnPCoreSdkPathValue
$env:PnPFrameworkPath = $localPnPFrameworkPathValue