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
34 changes: 34 additions & 0 deletions .agents/prompts/sdk-packable-project-analyzer-defaults.prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
agent: ask
description: "Ensure the Purview.DotNetProjectSdk applies analyzer/source-generator best-practice defaults to packable projects, so consumers of Purview.SourceGeneratorFramework (and any Roslyn component) get correct packaging without per-project overrides."
---

You are working on the **Purview.DotNetProjectSdk** project (the `Purview.DotNetProjectSdk` package that projects import via `<Project Sdk="Purview.DotNetProjectSdk">`). Apply this checklist to its `Sdk.props` / `Sdk.targets` so that **packable** analyzer and source-generator projects get Roslyn best-practice defaults automatically.

## Context

The `Purview.SourceGeneratorFramework` guidance requires every analyzer/generator project to set these properties or the shipped analyzer asset is broken or unoptimised. Consumers should not have to set them per project. The SDK is the right place to default them.

## Task

For projects the SDK classifies as analyzers/source generators (`IsRoslynComponent`, or projects that produce `analyzers/dotnet/cs` assets) and that are packable, ensure the following are the **defaults** (still overridable by the project):

1. `TargetFramework=netstandard2.0` unless the project explicitly overrides it.
2. `LangVersion=latest` and `Nullable=enable`.
3. `IncludeBuildOutput=false` (so the library isn't packed as a `lib/` asset) and the analyzer/generator DLL packed into `analyzers/dotnet/cs`:
```xml
<None Include="$(TargetPath)" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
```
4. `EnforceExtendedAnalyzerRules=true` and `TreatWarningsAsErrors=true`.
5. Roslyn development dependencies (`Microsoft.CodeAnalysis.*`, `Microsoft.CodeAnalysis.Analyzers`) referenced with `PrivateAssets="all"`.

## Requirements

- Do not break existing projects that already set these explicitly; the SDK defaults must be overridable.
- Handle the distinction between packable and non-packable projects — only packable analyzer/generator projects get the analyzer-asset packaging.
- Ensure the defaults apply at the right evaluation point in the SDK (props vs targets) so project files can still override with normal `PropertyGroup` values.
- Verify with a consumer project that references a generator through the SDK that the packed `.nupkg` contains `analyzers/dotnet/cs/<assembly>.dll` and the `lib/` output is empty.

## Background

See the `source-generator-codewriter-modernization` skill's "Recommended project configuration" for the canonical generator project shape this SDK should default to.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"allowPrerelease": false
},
"msbuild-sdks": {
"Purview.DotNetProjectSdk": "1.0.0-prerelease.44"
"Purview.DotNetProjectSdk": "1.0.0-prerelease.45"
},
"test": {
"runner": "Microsoft.Testing.Platform"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "purview-sourcegeneratorframework",
"version": "1.0.0-prerelease.27",
"version": "1.0.0-prerelease.28",
"private": true
}
2 changes: 2 additions & 0 deletions src/SourceGeneratorFramework.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Project Path="src/SourceGeneratorShared/SourceGeneratorShared.csproj" />
</Folder>
<Folder Name="/src/examples/">
<Project Path="src/SourceGeneratorFramework.ExampleGenerator.CodeFixers/SourceGeneratorFramework.ExampleGenerator.CodeFixers.csproj" />
<Project Path="src/SourceGeneratorFramework.ExampleGenerator/SourceGeneratorFramework.ExampleGenerator.csproj" />
</Folder>
<Folder Name="/tests/">
Expand All @@ -36,6 +37,7 @@
<Project Path="tests/SourceGeneratorShared.UnitTests/SourceGeneratorShared.UnitTests.csproj" />
</Folder>
<Folder Name="/tests/examples/">
<Project Path="tests/SourceGeneratorFramework.ExampleGenerator.CodeFixers.UnitTests/SourceGeneratorFramework.ExampleGenerator.CodeFixers.UnitTests.csproj" />
<Project Path="tests/SourceGeneratorFramework.ExampleGenerator.UnitTests/SourceGeneratorFramework.ExampleGenerator.UnitTests.csproj" />
</Folder>
</Solution>
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
### New Rules

Rule ID | Category | Severity | Notes
--------|----------|----------|-------
PSGF001 | Purview.SourceGeneratorFramework | Error | Generation capabilities must be a record
PSGFR11 | Purview.SourceGeneratorFramework | Warning | Prefer ForAttributeWithMetadataName over CreateSyntaxProvider
PSGFR12 | Purview.SourceGeneratorFramework | Warning | Use IIncrementalGenerator instead of ISourceGenerator
PSGFR14 | Purview.SourceGeneratorFramework | Warning | Avoid RegisterImplementationSourceOutput
PSGFR15 | Purview.SourceGeneratorFramework | Warning | Pipeline model collection lacks sequence equality
ADM0010 | Property | Error | Attribute data model property type is not cacheable |
PSGFR16 | Purview.SourceGeneratorFramework | Info | Prefer the nullable-context overload
ADM0001 | Target | Error | Target attribute type cannot be resolved
ADM0002 | Property | Error | Property type is not supported for attribute extraction
ADM0003 | Source | Error | Specified constructor index/name does not exist on the target attribute
ADM0004 | NestedModel | Error | Nested model type is not annotated with GenerateAttributeDataModel
ADM0005 | DefaultValue | Error | Default value cannot be emitted for the property type
ADM0006 | DefaultValue | Error | Non-nullable reference type property requires a default value
ADM0007 | AutoDiscovery | Error | Auto-discovery requires a target attribute type
ADM0008 | TypeArgument | Error | Type argument property type must be TypeIdentity
ADM0009 | Property | Error | IsEnum property must be a string type
ADM0010 | Property | Error | Attribute data model property type is not cacheable |
Loading