Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .config/purview-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ docs:
- index.md
targetFrameworks:
- net10.0
- net11.0
packages:
- id: Purview.Aspire.ResourceKit
description: Runtime and source generator for resource kits.
Expand All @@ -51,13 +52,9 @@ useCases:
[HostKit]
partial class ShopHostKit;

[ResourceDefinition<Projects.Example_Service>("api")]
partial class ApiResourceKit
{
protected override IResourceBuilder<ProjectResource> BuildResource(
IDistributedApplicationBuilder builder)
=> builder.AddProject<Projects.Example_Service>(Name);
}
// BuildResource is generated as AddDotnetProject(builder, Name, ProjectPath).
[ResourceDefinition<DotnetProjectResource>("api", ProjectPath = "../Api/Api.csproj")]
partial class ApiResourceKit;
language: csharp
outcome: >-
Resource definitions become strongly typed, source-generated classes with generated host
Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ npx skills add purview-dev/aspire-resourcekit

| Skill | Answers |
| --- | --- |
| `skills/purview-resourcekit-authoring/` | declaring a `[HostKit]` and resource kits, attribute styles, parent/child hierarchies, the Build/Configure lifecycle, project resources, groups and URLs |
| `skills/purview-resourcekit-authoring/` | declaring a `[HostKit]` and resource kits, attribute styles, parent/child hierarchies, the Build/Configure lifecycle, project and path-based resources (including the generated `BuildResource` and typed `AppHostProjects` paths), groups and URLs |
| `skills/purview-resourcekit-options/` | generated options including nested child options, extending them, run modes (`Mode`), inherited `IsEnabled` versus `IsResourceEnabled`, `OptionsHelper` |
| `skills/purview-resourcekit-testing/` | TUnit.Aspire fixtures, overriding options from a test, hierarchy model tests, running the tiers |
| `skills/purview-resourcekit-diagnostics/` | what an `SG00xx` means, including hierarchy, group-placement and redundant-`ResourceBuilder` rules, and how to fix it |
| `skills/purview-resourcekit-diagnostics/` | what an `SG00xx` means, including hierarchy, group-placement, declared-path, redundant-`ResourceBuilder` and redundant-`BuildResource` rules, the `RKP` build errors, and how to fix each |
| `skills/purview-resourcekit-migration/` | converting an existing inline AppHost into ResourceKit composition, including extracting child resource kits |

Every skill carries the `purview-resourcekit` prefix. Skills install into one flat directory per
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ All notable changes to `Purview.Aspire.ResourceKit` are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- **Generated `BuildResource` for path-based kits.** A `DotnetProjectResource`, `ViteAppResource` or
`NextJsAppResource` kit that declares `ProjectPath`/`ResourcePath` and writes no `BuildResource` gets
the `AddDotnetProject`/`AddViteApp`/`AddNextJsApp` registration generated from the declared path. It
is not generated when the kit writes the override or an explicit base class implements it.
- **SG0044** (Info) reports a `BuildResource` override that only repeats the generated call; its code
fix removes the override, first moving the path into `ProjectPath`/`ResourcePath` when the attribute
does not declare it.

### Fixed

- **Aspire 17 migration guidance no longer loses `Projects.*` projects.** `Aspire.AppHost.Sdk` marked
every `<ProjectReference>` `IsAspireProjectResource=true`; `Microsoft.NET.Sdk` does not, so a plain
reference stops generating its `Projects.*` type and the project's path is lost. The migration skill
and the project-resources page now inventory every reference before the SDK changes, and convert each
one to a `<ResourceKitProject>` or keep it with the metadata restored.

## [2.1.0] - 2026-11-18

### Added
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,17 @@ If your AppHost is getting bigger, this helps you keep resource setup maintainab

