Skip to content

Commit f893082

Browse files
committed
dotnettool: translate layout+pack scripts to pwsh
Translate the layout.sh and pack.sh Bash scripts to PowerShell scripts. We are now building the .NET tool NuGet packages on Windows. Signed-off-by: Matthew John Cheetham <[email protected]>
1 parent defa690 commit f893082

File tree

6 files changed

+188
-139
lines changed

6 files changed

+188
-139
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ jobs:
401401
run: |
402402
src/shared/DotnetTool/pack.sh --configuration=Release \
403403
--version="${{ needs.prereqs.outputs.version }}" \
404-
--publish-dir=$(pwd)/signed
404+
--package-root=$(pwd)/signed
405405
406406
- name: Upload unsigned package
407407
uses: actions/upload-artifact@v5

src/shared/DotnetTool/dotnet-tool.nuspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
<description>Secure, cross-platform Git credential storage with authentication to Azure Repos, GitHub, and other popular Git hosting services.</description>
77
<authors>git-credential-manager</authors>
88
<icon>images\icon.png</icon>
9-
<iconUrl>https://raw.githubusercontent.com/git-ecosystem/git-credential-manager/main/assets/gcm-transparent.png</iconUrl>
109
<packageTypes>
1110
<packageType name="DotnetTool" />
1211
</packageTypes>
1312
</metadata>
1413
<files>
15-
<file src="$publishdir$payload/" target="tools/net8.0/any" />
16-
<file src="$publishdir$images/icon.png" target="images" />
14+
<file src="tools/net8.0/any/**" />
15+
<file src="images/**" />
1716
</files>
1817
</package>

src/shared/DotnetTool/layout.ps1

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<#
2+
.SYNOPSIS
3+
Lays out the .NET tool package directory.
4+
5+
.PARAMETER Configuration
6+
Build configuration (Debug/Release). Defaults to Debug.
7+
8+
.PARAMETER Output
9+
Root output directory for the nupkg layout. If omitted:
10+
out/shared/DotnetTool/nupkg/<Configuration>
11+
12+
.EXAMPLE
13+
pwsh ./layout.ps1 -Configuration Release
14+
15+
.EXAMPLE
16+
pwsh ./layout.ps1 -Output C:\temp\tool-layout
17+
18+
#>
19+
20+
[CmdletBinding()]
21+
param(
22+
[string]$Configuration = "Debug",
23+
[string]$Output
24+
)
25+
26+
Set-StrictMode -Version Latest
27+
$ErrorActionPreference = 'Stop'
28+
29+
function Make-Absolute {
30+
param([string]$Path)
31+
if ([string]::IsNullOrWhiteSpace($Path)) { return $null }
32+
if ([System.IO.Path]::IsPathRooted($Path)) { return $Path }
33+
return (Join-Path -Path (Get-Location) -ChildPath $Path)
34+
}
35+
36+
Write-Host "Starting layout..." -ForegroundColor Cyan
37+
38+
# Directories
39+
$ScriptDir = $PSScriptRoot
40+
$Root = (Resolve-Path (Join-Path $ScriptDir "..\..\..")).Path
41+
$Src = Join-Path $Root "src"
42+
$Out = Join-Path $Root "out"
43+
$DotnetToolRel = "shared/DotnetTool"
44+
$GcmSrc = Join-Path $Src "shared\Git-Credential-Manager"
45+
$ProjOut = Join-Path $Out $DotnetToolRel
46+
47+
$Framework = "net8.0"
48+
49+
if (-not $Output -or $Output.Trim() -eq "") {
50+
$Output = Join-Path $ProjOut "nupkg\$Configuration"
51+
}
52+
53+
$ImgOut = Join-Path $Output "images"
54+
$BinOut = Join-Path $Output "tools\$Framework\any"
55+
56+
# Cleanup previous layout
57+
if (Test-Path $Output) {
58+
Write-Host "Cleaning existing output directory '$Output'..."
59+
Remove-Item -Force -Recurse $Output
60+
}
61+
62+
# Recreate directories
63+
$null = New-Item -ItemType Directory -Path $BinOut -Force
64+
$null = New-Item -ItemType Directory -Path $ImgOut -Force
65+
66+
# Determine DOTNET_ROOT if not set
67+
if (-not $env:DOTNET_ROOT -or $env:DOTNET_ROOT.Trim() -eq "") {
68+
$dotnetCmd = Get-Command dotnet -ErrorAction Stop
69+
$env:DOTNET_ROOT = Split-Path -Parent $dotnetCmd.Source
70+
}
71+
72+
Write-Host "Publishing core application..."
73+
& "$env:DOTNET_ROOT/dotnet" publish $GcmSrc `
74+
--configuration $Configuration `
75+
--framework $Framework `
76+
--output (Make-Absolute $BinOut) `
77+
-p:UseAppHost=false
78+
79+
if ($LASTEXITCODE -ne 0) {
80+
Write-Error "dotnet publish failed with exit code $LASTEXITCODE"
81+
exit $LASTEXITCODE
82+
}
83+
84+
Write-Host "Copying package configuration file..."
85+
Copy-Item -Path (Join-Path $Src "$DotnetToolRel\DotnetToolSettings.xml") -Destination $BinOut -Force
86+
87+
Write-Host "Copying images..."
88+
Copy-Item -Path (Join-Path $Src "$DotnetToolRel\icon.png") -Destination $ImgOut -Force
89+
90+
Write-Host "Layout complete." -ForegroundColor Green

