Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

src/ClassExplorer/Generated/

# Project specific files
tools/dotnet
tools/opencover
Expand Down
199 changes: 132 additions & 67 deletions ClassExplorer.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,96 @@ $testModuleManifestSplat = @{
}

$manifest = Test-ModuleManifest @testModuleManifestSplat

$script:Settings = @{
Name = $moduleName
Manifest = $manifest
Version = $manifest.Version
ShouldTest = $true
}

$script:Folders = @{
PowerShell = "$PSScriptRoot\module"
CSharp = "$PSScriptRoot\src"
Build = '{0}\src\{1}\bin\{2}' -f $PSScriptRoot, $moduleName, $Configuration
Release = '{0}\Release\{1}\{2}' -f $PSScriptRoot, $moduleName, $manifest.Version
Docs = "$PSScriptRoot\docs"
Test = "$PSScriptRoot\test"
Results = "$PSScriptRoot\testresults"
}

$script:Discovery = @{
HasDocs = Test-Path ('{0}\{1}\*.md' -f $Folders.Docs, $PSCulture)
HasTests = Test-Path ('{0}\*.Tests.ps1' -f $Folders.Test)
IsUnix = $PSVersionTable.PSEdition -eq "Core" -and -not $IsWindows
}
$moduleVersion = $manifest.Version

$tools = "$PSScriptRoot\tools"
$script:GetDotNet = Get-Command $tools\GetDotNet.ps1
$script:AssertModule = Get-Command $tools\AssertRequiredModule.ps1
$script:GetOpenCover = Get-Command $tools\GetOpenCover.ps1
$script:GenerateSignatureMarkdown = Get-Command $tools\GenerateSignatureMarkdown.ps1

function RemakeFolder {
[CmdletBinding()]
param(
[ValidateNotNullOrEmpty()]
[string] $LiteralPath
)
end {
$ErrorActionPreference = 'Stop'
if (Test-Path -LiteralPath $LiteralPath) {
Remove-Item -LiteralPath $LiteralPath -Recurse
}

$null = New-Item -ItemType Directory -Path $LiteralPath
}
}

function GetArtifactPath {
[CmdletBinding()]
param(
[ValidateNotNullOrEmpty()]
[string] $FileName,

[switch] $Legacy
)
end {
$moduleName = $script:ModuleName
$config = $script:Configuration
$legacyTarget = $script:LegacyTarget
$modernTarget = $script:ModernTarget

$target = $modernTarget
if ($Legacy) {
$target = $legacyTarget
}

if (-not $FileName) {
return "./artifacts/publish/$moduleName/${config}_${target}"
}

return "./artifacts/publish/$moduleName/${config}_${target}/$FileName"
}
}

task GetProjectInfo {
$script:ModernTarget = $null
$script:LegacyTarget = $null
if (Test-Path -LiteralPath ./Directory.Build.props) {
$content = Get-Content -Raw -LiteralPath ./Directory.Build.props
if ($content -match '<ModernTarget>(?<target>[^<]+)</ModernTarget>') {
$script:ModernTarget = $matches['target']
}

if ($content -match '<LegacyTarget>(?<target>[^<]+)</LegacyTarget>') {
$script:LegacyTarget = $matches['target']
}
}


$script:ModuleName = $ModuleName = 'ClassExplorer'
$testModuleManifestSplat = @{
ErrorAction = 'Ignore'
WarningAction = 'Ignore'
Path = "./module/$ModuleName.psd1"
}

$manifest = Test-ModuleManifest @testModuleManifestSplat
$script:ModuleVersion = $manifest.Version
$script:_IsWindows = $true
$runtimeInfoType = 'System.Runtime.InteropServices.RuntimeInformation' -as [type]
try {
if ($null -ne $runtimeInfoType) {
$script:_IsWindows = $runtimeInfoType::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)
}
} catch { }
}

task AssertDotNet {
$script:dotnet = & $GetDotNet -Unix:$Discovery.IsUnix
$script:dotnet = & $GetDotNet -Unix:(-not $script:_IsWindows)
}