```csharp
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Dotnet;
using Purview.Aspire.ResourceKit;

[HostKit]
partial class ShopHostKit;

// Aspire 17 Project V2. On Aspire 13.6, use [ResourceDefinition<Projects.Example_Service>] with
// Aspire 17 Project V2: BuildResource is generated as AddDotnetProject(Name, ProjectPath). On Aspire
// 13.6, use [ResourceDefinition<Projects.Example_Service>] with an override that calls
// builder.AddProject<Projects.Example_Service>(Name) instead; both forms are supported.
[ResourceDefinition<DotnetProjectResource>("api", ProjectPath = "../Api/Api.csproj")]
partial class ApiResourceKit
{
protected override IResourceBuilder<DotnetProjectResource> BuildResource(IDistributedApplicationBuilder builder)
=> builder.AddDotnetProject(Name, "../Api/Api.csproj");
}
partial class ApiResourceKit;

var builder = DistributedApplication.CreateBuilder(args);
builder.AddAspireResourceKit();
Expand Down
5 changes: 3 additions & 2 deletions docs/wiki/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ both Aspire lines.
| Pre-17 (13.6) | `src/src/Example.Pre17.AppHost` | `src/src/Example.Pre17.ManualAppHost` |

The **generated** projects use attributes and no hand-written wiring. The **manual** projects implement
`HostKitBase` / `ResourceKitBase` by hand and disable the source generator. The Aspire 17 pair adds the
API with `AddDotnetProject` and declares `ProjectPath` on the resource kit; the Pre-17 pair uses
`HostKitBase` / `ResourceKitBase` by hand and disable the source generator. In the Aspire 17 pair the
API is a `DotnetProjectResource`: the generated host declares `ProjectPath` and lets ResourceKit generate
the `AddDotnetProject` call, and the manual host writes that call itself. The Pre-17 pair uses
`AddProject<Projects.Example_Service>`.

The Aspire 17 examples require the Aspire CLI bundle at build time (ASPIRE013); the Pre-17 pair does
Expand Down
8 changes: 5 additions & 3 deletions docs/wiki/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ partial class ApiResourceKit
> explicit base, when used, resolves to `ProjectResource` (SG0019).
>
> On **Aspire 17**, use Project V2 instead:
> `[ResourceDefinition<DotnetProjectResource>("api", ProjectPath = "../Api/Api.csproj")]` and
> `builder.AddDotnetProject(Name, "../Api/Api.csproj")`. SG0018 validates the declared path, SG0019 the
> explicit base, and SG0041 reports a `ProjectPath` on a non-V2 resource. The legacy form still works on
> `[ResourceDefinition<DotnetProjectResource>("api", ProjectPath = "../Api/Api.csproj")]`. With no
> override, `BuildResource` is generated as `AddDotnetProject(Name, "../Api/Api.csproj")`. SG0018
> validates the path in a hand-written override, SG0044 reports one that only repeats the generated
> call, SG0019 validates an explicit base, and SG0041 reports a `ProjectPath` on a non-V2 resource. The
> legacy form still works on
> 17, where `AddProject<T>` reports `CS0618`. See [Project Resources](concepts/Project-Resources.md).

### Choose an attribute style
Expand Down
103 changes: 74 additions & 29 deletions docs/wiki/concepts/Project-Resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,72 @@ catch wiring mistakes:

| Aspire | Registration | Declaration |
| --- | --- | --- |
| 17+ (Project V2) | `AddDotnetProject(name, path)` | `[ResourceDefinition<DotnetProjectResource>(ProjectPath = "...")]` |
| 17+ (Project V2) | `AddDotnetProject(name, path)`, generated from `ProjectPath` | `[ResourceDefinition<DotnetProjectResource>(ProjectPath = "...")]` |
| 13.6 (legacy) | `AddProject<TProject>()` | `[ResourceDefinition<Projects.MyService>]` |

The legacy form still works on Aspire 17, where `AddProject<T>` reports `CS0618`; the V2 form is the
one to use for a new Aspire 17 AppHost. The package declares the 13.6 floor, so a 13.6 consumer never
has to reference `Aspire.Hosting.Dotnet`.
The V2 form is the one to use for an Aspire 17 AppHost. The package declares the 13.6 floor, so a 13.6
consumer never has to reference `Aspire.Hosting.Dotnet`.

> [!WARNING]
> **Moving to Aspire 17 drops every `Projects.*` type unless you carry the reference over.**
> `Aspire.AppHost.Sdk` set `IsAspireProjectResource=true` on every `<ProjectReference>`, and
> `Aspire.Hosting.AppHost` generates `Projects.<Name>` only from references that carry it. An Aspire 17
> AppHost uses `Microsoft.NET.Sdk`, which adds no such default. A plain `<ProjectReference>` then stops
> producing its type, and it turns into an ordinary assembly reference. Before changing the SDK, list
> every `<ProjectReference>` not marked `IsAspireProjectResource="false"`. Convert each one to a
> `<ResourceKitProject>` item and a `ProjectPath` (see [Typed paths](#typed-paths-apphostprojects)), or
> keep it with `IsAspireProjectResource="true"`, `ReferenceOutputAssembly="false"` and
> `SkipGetTargetFrameworkProperties="true"` when the registration still needs the `Projects.*` type
> (for example `AddAzureFunctionsProject<T>`). With that metadata the legacy form still works, though
> `AddProject<T>` reports `CS0618`.

## Aspire 17 Project V2

Declare the project path on the attribute and add the same path with `AddDotnetProject`:
Declare the project path on the attribute. That is the only place it needs to be stated:

```csharp
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Dotnet;
using Purview.Aspire.ResourceKit;

