Skip to content

Commit 27d0717

Browse files
MGudginGudgeCopilot
authored
Extract the .NET package smoke test into a shared script (#1655)
This PR moves the packed .NET SDK validation from the workflow into a PowerShell script that developers can run locally. CI invokes the same script and retains the .NET 8 and .NET 10 discovery and assembly checks. Details * Add a location-independent script with Release and Debug configurations. * Use isolated temporary consumers and caches, restoring MXC_FFI_DIR and removing temporary output even when validation fails. * Replace the inline workflow block and document local prerequisites. Tests * External `.\scripts\ci\test-dotnet-package.ps1` passed: both framework consumers ran native discovery and matched their packaged SDK assembly. * A controlled pack failure propagated its error and restored the caller's location and environment without leaving temporary output. * PowerShell syntax, workflow YAML, and `git diff --check` passed. * Linux and macOS execution awaits CI. Generated-with: auto (gpt) Co-authored-by: Gudge <gudge@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d4db3de4-724a-45fe-a8df-d3ea4f9d779c
1 parent bf0dbe5 commit 27d0717

3 files changed

Lines changed: 78 additions & 44 deletions

File tree

‎.github/workflows/SDK.Dotnet.Test.Job.yml‎

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -254,48 +254,5 @@ jobs:
254254
255255
- name: Test packed .NET SDK outside the checkout
256256
shell: pwsh
257-
env:
258-
MXC_FFI_DIR: ''
259257
run: |
260-
$ErrorActionPreference = 'Stop'
261-
$root = Join-Path $env:RUNNER_TEMP 'dotnet-package-smoke'
262-
$feed = Join-Path $root 'feed'
263-
$version = '0.0.0-package-smoke'
264-
dotnet pack Microsoft.Mxc.Sdk -c Release --no-restore -o $feed --nologo -p:PackageVersion=$version -p:MxcPackSingleRid=true
265-
if ($LASTEXITCODE -ne 0) { throw "Packing the SDK exited $LASTEXITCODE" }
266-
foreach ($framework in @('net8.0', 'net10.0')) {
267-
$consumer = Join-Path $root $framework
268-
New-Item -ItemType Directory -Force -Path $consumer | Out-Null
269-
@"
270-
<Project Sdk="Microsoft.NET.Sdk">
271-
<PropertyGroup>
272-
<OutputType>Exe</OutputType>
273-
<TargetFramework>$framework</TargetFramework>
274-
<ImplicitUsings>enable</ImplicitUsings>
275-
<Nullable>enable</Nullable>
276-
</PropertyGroup>
277-
</Project>
278-
"@ | Set-Content (Join-Path $consumer 'Consumer.csproj')
279-
@'
280-
using Microsoft.Mxc.Sdk.V1;
281-
282-
var support = MxcPlatform.GetPlatformSupport();
283-
Console.WriteLine($"platform supported: {support.IsSupported}; reason: {support.Reason}");
284-
foreach (var backend in MxcPlatform.GetAvailableBackends())
285-
{
286-
Console.WriteLine($"backend: {backend.Backend}");
287-
Console.WriteLine($"capabilities: {string.Join(", ", backend.Capabilities)}");
288-
Console.WriteLine($"warnings: {string.Join(", ", backend.Warnings)}");
289-
}
290-
'@ | Set-Content (Join-Path $consumer 'Program.cs')
291-
$cache = Join-Path $root "cache-$framework"
292-
dotnet package add Microsoft.Mxc.Sdk --project $consumer --version $version --source $feed --package-directory $cache
293-
if ($LASTEXITCODE -ne 0) { throw "Restoring the $framework package consumer exited $LASTEXITCODE" }
294-
dotnet run --project $consumer -c Release --no-restore
295-
if ($LASTEXITCODE -ne 0) { throw "The $framework packed SDK consumer exited $LASTEXITCODE" }
296-
$expected = Join-Path $cache "microsoft.mxc.sdk/$version/lib/$framework/Microsoft.Mxc.Sdk.dll"
297-
$actual = Join-Path $consumer "bin/Release/$framework/Microsoft.Mxc.Sdk.dll"
298-
if ((Get-FileHash $expected).Hash -ne (Get-FileHash $actual).Hash) {
299-
throw "The $framework consumer did not use the matching SDK assembly."
300-
}
301-
}
258+
& (Join-Path $env:GITHUB_WORKSPACE 'scripts\ci\test-dotnet-package.ps1')

‎docs/development/build-and-test/pull-requests.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ dotnet build Microsoft.Mxc.Sdk.slnx -c Release
9696
dotnet test --solution Microsoft.Mxc.Sdk.slnx -c Release --no-build
9797
```
9898

99+
To run the same packed-SDK check as CI, use PowerShell 7 from any directory:
100+
101+
```powershell
102+
& <repo>\scripts\ci\test-dotnet-package.ps1
103+
```
104+
105+
First build the solution as above to restore its dependencies. The script
106+
packs the SDK in Release configuration, runs both temporary consumers, and
107+
removes their isolated package caches and output afterward. Use
108+
`-Configuration Debug` to pack a Debug build instead. It temporarily clears
109+
`MXC_FFI_DIR` and restores the caller's value when finished. Both .NET 8 and
110+
.NET 10 runtimes must be installed.
111+
99112
### Local Node SDK package validation
100113

101114
From `sdk/node`, run `npm run typecheck` before pushing SDK changes. It builds

‎scripts/ci/test-dotnet-package.ps1‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[CmdletBinding()]
2+
param(
3+
[ValidateSet('Debug', 'Release')]
4+
[string]$Configuration = 'Release'
5+
)
6+
7+
$ErrorActionPreference = 'Stop'
8+
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
9+
$tempRoot = if ($env:RUNNER_TEMP) { $env:RUNNER_TEMP } else { [IO.Path]::GetTempPath() }
10+
$root = Join-Path $tempRoot "dotnet-package-smoke-$([guid]::NewGuid())"
11+
$feed = Join-Path $root 'feed'
12+
$version = '0.0.0-package-smoke'
13+
$originalFfiDir = $env:MXC_FFI_DIR
14+
15+
Push-Location (Join-Path $repoRoot 'sdk\dotnet')
16+
try {
17+
$env:MXC_FFI_DIR = ''
18+
dotnet pack Microsoft.Mxc.Sdk -c $Configuration --no-restore -o $feed --nologo -p:PackageVersion=$version -p:MxcPackSingleRid=true
19+
if ($LASTEXITCODE -ne 0) { throw "Packing the SDK exited $LASTEXITCODE" }
20+
foreach ($framework in @('net8.0', 'net10.0')) {
21+
$consumer = Join-Path $root $framework
22+
New-Item -ItemType Directory -Force -Path $consumer | Out-Null
23+
@"
24+
<Project Sdk="Microsoft.NET.Sdk">
25+
<PropertyGroup>
26+
<OutputType>Exe</OutputType>
27+
<TargetFramework>$framework</TargetFramework>
28+
<ImplicitUsings>enable</ImplicitUsings>
29+
<Nullable>enable</Nullable>
30+
</PropertyGroup>
31+
</Project>
32+
"@ | Set-Content (Join-Path $consumer 'Consumer.csproj')
33+
@'
34+
using Microsoft.Mxc.Sdk.V1;
35+
36+
var support = MxcPlatform.GetPlatformSupport();
37+
Console.WriteLine($"platform supported: {support.IsSupported}; reason: {support.Reason}");
38+
foreach (var backend in MxcPlatform.GetAvailableBackends())
39+
{
40+
Console.WriteLine($"backend: {backend.Backend}");
41+
Console.WriteLine($"capabilities: {string.Join(", ", backend.Capabilities)}");
42+
Console.WriteLine($"warnings: {string.Join(", ", backend.Warnings)}");
43+
}
44+
'@ | Set-Content (Join-Path $consumer 'Program.cs')
45+
$cache = Join-Path $root "cache-$framework"
46+
dotnet package add Microsoft.Mxc.Sdk --project $consumer --version $version --source $feed --package-directory $cache
47+
if ($LASTEXITCODE -ne 0) { throw "Restoring the $framework package consumer exited $LASTEXITCODE" }
48+
dotnet run --project $consumer -c Release --no-restore
49+
if ($LASTEXITCODE -ne 0) { throw "The $framework packed SDK consumer exited $LASTEXITCODE" }
50+
$expected = Join-Path $cache "microsoft.mxc.sdk\$version\lib\$framework\Microsoft.Mxc.Sdk.dll"
51+
$actual = Join-Path $consumer "bin\Release\$framework\Microsoft.Mxc.Sdk.dll"
52+
if ((Get-FileHash $expected).Hash -ne (Get-FileHash $actual).Hash) {
53+
throw "The $framework consumer did not use the matching SDK assembly."
54+
}
55+
Write-Host "$framework packed SDK discovery and assembly checks passed."
56+
}
57+
}
58+
finally {
59+
$env:MXC_FFI_DIR = $originalFfiDir
60+
Pop-Location
61+
if (Test-Path -LiteralPath $root) {
62+
Remove-Item -LiteralPath $root -Recurse -Force
63+
}
64+
}

0 commit comments

Comments
 (0)