src/shared/DotnetTool/layout.sh

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/shared/DotnetTool/pack.ps1

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<#
2+
.SYNOPSIS
3+
Creates the NuGet package for the .NET tool.
4+
5+
.PARAMETER Configuration
6+
Build configuration (Debug/Release). Defaults to Debug.
7+
8+
.PARAMETER Version
9+
Package version (required).
10+
11+
.PARAMETER PackageRoot
12+
Root of the pre-laid-out package structure (from layout). Defaults to:
13+
out/shared/DotnetTool/nupkg/<Configuration>
14+
15+
.PARAMETER Output
16+
Optional directory for the produced .nupkg/.snupkg. If omitted NuGet chooses.
17+
18+
.EXAMPLE
19+
pwsh ./pack.ps1 -Version 2.0.123-beta
20+
21+
.EXAMPLE
22+
pwsh ./pack.ps1 -Configuration Release -Version 2.1.0 -Output C:\pkgs
23+
24+
#>
25+
26+
[CmdletBinding()]
27+
param(
28+
[string]$Configuration = "Debug",
29+
[Parameter(Mandatory = $true)]
30+
[string]$Version,
31+
[string]$PackageRoot,
32+
[string]$Output
33+
)
34+
35+
Set-StrictMode -Version Latest
36+
$ErrorActionPreference = 'Stop'
37+
38+
Write-Host "Starting pack..." -ForegroundColor Cyan
39+
40+
# Directories
41+
$ScriptDir = $PSScriptRoot
42+
$Root = (Resolve-Path (Join-Path $ScriptDir "..\..\..")).Path
43+
$Src = Join-Path $Root "src"
44+
$Out = Join-Path $Root "out"
45+
$DotnetToolRel = "shared\DotnetTool"
46+
$NuspecFile = Join-Path $Src "$DotnetToolRel\dotnet-tool.nuspec"
47+
48+
if (-not (Test-Path $NuspecFile)) {
49+
Write-Error "Could not locate nuspec file at '$NuspecFile'"
50+
exit 1
51+
}
52+
53+
if (-not $PackageRoot -or $PackageRoot.Trim() -eq "") {
54+
$PackageRoot = Join-Path $Out "$DotnetToolRel\nupkg\$Configuration"
55+
}
56+
57+
if (-not (Test-Path $PackageRoot)) {
58+
Write-Error "Package root '$PackageRoot' does not exist. Run layout.ps1 first."
59+
exit 1
60+
}
61+
62+
# Locate nuget
63+
$nugetCmd = Get-Command nuget -ErrorAction SilentlyContinue
64+
if (-not $nugetCmd) {
65+
Write-Error "nuget CLI not found in PATH (install: https://www.nuget.org/downloads)"
66+
exit 1
67+
}
68+
$nugetExe = $nugetCmd.Source
69+
70+
Write-Host "Creating .NET tool package..."
71+
72+
$packArgs = @(
73+
"pack", "$NuspecFile",
74+
"-Properties", "Configuration=$Configuration",
75+
"-Version", $Version,
76+
"-Symbols", "-SymbolPackageFormat", "snupkg",
77+
"-BasePath", "$PackageRoot"
78+
)
79+
80+
if ($Output -and $Output.Trim() -ne "") {
81+
if (-not (Test-Path $Output)) {
82+
Write-Host "Creating output directory '$Output'..."
83+
New-Item -ItemType Directory -Force -Path $Output | Out-Null
84+
}
85+
$packArgs += @("-OutputDirectory", "$Output")
86+
}
87+
88+
& $nugetExe @packArgs
89+
90+
if ($LASTEXITCODE -ne 0) {
91+
Write-Error "nuget pack failed with exit code $LASTEXITCODE"
92+
exit $LASTEXITCODE
93+
}
94+
95+
Write-Host ".NET tool pack complete." -ForegroundColor Green

src/shared/DotnetTool/pack.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)