[ResourceDefinition<DotnetProjectResource>("api", ProjectPath = "../Example.Service/Example.Service.csproj")]
partial class ApiResourceKit;
```

The generator emits `ResourceKitBase<THostKit, DotnetProjectResource>` and, because the kit writes no
`BuildResource`, the registration as well:

```csharp
protected override IResourceBuilder<DotnetProjectResource> BuildResource(IDistributedApplicationBuilder builder) =>
global::Aspire.Hosting.DotnetProjectHostingExtensions.AddDotnetProject(builder, Name, "../Example.Service/Example.Service.csproj");
```

`DotnetProjectResource` implements `IResourceWithEndpoints` and `IResourceWithEnvironment`, so URLs,
references and `WithEnvironment` work as they do for any other resource. Put that configuration in
`ConfigureResource`, which leaves the generated `BuildResource` in place.

### Writing `BuildResource` yourself

Write the override when registration needs more than the name and path, such as the `configure`
callback of `AddDotnetProject` or a fluent call on the result. ResourceKit then generates nothing, and
SG0018 checks that your override adds the declared path:

```csharp
[ResourceDefinition<DotnetProjectResource>("api", ProjectPath = "../Example.Service/Example.Service.csproj")]
partial class ApiResourceKit
{
protected override IResourceBuilder<DotnetProjectResource> BuildResource(IDistributedApplicationBuilder builder)
=> builder.AddDotnetProject(Name, "../Example.Service/Example.Service.csproj");
=> builder.AddDotnetProject(Name, "../Example.Service/Example.Service.csproj").WithHttpEndpoint();
}
```

The generator emits `ResourceKitBase<THostKit, DotnetProjectResource>`. `DotnetProjectResource`
implements `IResourceWithEndpoints` and `IResourceWithEnvironment`, so URLs, references and
`WithEnvironment` work as they do for any other resource.
An override that only repeats the generated call, `builder.AddDotnetProject(Name, path)`, reports
**SG0044** (info). Its code fix deletes the override. If the attribute doesn't declare the path yet,
the fix first moves the path argument into `ProjectPath`, so the attribute becomes the one place the
path is stated. A literal moves as written. A constant such as `AppHostProjects.Api.Path` moves as a
reference to that constant.

The override is never generated when a base class already implements `BuildResource`, or for the
legacy `Projects.*` form, which has no path.

`ProjectPath` is a named argument on both `[ResourceDefinition]` and
`[ResourceDefinition<TResource>]`. It is a build-time declaration, not a bindable option.
Expand All @@ -41,9 +79,10 @@ implements `IResourceWithEndpoints` and `IResourceWithEnvironment`, so URLs, ref

### The declared path must be added (SG0018)

`BuildResource` must call `AddDotnetProject` with the declared path. The comparison normalises `\`
and `/`, so either separator is accepted; a computed (non-literal) path is accepted because it cannot
be compared at compile time.
A hand-written `BuildResource` must call `AddDotnetProject` with the declared path. A generated one
always does, so SG0018 only applies when you write the override. The comparison normalises `\` and
`/`, so either separator is accepted. A computed (non-constant) path is accepted because it can't be
compared at compile time.

```csharp
// OK
Expand Down Expand Up @@ -157,14 +196,26 @@ separator normalisation and computed-path allowance as `AddDotnetProject`:
```csharp
using Aspire.Hosting.JavaScript;

// Generates BuildResource as AddViteApp(builder, Name, "../../../web/packages/vite-app").
[ResourceDefinition<ViteAppResource>("web", ResourcePath = "../../../web/packages/vite-app")]
partial class WebResourceKit
partial class WebResourceKit;

// AddNodeApp also needs a script path, so the override is written by hand and SG0018 validates it.
[ResourceDefinition<NodeAppResource>("worker", ResourcePath = "../../../web/packages/worker")]
partial class WorkerResourceKit
{
protected override IResourceBuilder<ViteAppResource> BuildResource(IDistributedApplicationBuilder builder) =>
builder.AddViteApp(Name, "../../../web/packages/vite-app", "dev");
protected override IResourceBuilder<NodeAppResource> BuildResource(IDistributedApplicationBuilder builder) =>
builder.AddNodeApp(Name, "../../../web/packages/worker", "server.js");
}
```

