Agents & OrchestrationSûr100100/100

Swa Pack Format (.NET)

Understand and fix Static Web Assets Pack tests. USE FOR: fixing Pack test assertion failures after nupkg content changes, tracing MSBuild conditions to expected nupkg content, updating test assertions for new or changed package layouts, understanding conditional pack logic in .targets files.

ou envoie-le directement à ton agent.

Installer dans ton projet

$ curl -fsSL https://arboristhree.xyz/cli/install-skill.mjs -o /tmp/arboris-install-skill.mjs && node /tmp/arboris-install-skill.mjs swa-pack-format__dotnet-dotnet__src-sdk-claude-skills-62f7094108e7
.NET
dotnet/dotnet
Contenu à copier
---
name: swa-pack-format
description: 'Understand and fix Static Web Assets Pack tests. USE FOR: fixing Pack test assertion failures after nupkg content changes, tracing MSBuild conditions to expected nupkg content, updating test assertions for new or changed package layouts, understanding conditional pack logic in .targets files.'
metadata:
  origin: .NET
---

# SWA Pack Testing

Pack tests validate that `dotnet pack` produces nupkg files with the correct content (import files, manifests, static assets). The nupkg layout is defined by MSBuild `.targets` files that use conditions to branch on TFM version, project configuration, or feature flags.

## How Pack Content Is Defined

Pack targets live in `src/StaticWebAssetsSdk/Targets/` (primarily `Microsoft.NET.Sdk.StaticWebAssets.Pack.targets`). They populate nupkg content using `<Content>` or `<None>` items with `Pack="true"` and `PackagePath` metadata.

The targets use **MSBuild conditions** to determine which files to include. Common condition axes:

- **Target Framework Version** — different TFMs may produce different nupkg layouts
- **Feature flags** — MSBuild properties that gate new behavior behind conditions
- **Asset presence** — whether the project has scoped CSS, JS modules, etc.

When a condition branches, **each branch produces a different set of nupkg entries**. Test assertions must match the branch that the test's TFM and configuration activate.

## How Pack Tests Work

Pack tests are in `StaticWebAssetsPackIntegrationTest`. They:

1. Create a test project via `CreateAspNetSdkTestAsset()` (optionally overriding the TFM)
2. Run `dotnet pack` against it
3. Assert nupkg contents using helper methods:
   - `NuPkgContainsPatterns(nupkgPath, ...patterns)` — glob matching
   - `NuPkgContain(nupkgPath, ...exactPaths)` — exact path matching

## Fixing Pack Test Assertion Failures

When a pack test fails because the nupkg contains different files than expected:

### Step 1: Identify the test's TFM

Check how the test creates its asset:
```csharp
// Uses the repo's default TFM (current)
var testAsset = ProjectDirectory.CreateAspNetSdkTestAsset(testAssetName);

// Explicitly targets an older TFM
var testAsset = ProjectDirectory.CreateAspNetSdkTestAsset(testAssetName, identifier: "net60")
    .WithProjectChanges(p => { /* sets TargetFramework to net6.0 */ });
```

### Step 2: Trace the condition in Pack.targets

Open `Microsoft.NET.Sdk.StaticWebAssets.Pack.targets` and find the `Condition` attributes on the `<ItemGroup>` elements that populate pack content. Evaluate which branch fires for the test's TFM.

### Step 3: Update assertions to match the active branch

The test assertion must list exactly what the active condition branch puts into the nupkg — no more, no less. Common nupkg paths:
- `build/{file}` — build-time imports and manifests
- `buildMultiTargeting/{file}` — multi-targeting imports
- `buildTransitive/{file}` — transitive dependency imports
- `staticwebassets/**` — the actual asset files

### Step 4: Preserve backward-compat tests

Tests that explicitly target older TFMs exist to verify backward compatibility. Their assertions match the older format and must not be updated to the current format. Only update tests whose TFM activates the new condition branch.

## Intermediate File Assertions

Some tests verify names of intermediate outputs (files generated during the build but not shipped in the nupkg). These file names are also conditioned — trace the `.targets` to find the correct intermediate filename for the test's configuration.

## Key Locations

| What | Where |
|------|-------|
| Pack targets | `src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.Pack.targets` |
| Pack tests | `test/Microsoft.NET.Sdk.StaticWebAssets.Tests/Pack/StaticWebAssetsPackIntegrationTest.cs` |
| Test helpers | `NuPkgContainsPatterns`, `NuPkgContain` in the test utilities |

## General Principle

When you change pack-related `.targets` logic (new conditions, new files, changed paths), find every pack test whose TFM and configuration activate the changed branch, and update its assertions. Leave tests on other branches untouched.
Colle ce Markdown dans ton agent ou utilise les boutons ci-dessus pour l’écrire dans ton projet.

Ce que fait Swa Pack Format (.NET)

**Target Framework Version** — different TFMs may produce different nupkg layouts
**Feature flags** — MSBuild properties that gate new behavior behind conditions
**Asset presence** — whether the project has scoped CSS, JS modules, etc.
`NuPkgContainsPatterns(nupkgPath, ...patterns)` — glob matching

Comment utiliser Swa Pack Format (.NET)

1
Copie le prompt
Un clic copie le prompt packagé (ou l'envoie à ton agent).
2
L'agent installe le skill
Il ajoute le SKILL.md et ses ressources à ton projet.
3
Activation automatique
Le skill s'active dès que le contexte correspond.

Déclencheurs pour Swa Pack Format (.NET)

Dis simplement à ton agent quelque chose comme :

Applique le skill swa-pack-format__dotnet-dotnet__src-sdk-claude-skills-62f7094108e7 à cette tâche
Utilise swa-pack-format__dotnet-dotnet__src-sdk-claude-skills-62f7094108e7 pour améliorer cette implémentation
Passe en revue ce sujet avec swa-pack-format__dotnet-dotnet__src-sdk-claude-skills-62f7094108e7

Skills liés à Swa Pack Format (.NET)