Skip to main content

swa-pack-format

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.

소스 정보

저장소
dotnet/sdk
최근 소스 활동
2026년 3월 19일 13:27
감지된 SKILL.md 언어
영어
스타
3,227
포크
1,300

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
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.
# 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.
GitHub에서 보기