66 [string []]$ModuleName = @ (" Microsoft.PowerShell.ConsoleGuiTools" )
77)
88
9- $script :IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq " Core" -and ! $IsWindows
10-
119$script :TargetFramework = " net6.0"
12- $script :RequiredSdkVersion = (Get-Content (Join-Path $PSScriptRoot ' global.json' ) | ConvertFrom-Json ).sdk.version
1310
1411$script :ModuleLayouts = @ {}
1512foreach ($mn in $ModuleName ) {
1613 $script :ModuleLayouts .$mn = Import-PowerShellDataFile - Path " $PSScriptRoot /src/$mn /ModuleLayout.psd1"
1714}
1815
19- task SetupDotNet - Before Clean , Build {
20-
21- $dotnetPath = " $PSScriptRoot /.dotnet"
22- $dotnetExePath = if ($script :IsUnix ) { " $dotnetPath /dotnet" } else { " $dotnetPath /dotnet.exe" }
23- $originalDotNetExePath = $dotnetExePath
24-
25- if (! (Test-Path $dotnetExePath )) {
26- $installedDotnet = Get-Command dotnet - ErrorAction Ignore
27- if ($installedDotnet ) {
28- $dotnetExePath = $installedDotnet.Source
29- }
30- else {
31- $dotnetExePath = $null
32- }
33- }
34-
35- # Make sure the dotnet we found is the right version
36- if ($dotnetExePath ) {
37- # dotnet --version can write to stderr, which causes builds to abort, therefore use --list-sdks instead.
38- if ((& $dotnetExePath -- list- sdks | ForEach-Object { $_.Split ()[0 ] } ) -contains $script :RequiredSdkVersion ) {
39- $script :dotnetExe = $dotnetExePath
40- }
41- else {
42- # Clear the path so that we invoke installation
43- $script :dotnetExe = $null
44- }
45- }
46- else {
47- # Clear the path so that we invoke installation
48- $script :dotnetExe = $null
49- }
50-
51- if ($script :dotnetExe -eq $null ) {
52-
53- Write-Host " `n ### Installing .NET CLI $script :RequiredSdkVersion ...`n " - ForegroundColor Green
16+ task FindDotNet - Before Clean , Build {
17+ Assert (Get-Command dotnet - ErrorAction SilentlyContinue) " dotnet not found, please install it: https://aka.ms/dotnet-cli"
5418
55- # The install script is platform-specific
56- $installScriptExt = if ($script :IsUnix ) { " sh" } else { " ps1" }
19+ # Strip out semantic version metadata so it can be cast to `Version`
20+ [Version ]$existingVersion , $null = (dotnet -- version) -split " " -split " -"
21+ Assert ($existingVersion -ge [Version ](" 6.0" )) " .NET SDK 6.0 or higher is required, please update it: https://aka.ms/dotnet-cli"
5722
58- # Download the official installation script and run it
59- $installScriptPath = " $ ( [System.IO.Path ]::GetTempPath()) dotnet-install.$installScriptExt "
60- Invoke-WebRequest " https://dot.net/v1/dotnet-install.$installScriptExt " - OutFile $installScriptPath
61- $env: DOTNET_INSTALL_DIR = " $PSScriptRoot /.dotnet"
62-
63- if (! $script :IsUnix ) {
64- & $installScriptPath - Version $script :RequiredSdkVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
65- }
66- else {
67- & / bin/ bash $installScriptPath - Version $script :RequiredSdkVersion - InstallDir " $env: DOTNET_INSTALL_DIR "
68- $env: PATH = $dotnetExeDir + [System.IO.Path ]::PathSeparator + $env: PATH
69- }
70-
71- Write-Host " `n ### Installation complete." - ForegroundColor Green
72- $script :dotnetExe = $originalDotnetExePath
73- }
74-
75- # This variable is used internally by 'dotnet' to know where it's installed
76- $script :dotnetExe = Resolve-Path $script :dotnetExe
77- if (! $env: DOTNET_INSTALL_DIR ) {
78- $dotnetExeDir = [System.IO.Path ]::GetDirectoryName($script :dotnetExe )
79- $env: PATH = $dotnetExeDir + [System.IO.Path ]::PathSeparator + $env: PATH
80- $env: DOTNET_INSTALL_DIR = $dotnetExeDir
81- }
82-
83- Write-Host " `n ### Using dotnet v$ ( & $script :dotnetExe -- version) at path $script :dotnetExe `n " - ForegroundColor Green
23+ Write-Host " Using dotnet v$ ( dotnet -- version) at path $ ( (Get-Command dotnet).Source) " - ForegroundColor Green
8424}
8525
8626task Build {
8727 Remove-Item $PSScriptRoot / module - Recurse - Force - ErrorAction Ignore
8828
8929 foreach ($moduleLayout in $script :ModuleLayouts.Values ) {
9030 foreach ($projName in $moduleLayout.RequiredBuildAssets.Keys ) {
91- exec { & $ script :dotnetExe publish - c $Configuration " $PSScriptRoot /src/$projName /$projName .csproj" }
31+ exec { & dotnet publish - c $Configuration " $PSScriptRoot /src/$projName /$projName .csproj" }
9232 }
9333
9434 foreach ($nativeProj in $moduleLayout.NativeBuildAssets.Keys ) {
@@ -99,29 +39,24 @@ task Build {
9939 else {
10040 " /property:IsWindows=false"
10141 }
102- exec { & $ script :dotnetExe publish - c $Configuration " $PSScriptRoot /src/$nativeProj /$nativeProj .csproj" - r $targetPlatform $buildPropertyParams }
42+ exec { & dotnet publish - c $Configuration " $PSScriptRoot /src/$nativeProj /$nativeProj .csproj" - r $targetPlatform $buildPropertyParams }
10343 }
10444 }
10545 }
10646}
10747
10848task Clean {
109- # Remove Module Build
110- Remove-Item $PSScriptRoot / module - Recurse - Force - ErrorAction Ignore
49+ Remove-BuildItem $PSScriptRoot / module
11150
11251 foreach ($moduleLayout in $script :ModuleLayouts.Values ) {
11352 foreach ($projName in $moduleLayout.RequiredBuildAssets.Keys ) {
114- exec { & $ script :dotnetExe clean - c $Configuration " $PSScriptRoot /src/$projName /$projName .csproj" }
53+ exec { & dotnet clean - c $Configuration " $PSScriptRoot /src/$projName /$projName .csproj" }
11554 }
11655
11756 foreach ($projName in $moduleLayout.NativeBuildAssets.Keys ) {
118- exec { & $ script :dotnetExe clean - c $Configuration " $PSScriptRoot /src/$projName /$projName .csproj" }
57+ exec { & dotnet clean - c $Configuration " $PSScriptRoot /src/$projName /$projName .csproj" }
11958 }
12059 }
121-
122- foreach ($mn in $ModuleName ) {
123- Get-ChildItem " $PSScriptRoot \module\$mn \Commands\en-US\*-help.xml" - ErrorAction Ignore | Remove-Item - Force
124- }
12560}
12661
12762task LayoutModule - After Build {
@@ -132,7 +67,7 @@ task LayoutModule -After Build {
13267 # Create the destination dir
13368 $null = New-Item - Force $moduleBinPath - Type Directory
13469
135- # For each PSES subproject
70+ # For each subproject
13671 foreach ($projectName in $moduleLayout.RequiredBuildAssets.Keys ) {
13772 # Get the project build dir path
13873 $basePath = [System.IO.Path ]::Combine($PSScriptRoot , ' src' , $projectName , ' bin' , $Configuration , $script :TargetFramework )
0 commit comments