Skip to content

Commit e28a62e

Browse files
Add Invoke-Member and Get-AssemblyLoadContext (#55)
* Add Invoke-Member and Get-AssemblyLoadContext * Forgot to save alias change * Update workflow versions * Fix test and skip code coverage * Fix artifact path casing * Fix the casing of the correct variable this time * Add tests for Invoke-Member * Reverse the `-If` to skip open cover * Add docs for `Invoke-Member` * Fix up galc and add some comments * Add galc formatting * Add docs for galc
1 parent ab7f910 commit e28a62e

37 files changed

+1466
-70
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ jobs:
2929
steps:
3030
- name: Check Version
3131
run: $PSVersionTable
32-
- uses: actions/checkout@v1
32+
- uses: actions/checkout@v6
3333
- name: Test and Build
3434
run: ./build.ps1 -Force -Configuration Release
35-
- uses: actions/upload-artifact@v1
35+
- uses: actions/upload-artifact@v4
3636
if: matrix.os == 'windows-latest'
3737
with:
3838
name: ClassExplorer
3939
path: ./Release/ClassExplorer
40-
- uses: actions/upload-artifact@v1
40+
- uses: actions/upload-artifact@v4
4141
if: matrix.os != 'windows-latest'
4242
with:
4343
name: ClassExplorer-${{ matrix.os }}
4444
path: ./Release/ClassExplorer
4545
- name: Upload Test Results
4646
if: always()
47-
uses: actions/upload-artifact@v2
47+
uses: actions/upload-artifact@v4
4848
with:
4949
name: Unit Test Results (${{ matrix.os }})
5050
path: ./TestResults/Pester.xml

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ jobs:
1919
name: Publish
2020
runs-on: windows-latest
2121
steps:
22-
- uses: actions/checkout@v1
22+
- uses: actions/checkout@v6
2323
- name: Test and Build
2424
run: ./build.ps1 -Force -Publish -Configuration Release
2525
env:
2626
GALLERY_API_KEY: ${{ secrets.GALLERY_API_KEY }}
2727
- name: Upload Test Results
2828
if: always()
29-
uses: actions/upload-artifact@v2
29+
uses: actions/upload-artifact@v4
3030
with:
3131
name: Unit Test Results
3232
path: ./TestResults/Pester.xml

ClassExplorer.build.ps1

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ param(
1010
[switch] $Force
1111
)
1212

13-
$moduleName = 'ClassExplorer'
14-
$testModuleManifestSplat = @{
15-
ErrorAction = 'Ignore'
16-
WarningAction = 'Ignore'
17-
Path = "$PSScriptRoot\module\$moduleName.psd1"
18-
}
19-
20-
$manifest = Test-ModuleManifest @testModuleManifestSplat
21-
$moduleVersion = $manifest.Version
22-
2313
$tools = "$PSScriptRoot\tools"
2414
$script:GetDotNet = Get-Command $tools\GetDotNet.ps1
2515
$script:AssertModule = Get-Command $tools\AssertRequiredModule.ps1
@@ -61,6 +51,8 @@ function GetArtifactPath {
6151
$target = $legacyTarget
6252
}
6353

54+
# dotnet always uses lower case for the path now for some reason
55+
$config = $config.ToLowerInvariant()
6456
if (-not $FileName) {
6557
return "./artifacts/publish/$moduleName/${config}_${target}"
6658
}
@@ -93,6 +85,7 @@ task GetProjectInfo {
9385

9486
$manifest = Test-ModuleManifest @testModuleManifestSplat
9587
$script:ModuleVersion = $manifest.Version
88+
$script:ReleasePath = "./Release/$script:ModuleName/$script:ModuleVersion"
9689
$script:_IsWindows = $true
9790
$runtimeInfoType = 'System.Runtime.InteropServices.RuntimeInformation' -as [type]
9891
try {
@@ -106,7 +99,7 @@ task AssertDotNet {
10699
$script:dotnet = & $GetDotNet -Unix:(-not $script:_IsWindows)
107100
}
108101

109-
task AssertOpenCover -If { $GenerateCodeCoverage.IsPresent } {
102+
task AssertOpenCover -If { $false } {
110103
if (-not $script:_IsWindows) {
111104
Write-Warning 'Generating code coverage from .NET core is currently unsupported, disabling code coverage generation.'
112105
$script:GenerateCodeCoverage = $false
@@ -132,7 +125,7 @@ task Clean {
132125
}
133126

134127
task BuildDocs -If { Test-Path ./docs/$PSCulture/*.md } {
135-
$releaseDocs = "./Release/ClassExplorer/$moduleVersion"
128+
$releaseDocs = $script:ReleasePath
136129
$null = New-Item $releaseDocs/$PSCulture -ItemType Directory -Force -ErrorAction Ignore
137130
$null = New-ExternalHelp -Path ./docs/$PSCulture -OutputPath $releaseDocs/$PSCulture
138131

@@ -149,19 +142,15 @@ task BuildDll {
149142
}
150143

151144
task CopyToRelease {
152-
$version = $script:ModuleVersion
153-
$modern = $script:ModernTarget
154-
$legacy = $script:LegacyTarget
155-
156-
$releasePath = "./Release/ClassExplorer/$version"
157-
if (-not (Test-Path -LiteralPath $releasePath)) {
158-
$null = New-Item $releasePath -ItemType Directory
145+
$release = $script:ReleasePath
146+
if (-not (Test-Path -LiteralPath $release)) {
147+
$null = New-Item $release -ItemType Directory
159148
}
160149

161-
Copy-Item -Path ./module/* -Destination $releasePath -Recurse -Force
150+
Copy-Item -Path ./module/* -Destination $release -Recurse -Force
162151

163152
if ($script:_IsWindows) {
164-
$null = New-Item $releasePath/bin/Legacy -Force -ItemType Directory
153+
$null = New-Item $release/bin/Legacy -Force -ItemType Directory
165154
$legacyFiles = (
166155
'ClassExplorer.dll',
167156
'ClassExplorer.pdb',
@@ -172,33 +161,42 @@ task CopyToRelease {
172161
'System.Runtime.CompilerServices.Unsafe.dll')
173162

174163
foreach ($file in $legacyFiles) {
175-
Copy-Item -Force -LiteralPath ./artifacts/publish/ClassExplorer/${Configuration}_$legacy/$file -Destination $releasePath/bin/Legacy
164+
Copy-Item -Force -LiteralPath (GetArtifactPath -FileName $file -Legacy) -Destination $release/bin/Legacy
176165
}
177166
}
178167

179-
$null = New-Item $releasePath/bin/Modern -Force -ItemType Directory
168+
$null = New-Item $release/bin/Modern -Force -ItemType Directory
180169
$modernFiles = (
181170
'ClassExplorer.dll',
182171
'ClassExplorer.pdb',
183172
'ClassExplorer.deps.json')
184173
foreach ($file in $modernFiles) {
185-
Copy-Item -Force -LiteralPath ./artifacts/publish/ClassExplorer/${Configuration}_$modern/$file -Destination $releasePath/bin/Modern
174+
Copy-Item -Force -LiteralPath (GetArtifactPath -FileName $file) -Destination $release/bin/Modern
186175
}
187176
}
188177

189178
task DoTest -If { Test-Path ./test/*.ps1 } {
190-
if (-not $script:_IsWindows) {
191-
$scriptString = '
192-
$projectPath = "{0}"
193-
Invoke-Pester "$projectPath" -OutputFormat NUnitXml -OutputFile "$projectPath\testresults\pester.xml"
194-
' -f $PSScriptRoot
195-
} else {
196-
$scriptString = '
197-
Set-ExecutionPolicy Bypass -Force -Scope Process
198-
$projectPath = "{0}"
199-
Invoke-Pester "$projectPath" -OutputFormat NUnitXml -OutputFile "$projectPath\testresults\pester.xml"
200-
' -f $PSScriptRoot
201-
}
179+
180+
$scriptString = @(
181+
if (-not $script:_IsWindows) {
182+
'Set-ExecutionPolicy Bypass -Force -Scope Process'
183+
''
184+
}
185+
186+
'$projectPath = ''{0}''' -f $PSScriptRoot
187+
'$config = New-PesterConfiguration @{'
188+
' Run = @{'
189+
' Path = $projectPath'
190+
' }'
191+
' TestResult = @{'
192+
' Enable = $true'
193+
' OutputFormat = ''NUnitXml'''
194+
' OutputPath = "$projectPath\testresults.pester.xml"'
195+
' }'
196+
'}'
197+
''
198+
'Invoke-Pester -Configuration $config'
199+
) -join [Environment]::NewLine
202200

203201
$encodedCommand =
204202
[convert]::ToBase64String(
@@ -210,19 +208,22 @@ task DoTest -If { Test-Path ./test/*.ps1 } {
210208
$powershellCommand = 'pwsh'
211209
}
212210

213-
$powershell = (Get-Command -CommandType Application $powershellCommand).Source
211+
$powershell = Get-Command -CommandType Application $powershellCommand |
212+
Select-Object -First 1 -ExpandProperty Source
214213

214+
# Can't be bothered atm, gotta modernize this at some point.
215+
$GenerateCodeCoverage = $false
215216
if ($GenerateCodeCoverage.IsPresent) {
216217
# OpenCover needs full pdb's. I'm very open to suggestions for streamlining this...
217218
# & $dotnet clean
218219
& $dotnet publish --configuration $Configuration --framework $script:LegacyTarget --verbosity quiet --nologo /p:DebugType=Full
219220

220221
$moduleName = $Settings.Name
221-
$release = '{0}\bin\Desktop\{1}' -f $Folders.Release, $moduleName
222-
$coverage = '{0}\net471\{1}' -f $Folders.Build, $moduleName
222+
$release = "$script:ReleasePath/bin/Legacy/$script:ModuleName"
223+
$coverage = GetArtifactPath -Legacy $script:ModuleName
223224

224-
Rename-Item "$release.pdb" -NewName "$moduleName.pdb.tmp"
225-
Rename-Item "$release.dll" -NewName "$moduleName.dll.tmp"
225+
Rename-Item "$release.pdb" -NewName "$script:ModuleName.pdb.tmp"
226+
Rename-Item "$release.dll" -NewName "$script:ModuleName.dll.tmp"
226227
Copy-Item "$coverage.pdb" "$release.pdb"
227228
Copy-Item "$coverage.dll" "$release.dll"
228229

@@ -236,8 +237,8 @@ task DoTest -If { Test-Path ./test/*.ps1 } {
236237

237238
Remove-Item "$release.pdb"
238239
Remove-Item "$release.dll"
239-
Rename-Item "$release.pdb.tmp" -NewName "$moduleName.pdb"
240-
Rename-Item "$release.dll.tmp" -NewName "$moduleName.dll"
240+
Rename-Item "$release.pdb.tmp" -NewName "$script:ModuleName.pdb"
241+
Rename-Item "$release.dll.tmp" -NewName "$script:ModuleName.dll"
241242
} else {
242243
& $powershell -NoProfile -EncodedCommand $encodedCommand
243244
}

docs/en-US/ClassExplorer.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,33 @@ Type signatures are a custom query language built into PowerShell type expressio
2222

2323
### [Find-Member](Find-Member.md)
2424

25-
The Find-Member cmdlet searches the AppDomain for members that fit specified criteria. You can search the entire AppDomain, search in specific types, or filter an existing list of members.
25+
The `Find-Member` cmdlet searches the AppDomain for members that fit specified criteria. You can search the entire AppDomain, search in specific types, or filter an existing list of members.
2626

2727
### [Find-Type](Find-Type.md)
2828

29-
The Find-Type cmdlet searches the AppDomain for .NET classes that match specified criteria.
29+
The `Find-Type` cmdlet searches the AppDomain for .NET classes that match specified criteria.
3030

3131
### [Get-Assembly](Get-Assembly.md)
3232

33-
The Get-Assembly cmdlet gets assemblies loaded in the AppDomain.
33+
The `Get-Assembly` cmdlet gets assemblies loaded in the AppDomain.
3434

3535
### [Get-Parameter](Get-Parameter.md)
3636

37-
The Get-Parameter cmdlet gets parameter info from a member.
37+
The `Get-Parameter` cmdlet gets parameter info from a member.
3838

3939
### [Format-MemberSignature](Format-MemberSignature.md)
4040

41-
The Format-MemberSignature cmdlet uses the input reflection objects to generate reference library style C# pseudo code. Use this cmdlet to get a more in depth look at specific member including attribute decorations, generic type constraints, and more.
41+
The `Format-MemberSignature` cmdlet uses the input reflection objects to generate reference library style C# pseudo code. Use this cmdlet to get a more in depth look at specific member including attribute decorations, generic type constraints, and more.
42+
43+
### [Invoke-Member](Invoke-Member.md)
44+
45+
The `Invoke-Member` cmdlet takes a reflection info (`System.Reflection.MemberInfo`) object and
46+
facilitates seamless invocation in a pipeline. `Invoke-Member` will handle any necessary
47+
conversions, unwrapping of psobjects, and streamlined `ref` handling for interactive use.
48+
49+
### [Get-AssemblyLoadContext](Get-AssemblyLoadContext.md)
50+
51+
The `Get-AssemblyLoadContext` cmdlet gets all currently active assembly load
52+
contexts (ALCs), or the relevant ALCs if any parameters are specified.
53+
54+
This command is only supported in PowerShell 7+

docs/en-US/Find-Member.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,3 +677,5 @@ Matched MemberInfo objects will be returned to the pipeline.
677677
[Get-Assembly](Get-Assembly.md)
678678
[Get-Parameter](Get-Parameter.md)
679679
[Format-MemberSignature](Format-MemberSignature.md)
680+
[Invoke-Member](Invoke-Member.md)
681+
[Get-AssemblyLoadContext](Get-AssemblyLoadContext.md)

docs/en-US/Find-Type.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,5 @@ Matched Type objected will be returned to the pipeline.
447447
[Get-Assembly](Get-Assembly.md)
448448
[Get-Parameter](Get-Parameter.md)
449449
[Format-MemberSignature](Format-MemberSignature.md)
450+
[Invoke-Member](Invoke-Member.md)
451+
[Get-AssemblyLoadContext](Get-AssemblyLoadContext.md)

docs/en-US/Format-MemberSignature.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,5 @@ The formatted display string will be returned to the pipeline.
212212
[Find-Member](Find-Member.md)
213213
[Get-Assembly](Get-Assembly.md)
214214
[Get-Parameter](Get-Parameter.md)
215+
[Invoke-Member](Invoke-Member.md)
216+
[Get-AssemblyLoadContext](Get-AssemblyLoadContext.md)

docs/en-US/Get-Assembly.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,5 @@ Matched Assembly objects will be returned to the pipeline.
8585
[Find-Member](Find-Member.md)
8686
[Get-Parameter](Get-Parameter.md)
8787
[Format-MemberSignature](Format-MemberSignature.md)
88+
[Invoke-Member](Invoke-Member.md)
89+
[Get-AssemblyLoadContext](Get-AssemblyLoadContext.md)

0 commit comments

Comments
 (0)