- `BuildResource` is generated for `ViteAppResource` (`AddViteApp`) and `NextJsAppResource`
(`AddNextJsApp`), leaving the run script at its `"dev"` default. Pass a different script, and the
override is yours to write. SG0044 reports an override that only repeats the generated call,
including one that passes `"dev"` explicitly.
- Node, Bun and Deno apps, and a kit declared against the `JavaScriptAppResource` base type, always
need a hand-written override.

- Supported methods: `AddViteApp`, `AddNextJsApp`, `AddNodeApp`, `AddBunApp`, `AddDenoApp`,
`AddJavaScriptApp`. The path is read from the `appDirectory` parameter (or `path` /
`workingDirectory` when named).
Expand Down Expand Up @@ -208,23 +259,17 @@ internal static class AppHostProjects
```

```csharp
// Both registrations are generated from the declared path.
[ResourceDefinition<DotnetProjectResource>(AppHostProjects.Api.Name, ProjectPath = AppHostProjects.Api.Path)]
partial class ApiResourceKit
{
protected override IResourceBuilder<DotnetProjectResource> BuildResource(IDistributedApplicationBuilder builder) =>
builder.AddDotnetProject(Name, AppHostProjects.Api.Path);
}
partial class ApiResourceKit;

[ResourceDefinition<ViteAppResource>(AppHostProjects.Web.Name, ResourcePath = AppHostProjects.Web.Path)]
partial class WebResourceKit
{
protected override IResourceBuilder<ViteAppResource> BuildResource(IDistributedApplicationBuilder builder) =>
builder.AddViteApp(Name, AppHostProjects.Web.Path, "dev");
}
partial class WebResourceKit;
```

`Path` is a `const`, so SG0018 still validates it against `AddDotnetProject` or the matching JavaScript
`Add*App` call; a literal `ResourcePath` and a generated constant behave identically.
The path is declared once, in the csproj, and referenced once, on the attribute. `Path` is a `const`, so
the generator reads its value for the generated `BuildResource`. When you write the override yourself,
SG0018 validates the constant just as it validates a literal.

- The item's `Name` is the logical Aspire resource name and defaults to the leaf file/directory name.
Only letters, digits, `.`, `_` and `-` are allowed (`RKP0003`).
Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/project/Agent-Skills.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ records what it installed in `skills-lock.json`, so the set can be restored late

| Skill | Answers |
| --- | --- |
| `purview-resourcekit-authoring` | declaring a `[HostKit]` and resource kits, attribute styles, parent/child hierarchies, the Build/Configure lifecycle, project resources, groups and URLs |
| `purview-resourcekit-authoring` | declaring a `[HostKit]` and resource kits, attribute styles, parent/child hierarchies, the Build/Configure lifecycle, project and path-based resources (including the generated `BuildResource` and typed `AppHostProjects` paths), groups and URLs |
| `purview-resourcekit-options` | generated options including nested child options, extending them, run modes (`Mode`), inherited `IsEnabled` versus `IsResourceEnabled`, `OptionsHelper` |
| `purview-resourcekit-testing` | TUnit.Aspire fixtures, overriding options from a test, hierarchy model tests, running the tiers |
| `purview-resourcekit-diagnostics` | what an `SG00xx` means, including hierarchy, group-placement and redundant-`ResourceBuilder` rules, and how to fix it |
| `purview-resourcekit-diagnostics` | what an `SG00xx` means, including hierarchy, group-placement, declared-path, redundant-`ResourceBuilder` and redundant-`BuildResource` rules, the `RKP` build errors, and how to fix each |
| `purview-resourcekit-migration` | converting an existing inline AppHost into ResourceKit composition, including extracting child resource kits |

Each is authored at `skills/<name>/SKILL.md` in this repository, and validated on every test run
Expand Down
18 changes: 17 additions & 1 deletion docs/wiki/project/Release-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ upgrade from the `1.0.0-prerelease.*` line. The full, machine-readable history l
[`CHANGELOG.md`](https://github.com/purview-dev/aspire-resourcekit/blob/main/CHANGELOG.md) and on
the [GitHub releases page](https://github.com/purview-dev/aspire-resourcekit/releases).

## 2.2.0 (unreleased)

- **`BuildResource` is generated from a declared path.** A `DotnetProjectResource`, `ViteAppResource`
or `NextJsAppResource` kit that declares `ProjectPath`/`ResourcePath` and writes no override gets
`AddDotnetProject`, `AddViteApp` or `AddNextJsApp` generated, so the path is stated once, on the
attribute. A hand-written override still wins, and SG0018 still validates it. See
[Project Resources](../concepts/Project-Resources.md).
- **SG0044** (Info) and its code fix remove an override that only repeats the generated call, moving the
path into the attribute first when it isn't declared there.

## 2.1.0

- **Aspire 17 Project V2** — `[ResourceDefinition<DotnetProjectResource>("api", ProjectPath = "../Api/Api.csproj")]`
Expand All @@ -15,8 +25,14 @@ the [GitHub releases page](https://github.com/purview-dev/aspire-resourcekit/rel
- **Aspire 13.6 still supported.** The package keeps the `Aspire.Hosting` 13.6.5 floor and resolves
`DotnetProjectResource` by metadata name, so a 13.6 consumer is unaffected. `verify-consumers` builds
both a 13.6 and a 17 consumer from the packed package.
- **Path-based resources.** `ResourcePath` declares the path for `AddDotnetProject` and the Aspire
JavaScript `Add*App` methods, validated by SG0018. SG0042 reports a `ProjectPath` that disagrees with
it and SG0043 a resource type that is not added by path.
- **Typed paths.** `<ResourceKitProject>` and `<ResourceKitPath>` items generate `AppHostProjects`
constants (`Name`, `Path`) to use on the attribute; RKP0001–RKP0003 report a missing path or an
invalid name.

## Next (unreleased)
## 2.0.0

- **Breaking: .NET 10 is the minimum.** The `net8.0` and `net9.0` targets are gone; a consuming AppHost
must be on `net10.0` or `net11.0`, and the package ships `lib/net10.0` (the floor) and
Expand Down
Loading
Loading