task AssertOpenCover -If { $GenerateCodeCoverage.IsPresent } {
if ($Discovery.IsUnix) {
if (-not $script:_IsWindows) {
Write-Warning 'Generating code coverage from .NET core is currently unsupported, disabling code coverage generation.'
$script:GenerateCodeCoverage = $false
return
Expand All @@ -63,66 +117,77 @@ task AssertOpenCover -If { $GenerateCodeCoverage.IsPresent } {
}

task AssertRequiredModules {
& $AssertModule Pester 5.3.0 -Force:$Force.IsPresent
& $AssertModule InvokeBuild 5.8.4 -Force:$Force.IsPresent
& $AssertModule Pester 5.7.1 -Force:$Force.IsPresent
& $AssertModule InvokeBuild 5.14.22 -Force:$Force.IsPresent
& $AssertModule platyPS 0.14.2 -Force:$Force.IsPresent
& $AssertModule Yayaml 0.1.1 -Force:$Force.IsPresent
& $AssertModule Yayaml 0.7.0 -Force:$Force.IsPresent
}

task AssertDevDependencies -Jobs AssertDotNet, AssertOpenCover, AssertRequiredModules

task Clean {
if ($PSScriptRoot -and (Test-Path $PSScriptRoot\Release)) {
Remove-Item $PSScriptRoot\Release -Recurse
}

$null = New-Item $Folders.Release -ItemType Directory
if (Test-Path $Folders.Results) {
Remove-Item $Folders.Results -Recurse
}

$null = New-Item $Folders.Results -ItemType Directory
RemakeFolder ./Release
RemakeFolder ./testresults
& $dotnet clean --verbosity quiet -nologo
}

task BuildDocs -If { $Discovery.HasDocs } {
$sourceDocs = "$PSScriptRoot\docs\$PSCulture"
$releaseDocs = '{0}\{1}' -f $Folders.Release, $PSCulture
task BuildDocs -If { Test-Path ./docs/$PSCulture/*.md } {
$releaseDocs = "./Release/ClassExplorer/$moduleVersion"
$null = New-Item $releaseDocs/$PSCulture -ItemType Directory -Force -ErrorAction Ignore
$null = New-ExternalHelp -Path ./docs/$PSCulture -OutputPath $releaseDocs/$PSCulture

$null = New-Item $releaseDocs -ItemType Directory -Force -ErrorAction SilentlyContinue
$null = New-ExternalHelp -Path $sourceDocs -OutputPath $releaseDocs

& $GenerateSignatureMarkdown.Source -AboutHelp $releaseDocs\about_Type_Signatures.help.txt
& $GenerateSignatureMarkdown.Source $PSScriptRoot\docs\en-US\about_Type_Signatures.help.md
& $GenerateSignatureMarkdown.Source -AboutHelp $releaseDocs/about_Type_Signatures.help.txt
& $GenerateSignatureMarkdown.Source ./docs/en-US/about_Type_Signatures.help.md
}

task BuildDll {
if (-not $Discovery.IsUnix) {
& $dotnet publish --configuration $Configuration --framework net471 --verbosity quiet -nologo
if ($script:_IsWindows) {
& $dotnet publish --configuration $Configuration --framework $script:LegacyTarget --verbosity quiet -nologo
}
& $dotnet publish --configuration $Configuration --framework netcoreapp3.1 --verbosity quiet -nologo

& $dotnet publish --configuration $Configuration --framework $script:ModernTarget --verbosity quiet -nologo
}

task CopyToRelease {
$powershellSource = '{0}\*' -f $Folders.PowerShell
$release = $Folders.Release
$releaseDesktopBin = "$release\bin\Desktop"
$releaseCoreBin = "$release\bin\Core"
$sourceDesktopBin = '{0}\net471\publish\*' -f $Folders.Build
$sourceCoreBin = '{0}\netcoreapp3.1\publish\*' -f $Folders.Build
Copy-Item -Path $powershellSource -Destination $release -Recurse -Force
$version = $script:ModuleVersion
$modern = $script:ModernTarget
$legacy = $script:LegacyTarget

if (-not $Discovery.IsUnix) {
$null = New-Item $releaseDesktopBin -Force -ItemType Directory
Copy-Item -Path $sourceDesktopBin -Destination $releaseDesktopBin -Force
$releasePath = "./Release/ClassExplorer/$version"
if (-not (Test-Path -LiteralPath $releasePath)) {
$null = New-Item $releasePath -ItemType Directory
}

$null = New-Item $releaseCoreBin -Force -ItemType Directory
Copy-Item -Path $sourceCoreBin -Destination $releaseCoreBin -Force
Copy-Item -Path ./module/* -Destination $releasePath -Recurse -Force

if ($script:_IsWindows) {
$null = New-Item $releasePath/bin/Legacy -Force -ItemType Directory
$legacyFiles = (
'ClassExplorer.dll',
'ClassExplorer.pdb',
'System.Buffers.dll',
'System.Collections.Immutable.dll',
'System.Memory.dll',
'System.Numerics.Vectors.dll',
'System.Runtime.CompilerServices.Unsafe.dll')

foreach ($file in $legacyFiles) {
Copy-Item -Force -LiteralPath ./artifacts/publish/ClassExplorer/${Configuration}_$legacy/$file -Destination $releasePath/bin/Legacy
}
}

$null = New-Item $releasePath/bin/Modern -Force -ItemType Directory
$modernFiles = (
'ClassExplorer.dll',
'ClassExplorer.pdb',
'ClassExplorer.deps.json')
foreach ($file in $modernFiles) {
Copy-Item -Force -LiteralPath ./artifacts/publish/ClassExplorer/${Configuration}_$modern/$file -Destination $releasePath/bin/Modern
}
}

task DoTest -If { $Discovery.HasTests -and $Settings.ShouldTest } {
if ($Discovery.IsUnix) {
task DoTest -If { Test-Path ./test/*.ps1 } {
if (-not $script:_IsWindows) {
$scriptString = '
$projectPath = "{0}"
Invoke-Pester "$projectPath" -OutputFormat NUnitXml -OutputFile "$projectPath\testresults\pester.xml"
Expand All @@ -141,16 +206,16 @@ task DoTest -If { $Discovery.HasTests -and $Settings.ShouldTest } {
$scriptString))

$powershellCommand = 'powershell'
if ($Discovery.IsUnix) {
if ($PSVersionTable.PSVersion.Major -gt 5) {
$powershellCommand = 'pwsh'
}

$powershell = (Get-Command $powershellCommand).Source
$powershell = (Get-Command -CommandType Application $powershellCommand).Source

if ($GenerateCodeCoverage.IsPresent) {
# OpenCover needs full pdb's. I'm very open to suggestions for streamlining this...
# & $dotnet clean
& $dotnet publish --configuration $Configuration --framework net471 --verbosity quiet -nologo /p:DebugType=Full
& $dotnet publish --configuration $Configuration --framework $script:LegacyTarget --verbosity quiet --nologo /p:DebugType=Full

$moduleName = $Settings.Name
$release = '{0}\bin\Desktop\{1}' -f $Folders.Release, $moduleName
Expand Down Expand Up @@ -212,7 +277,7 @@ task DoPublish {
Publish-Module -Name $Folders.Release -NuGetApiKey $apiKey -Force:$Force.IsPresent
}

task Build -Jobs AssertDevDependencies, Clean, BuildDll, CopyToRelease, BuildDocs
task Build -Jobs GetProjectInfo, AssertDevDependencies, Clean, BuildDll, CopyToRelease, BuildDocs

task Test -Jobs Build, DoTest

Expand Down
10 changes: 10 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
<PropertyGroup>

<ModernTarget>net8.0</ModernTarget>
<LegacyTarget>net471</LegacyTarget>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>

</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions module/ClassExplorer.psm1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if (-not $PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq 'Desktop') {
Import-Module "$PSScriptRoot/bin/Desktop/ClassExplorer.dll"
Import-Module "$PSScriptRoot/bin/Legacy/ClassExplorer.dll"
} else {
Import-Module "$PSScriptRoot/bin/Core/ClassExplorer.dll"
Import-Module "$PSScriptRoot/bin/Modern/ClassExplorer.dll"
}

if (-not $env:CLASS_EXPLORER_TRUE_CHARACTER) {
Expand Down
43 changes: 27 additions & 16 deletions src/ClassExplorer/ClassExplorer.csproj
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net471</TargetFrameworks>
<!-- <TargetFrameworks>net471;netcoreapp3.1</TargetFrameworks> -->
<TargetFrameworks>$(ModernTarget);$(LegacyTarget)</TargetFrameworks>
<!-- <TargetFrameworks>$(LegacyTarget);$(ModernTarget)</TargetFrameworks> -->
<LangVersion>preview</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<!-- <AssemblyName>ClassExplorer2</AssemblyName> -->
<ResXGenerator_NullForgivingOperators>true</ResXGenerator_NullForgivingOperators>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aigamo.ResXGenerator" Version="4.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="PolySharp" Version="1.15.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" PrivateAssets="all" />
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net471' ">
<ItemGroup Condition=" '$(TargetFramework)' == '$(LegacyTarget)' ">
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<ItemGroup>
<!--
omnisharp-vscode doesn't seem to pick this up without this.
For now we'll ignore the compiler warning
-->
<Compile Include="$(IntermediateOutputPath)\SR.Designer.cs" />
<EmbeddedResource Update="SR.resx">
<Generator>ResXFileCodeGenerator</Generator>
<StronglyTypedFileName>$(IntermediateOutputPath)\SR.Designer.cs</StronglyTypedFileName>
<LastGenOutput>SR.Designer.cs</LastGenOutput>
<PartialClass>true</PartialClass>
<GenerateCode>true</GenerateCode>
<GenerateResource>false</GenerateResource>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>ClassExplorer</StronglyTypedNamespace>
<StronglyTypedClassName>SR</StronglyTypedClassName>
</EmbeddedResource>
</ItemGroup>

<Target Name="FixResGen" BeforeTargets="AfterResGen">
<Exec ConsoleToMsBuild="true" Command="pwsh -NoLogo -NoProfile -NonInteractive -Command &quot;Set-Content '$(IntermediateOutputPath)\SR.Designer.cs' ((Get-Content '$(IntermediateOutputPath)\SR.Designer.cs' -Raw) -replace '(?m)^(\s*internal )class', '$1partial class')&quot;" />
</Target>
<PropertyGroup>
<!-- Create files for source generated code -->
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<!-- Exclude the output of source generators from the compilation -->
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions src/ClassExplorer/IsExternalInit.cs

This file was deleted.

Loading
Loading