Skip to content

Commit ac0f4c7

Browse files
author
Zach Carpenter
authored
Update PowerShell Helper Library (#196)
This upgrades all the projects to netcoreapp3.1 and updates the powershell functions to include the proper library function.
1 parent da3300c commit ac0f4c7

File tree

6 files changed

+39
-63
lines changed

6 files changed

+39
-63
lines changed

Diff for: Tools/PowershellModule/src/Microsoft.WinGet.Source.psm1

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
11
<#
2-
Importing the Module requires that the Script be signed... or that Running scripts be approved for the computer.
2+
Importing the Module requires that the Script be signed... or that Running scripts be approved for the computer.
33
4-
Compiled RestAPIs Compressed folder must exist in the ".\Library\RestAPI\" container.
5-
Desktop AppInstaller Library must exist in the ".\Library\AppInstallerLib" container.
4+
Compiled RestAPIs Compressed folder must exist in the ".\Library\RestAPI\" container.
5+
Desktop AppInstaller Library must exist in the ".\Library\AppInstallerLib" container.
66
#>
77

88
## Loads Libraries
99
Get-ChildItem -Path "$PSScriptRoot\Library" -Filter *.ps1 | foreach-object { . $_.FullName }
1010

11-
[version] $WinGetModulePsVersion = $(Get-Host).Version
12-
[version] $WinGetLibMinVersionPS51 = [version]::New("5.1")
13-
$WinGetDesktopAppInstallerLibLoaded = $false
11+
[string] $WinGetPSEdition = "Core"
1412

15-
## Loads the binaries from the Desktop App Installer Library - Only if running PowerShell at a specified version
16-
if ($WinGetModulePsVersion -ge $WinGetLibMinVersionPS51) {
17-
if([intPtr]::size -eq 4){
18-
## PowerShell window is in x86 architecture.
19-
Add-Type -Path "$PSScriptRoot\Library\HelperLib\x86\Microsoft.Winget.PowershellSupport.dll"
20-
$WinGetDesktopAppInstallerLibLoaded = $true
13+
## Loads the binaries from the Desktop App Installer Library - Only if running PowerShell at a specified edition
14+
if ($PSEdition -eq $WinGetPSEdition) {
15+
try {
16+
Add-Type -Path "$PSScriptRoot\Library\WinGet.RestSource.PowershellSupport\Microsoft.Winget.PowershellSupport.dll"
2117
}
22-
else{
23-
## PowerShell window is in x64 architecture.
24-
Add-Type -Path "$PSScriptRoot\Library\HelperLib\x64\Microsoft.Winget.PowershellSupport.dll"
25-
$WinGetDesktopAppInstallerLibLoaded = $true
18+
catch [System.Reflection.ReflectionTypeLoadException] {
19+
Write-Host "Message: $($_.Exception.Message)"
20+
Write-Host "StackTrace: $($_.Exception.StackTrace)"
21+
Write-Host "LoaderExceptions: $($_.Exception.LoaderExceptions)"
22+
throw $_
2623
}
2724
}
2825
else {
29-
throw "Unable to load required binaries. Verify your PowerShell version is greater than $($WinGetLibMinVersionPS51.ToString())."
26+
throw "Unable to load required binaries. Verify you are using Powershell $($WinGetPSEdition)."
3027
}
3128

3229
## Validates that the required Azure Modules are present when the script is imported.
3330
[string[]]$RequiredModules = @("Az.Resources", "Az.Accounts", "Az.Websites", "Az.Functions")
3431

3532
## Verifies that the Azure Modules were previously installed.
3633
[Boolean] $TestResult = Test-PowerShellModuleExist -Modules $RequiredModules
37-
if(!$TestResult) {
34+
if (!$TestResult) {
3835
## Installs the required Azure Modules if not already installed
3936
$RequiredModules | ForEach-Object { Install-Module $_ -Force }
4037
}
4138

4239
## Verifies that the Azure Modules were successfully installed.
4340
[Boolean] $TestResult = Test-PowerShellModuleExist -Modules $RequiredModules
44-
if(!$TestResult) {
41+
if (!$TestResult) {
4542
## Modules have been identified as missing
4643
Write-Host ""
4744
$ErrorMessage = "There are missing PowerShell modules that must be installed.`n"

Diff for: pipelines/templates/copy-and-publish-powershell.yml

+16-38
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,26 @@
11
# Template helper to copy PowerShell scripts and all dependencies
22
parameters:
3-
helperLibsPath: '$(Build.SourcesDirectory)\src\WinGet.RestSource.PowershellSupport\bin\$(BuildConfiguration)\netstandard2.0'
4-
templatesPath: '$(build.SourcesDirectory)\src\WinGet.RestSource.Infrastructure\bin\$(BuildConfiguration)'
3+
helperLibsPath: '$(Build.SourcesDirectory)\src\WinGet.RestSource.PowershellSupport\bin\$(BuildConfiguration)\netcoreapp3.1'
4+
templatesPath: '$(Build.SourcesDirectory)\src\WinGet.RestSource.Infrastructure\bin\$(BuildConfiguration)'
55

66
steps:
77
- task: CopyFiles@2
8-
displayName: 'Copy Files: Powershell module'
8+
displayName: 'Copy Files: Powershell Module'
99
inputs:
10-
SourceFolder: '$(build.SourcesDirectory)\Tools\PowershellModule\src'
11-
TargetFolder: '$(build.artifactstagingdirectory)\Winget.PowerShell.Source'
10+
SourceFolder: '$(Build.SourcesDirectory)\Tools\PowershellModule\src'
11+
TargetFolder: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source'
1212
CleanTargetFolder: true
1313
OverWrite: true
1414

15-
- task: CopyFiles@2
16-
displayName: 'Copy Files: Helper Libs x86'
17-
inputs:
18-
Contents: |
19-
${{ parameters.helperLibsPath }}\Microsoft.Extensions.Logging.Abstractions.dll
20-
${{ parameters.helperLibsPath }}\Microsoft.WinGet.PowershellSupport.dll
21-
${{ parameters.helperLibsPath }}\Microsoft.WinGet.RestSource.Utils.dll
22-
${{ parameters.helperLibsPath }}\Newtonsoft.Json.dll
23-
${{ parameters.helperLibsPath }}\System.ComponentModel.Annotations.dll
24-
${{ parameters.helperLibsPath }}\YamlDotNet.dll
25-
${{ parameters.helperLibsPath }}\WinGetUtilInterop.dll
26-
${{ parameters.helperLibsPath }}\runtimes\win-x86\native\WinGetUtil.dll
27-
TargetFolder: '$(build.artifactstagingdirectory)\Winget.PowerShell.Source\Library\HelperLib\x86'
28-
OverWrite: true
29-
flattenFolders: true
30-
31-
- task: CopyFiles@2
32-
displayName: 'Copy Files: Helper libs x64'
15+
# Publish Helper Libs - win-x86
16+
- task: DotNetCoreCLI@2
17+
displayName: 'Package Helper Libs: Portable'
3318
inputs:
34-
Contents: |
35-
${{ parameters.helperLibsPath }}\Microsoft.Extensions.Logging.Abstractions.dll
36-
${{ parameters.helperLibsPath }}\Microsoft.WinGet.PowershellSupport.dll
37-
${{ parameters.helperLibsPath }}\Microsoft.WinGet.RestSource.Utils.dll
38-
${{ parameters.helperLibsPath }}\Newtonsoft.Json.dll
39-
${{ parameters.helperLibsPath }}\System.ComponentModel.Annotations.dll
40-
${{ parameters.helperLibsPath }}\YamlDotNet.dll
41-
${{ parameters.helperLibsPath }}\WinGetUtilInterop.dll
42-
${{ parameters.helperLibsPath }}\runtimes\win-x64\native\WinGetUtil.dll
43-
TargetFolder: '$(build.artifactstagingdirectory)\Winget.PowerShell.Source\Library\HelperLib\x64'
44-
OverWrite: true
45-
flattenFolders: true
19+
command: publish
20+
publishWebProjects: false
21+
projects: '$(Build.SourcesDirectory)\src\WinGet.RestSource.PowershellSupport\WinGet.RestSource.PowershellSupport.csproj'
22+
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Library --no-restore'
23+
zipAfterPublish: false
4624

4725
- task: CopyFiles@2
4826
displayName: 'Copy Files: Arm Templates'
@@ -58,19 +36,19 @@ steps:
5836
${{ parameters.templatesPath }}\**\frontdoor.json
5937
${{ parameters.templatesPath }}\**\keyvault.json
6038
${{ parameters.templatesPath }}\**\storageaccount.json
61-
TargetFolder: '$(build.artifactstagingdirectory)\Winget.PowerShell.Source\Library\ARMTemplate'
39+
TargetFolder: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Library\ARMTemplate'
6240
OverWrite: true
6341
flattenFolders: true
6442

6543
- task: CopyFiles@2
6644
displayName: 'Copy Files: azure function'
6745
inputs:
6846
SourceFolder: '$(Build.ArtifactStagingDirectory)\WinGet.RestSource.Functions'
69-
TargetFolder: '$(build.artifactstagingdirectory)\Winget.PowerShell.Source\Library\RestAPI'
47+
TargetFolder: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Library\RestAPI'
7048
OverWrite: true
7149

7250
- task: PublishBuildArtifacts@1
7351
displayName: 'Publish Artifact: WinGet.RestSource-Winget.PowerShell.Source'
7452
inputs:
75-
PathtoPublish: '$(build.artifactstagingdirectory)\Winget.PowerShell.Source'
53+
PathtoPublish: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source'
7654
ArtifactName: 'WinGet.RestSource-Winget.PowerShell.Source'

Diff for: src/Microsoft.WindowsPackageManager.Rest/Microsoft.WindowsPackageManager.Rest.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<Company>Microsoft</Company>
66
<Authors>Microsoft</Authors>
77
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

Diff for: src/WinGet.RestSource.IntegrationTest/WinGet.RestSource.IntegrationTest.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp5.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<Company>Microsoft</Company>
66
<Authors>Microsoft</Authors>
77
<AssemblyName>Microsoft.WinGet.RestSource.IntegrationTest</AssemblyName>
88
<RootNamespace>Microsoft.WinGet.RestSource.IntegrationTest</RootNamespace>
99
<IsPackable>false</IsPackable>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
11+
<LangVersion>9</LangVersion>
1112
</PropertyGroup>
1213

1314
<PropertyGroup>

Diff for: src/WinGet.RestSource.PowershellSupport/WinGet.RestSource.PowershellSupport.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<Company>Microsoft</Company>
66
<Authors>Microsoft</Authors>
77
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
@@ -67,4 +67,4 @@
6767
<Copy SourceFiles="@(WinGetDll)" DestinationFiles="@(WinGetDll->'$(OutDir)\runtimes\%(RecursiveDir)%(Filename)%(Extension)')" />
6868
</Target>
6969

70-
</Project>
70+
</Project>

Diff for: src/WinGet.RestSource.Utils/WinGet.RestSource.Utils.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<Company>Microsoft</Company>
66
<Authors>Microsoft</Authors>
77
<AssemblyName>Microsoft.WinGet.RestSource.Utils</AssemblyName>

0 commit comments

Comments
 (0)