Skip to content

Replace removed AddNpmApp in the What is Aspire C# AppHost sample - #1998

Merged
David Pine (IEvangelist) merged 1 commit into
mainfrom
aspireagent/fix-what-is-aspire-addnpmapp
Oct 30, 2026
Merged

David Pine (IEvangelist) merged 1 commit into
mainfrom
aspireagent/fix-what-is-aspire-addnpmapp

Conversation

@davidfowl

Copy link
Copy Markdown
Contributor

Summary

The C# tab of the flagship What is Aspire? AppHost sample calls builder.AddNpmApp("frontend", "../frontend"). AddNpmApp was removed in Aspire 13 (this repo's own whats-new/aspire-13.mdx says: "AddNpmApp() - Use AddJavaScriptApp() instead … or AddViteApp() for Vite projects"), so a reader who copies the sample into a file-based AppHost referencing the current Aspire.Hosting.JavaScript gets a compile error.

Fix: use AddViteApp("frontend", "../frontend"), which matches the sibling TypeScript tab (addViteApp("frontend", "../frontend")) and the current API: JavaScriptHostingExtensions.AddViteApp(this IDistributedApplicationBuilder builder, string name, string appDirectory, string runScriptName = "dev") in src/data/pkgs/Aspire.Hosting.JavaScript.13.6.0.json, generated from microsoft/aspire sourceCommit f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62. That API data contains no AddNpmApp member.

Regression check: the new tests/unit/get-started-apphost-apis.vitest.test.ts reads every C# fence under get-started/ that contains DistributedApplication.CreateBuilder. It asserts that each builder.AddXxx( call exists as a member in the generated src/data/pkgs API data.

  • Before the fix: it fails with exactly ["src/content/docs/get-started/what-is-aspire.mdx: AddNpmApp"].
  • After the fix: it passes.

How this was found: I audited English docs C# samples against the in-repo generated package API data (5,004 member names, 202 packages). Across 1,675 builder.AddXxx( calls in AppHost fences (excluding whats-new, which is historical), the only call missing from upstream data was AddNpmApp. The other misses are tutorial-defined extensions such as AddMailDev and AddMyResource. AddNpmApp also appears in app-host/certificate-configuration.mdx, architecture/resource-hierarchies.mdx and architecture/resource-model.mdx. I deliberately left those files alone because open PRs #1636, #1634 and #1164 touch them, so the new test is scoped to get-started/.

Rendered C# tab, desktop 1280×900, light theme (local dev server)

Before After
Before: What is Aspire C# AppHost sample calls builder.AddNpmApp, desktop 1280x900 light theme After: What is Aspire C# AppHost sample calls builder.AddViteApp, desktop 1280x900 light theme

Third-party links and affiliations

None

Validation

  • npx vitest run tests/unit/get-started-apphost-apis.vitest.test.ts: fails on main (the AddNpmApp entry above) and passes with the fix.
  • npx vitest run: 84 files, 1,120 passed, 1 skipped.
  • npx eslint . --max-warnings 0: clean.
  • npx prettier --check on the new test: clean. what-is-aspire.mdx already has Prettier warnings on main; this change doesn't touch them.
  • Playwright screenshots of the rendered C# tab before and after, taken from the local astro dev server.

🤖 Posted by AspireAgent (AI Agent)

AddNpmApp was removed in Aspire 13 (see whats-new/aspire-13). The C# tab on
get-started/what-is-aspire still called it, so the copied sample does not
compile against current Aspire.Hosting.JavaScript. Use AddViteApp, matching
the TypeScript tab's addViteApp, and add a unit check that get-started C#
AppHost samples only call builder Add* APIs present in the generated
package API data.

Co-authored-by: Copilot <[email protected]>
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Frontend HTML artifact ready

The latest frontend build uploaded the frontend-dist artifact for PR #1998. Use the VS Code button below to open this PR with GitHub Artifacts Explorer and browse the built HTML locally.

VS Code: Open PR #1998 artifacts

This comment updates automatically when a new frontend build artifact is uploaded.

@davidfowl
David Fowler (davidfowl) marked this pull request as ready for review October 30, 2026 15:35
Copilot AI balanced review requested due to automatic review settings October 30, 2026 15:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the sample API update and accompanying regression test.

No open issues 🎉

What changed in this PR

Updates the introductory C# AppHost sample to use AddViteApp instead of the removed AddNpmApp, matching the sibling TypeScript example.

Changes:

  • Replaces the obsolete API call in “What is Aspire?”
  • Adds a regression test that checks builder.AddXxx calls in get-started C# AppHost samples against generated package API member names.
File Description
src/​frontend/​tests/​unit/​get-started-apphost-apis.vitest.test.ts Adds API-name validation for get-started C# AppHost samples.
src/​frontend/​src/​content/​docs/​get-started/​what-is-aspire.mdx Switches the frontend resource to AddViteApp.

Review effort: Balanced

@IEvangelist
David Pine (IEvangelist) enabled auto-merge (squash) October 30, 2026 15:43
@IEvangelist
David Pine (IEvangelist) merged commit 726e0ce into main Oct 30, 2026
20 checks passed
@IEvangelist
David Pine (IEvangelist) deleted the aspireagent/fix-what-is-aspire-addnpmapp branch October 30, 2026 15:44
David Pine (IEvangelist) pushed a commit that referenced this pull request Nov 3, 2026
…2004)

## Summary

This PR started as a fix for the Japanese [What is
Aspire?](https://aspire.dev/ja/get-started/what-is-aspire/) C# AppHost
sample, which called `AddNpmApp`. That API was removed in Aspire 13.
#2015 has since replaced the line on `main` with
`AddJavaScriptApp("frontend", "../frontend")`. After the rebase, this PR
keeps `main`'s line and is **test-only**.

**Change:** extend the regression test that #1998 added,
`tests/unit/get-started-apphost-apis.vitest.test.ts`.
- It now scans `get-started/` in every locale, not just English.
- It asserts that at least one localized `get-started` directory was
included, so the coverage can't silently drop.
- It normalizes path separators so the reported paths are stable on
Windows.

Without this change, a localized sample that calls an API missing from
the published `src/data/pkgs` data, like `AddNpmApp`, isn't caught.

Maintainers can close this PR if they don't want the extra guard.

## Third-party links and affiliations

None.

## Validation

- `npx vitest run tests/unit/get-started-apphost-apis.vitest.test.ts`
passes on the rebased head.
- Negative check: temporarily restoring `AddNpmApp` in
`ja/get-started/what-is-aspire.mdx` makes the test fail with that entry.
I then reverted the probe.

No screenshots, because this PR has no rendered changes.

**🤖 Posted by AspireAgent (AI Agent)**

---------

Co-authored-by: davidfowl <[email protected]>
Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants