purview-buildsdk-project-detection

Explain why Purview.BuildSdk classified a project as test, shared, shared-testing, CLI, web, worker, Aspire host, container or Roslyn component, and why it added a package, a project reference, a name

SKILL.md

GitHub

Why Purview.BuildSdk did that

Use this skill when the question is why the SDK applied something automatically.

For where a project should live, use purview-buildsdk-project-layout. For the property that turns a behaviour off, use purview-buildsdk-configuration.

Diagnose from computed properties, never from the folder name

Read what the SDK actually computed:

dotnet msbuild <project> -getProperty:PurviewLogicalProjectName -getProperty:RootNamespace \
  -getProperty:TestingType -getProperty:TargetProjectName -getProperty:IsTestProject

The values worth inspecting first: MSBuildProjectName, NamespacePrefix, PurviewLogicalProjectName, RootNamespace, TestingType, TargetProjectName, SdkProjectName, IsTestProject, IsSharedProject, IsServerSharedProject, IsClientSideProject, IsSharedTestingProject, IsContainerProject, IsCLIProject, IsWebSdkProject, IsAspireHostProject, IsBlazorWebAssemblyProject, IsRazorClassLibraryProject, IsBlazorHostProject, IsBffProject.

Detection rules

Test projects

Name matches ^.*\.([\w|_]\w*)Tests?$ — a target name, a dot, then any word before Test/Tests. The captured word becomes TestingType.

This is a pattern, not a lookup. MyProject.GoldenTests is detected exactly as readily as MyProject.UnitTests, with TestingType=Golden and Category=Golden, even though Golden is not a name the SDK ships.

The dot is required. A project named plainly UnitTests does not match, and silently gets no runner, no coverage, no InternalsVisibleTo and no category. This is the single most common surprise.

Derived: IsTestProject=true, TestingType=<suffix>, PurviewTestType=<TestingType>Tests, TargetProjectName=<name with the suffix removed>.

The SDK's explicit TestType item group governs InternalsVisibleTo generation, not detection: a non-test project grants access to {AssemblyName}.{TestType}Tests for each name in the group. A suffix outside it still builds, runs and gets a category — it just cannot see internal members. The 53 names are in references/test-types.md.

Shared, shared-testing and ServerShared projects

Recognised by exact name, never by substring. The three lists are in references/detection.md. Derived: IsSharedProject, IsSharedTestingProject, IsServerSharedProject.

ServerShared is separate from Shared for a reason: a Shared project is referenced by almost everything, including code that ends up in a browser, so server-only helpers get their own name and are referenced automatically only by a project that cannot be downloaded. IsClientSideProject is the classification that decides it.

SDK and content based

Signal Result
the project's Sdk="..." declaration IsSdkProject, SdkProjectName
Microsoft.NET.Sdk.Web IsWebSdkProject=true
Microsoft.NET.Sdk.Worker IsWorkerSdkProject=true
SDK starts with Aspire.Sdk.Host or Aspire.AppHost.Sdk, or the project references Aspire.Hosting.AppHost (Aspire 17+) IsAspireHostProject=true
Dockerfile, dockerfile or Dockerfile.dev in the project directory IsContainerProject=true
name ends with CLI, Console, CommandLine, QuickStart, QuickStarts IsCLIProject=true
Microsoft.NET.Sdk.BlazorWebAssembly IsBlazorWebAssemblyProject=true
Microsoft.NET.Sdk.Razor IsRazorClassLibraryProject=true
a web SDK project whose name ends with Bff (case-sensitive, like CLI), or that sets IsBffProject=true IsBffProject=true
a web SDK project that references an IsBlazorWebAssemblyProject project IsBlazorHostProject=true

IsAspireHostProject also matches Aspire 17's form: Microsoft.NET.Sdk plus an Aspire.Hosting.AppHost PackageReference in the project file. The package's own IsAspireHost is imported after this SDK, so the project file is what is read. A reference declared only in a shared props file is not detected; set IsAspireHostProject=true before the Sdk.props import to opt in.

IsBffProject=false opts a *Bff project out. IsBlazorHostProject is never inferred into IsBffProject: a host that keeps no tokens is not a BFF, and BFF rules do not describe it.

IsBlazorHostProject is known at evaluation for the <Name>/<Name>.Client pairing. A host referencing a client under any other name is resolved during the build, so ask for it with the target that resolves it:

dotnet msbuild <host> -t:ResolvePurviewBlazorHostProject -getProperty:IsBlazorHostProject

What each Blazor and BFF classification applies - and the browser-safe library check - is in references/blazor.md.

Target frameworks

A project that declares neither TargetFramework nor TargetFrameworks gets the SDK's default set, net10.0;net11.0 (Current). A PurviewTargetFrameworkSet (Current, Latest, Supported, Broad, All) resolves the same way; an unknown name fails with PurviewInvalidTargetFrameworkSet. A Roslyn component keeps netstandard2.0 and ignores the sets (PurviewTargetFrameworkSetIgnored).

An explicit TargetFramework or TargetFrameworks always wins, wherever it is set: one the SDK cannot see in the project XML (a Condition, an imported file, a Directory.Build.props value) is reconciled after the project body, before the .NET SDK decides whether to multi-target. PurviewTargetFrameworkSet is still read from the project XML, so a Condition on it is not seen and is reported as PurviewConditionedProjectDeclaration. See purview-buildsdk-configuration for how to set them.

Namespace and identity

  1. PurviewLogicalProjectName is NamespacePrefix plus the project name, de-duplicated when the project name already starts with the prefix's tail.
  2. RootNamespace defaults to PurviewLogicalProjectName.
  3. Known suffixes are stripped from RootNamespace in two passes: while Sdk.props evaluates, the shared, server-shared and shared-testing names plus Core, EF, Shared, ClientShared and ServiceDefaults; then, during the build, the wider NamespaceRemoveSuffix list (Infrastructure, Abstractions, Contracts, …). A RootNamespace declared in the project file is left as written.
  4. Test suffixes are stripped too, so Acme.Api.UnitTests maps back to Acme.Api.
  5. AssemblyName and PackageId default to the fully evaluated RootNamespace — except where stripping removed a segment, where they use the full PurviewLogicalProjectName so the artifact stays distinct from its parent. Test and shared-testing projects keep their detected suffix. Explicit AssemblyName/PackageId/RootNamespace always win.
  6. The naming defaults are applied during Sdk.props, before the Microsoft SDK computes TargetName, so the compiled output name always matches AssemblyName.

Automatic packages and references

  • Non-test C# projects: a SourceLink provider package (SourceLinkPackageName, default Microsoft.SourceLink.GitHub; DisableSourceLink=true opts out), the Purview telemetry packages (unless ExcludePurviewTelemetry), GenerateDocumentationFile=true, and InternalsVisibleTo generation (unless DisableAutoInternalsVisibleTo).
  • Test and shared-testing projects: test-friendly NoWarn defaults, not packable or publishable, and the packages selected by TestingFramework, SubstituteFramework and TestDataFramework. TUnit test projects get Microsoft.Testing.Platform wiring automatically. Shared-testing projects skip the runnable test package.
  • Packable projects, Roslyn components and special project types (CLI, container, web, Aspire host): see references/detection.md.
  • Blazor WebAssembly clients, Blazor hosts, BFFs and browser-safe libraries: see references/blazor.md.

Project-reference probing is layout-driven and covered by purview-buildsdk-project-layout.

The shipped analyzers

The SDK adds Purview.BuildSdk.Analyzers as an <Analyzer> item to every C# project, so its rules surface in command-line builds and in Visual Studio. The code-fix assembly ships beside it. The rules read the SDK's compiler-visible properties (build_property.*) rather than re-deriving project state — PDS0008/PDS0009, for example, are gated on build_property.IsBffProject. The exported set is in purview-buildsdk-configuration.

Rule What it enforces
PDS0002 Extensions classes live under Extensions/<receiver namespace>/
PDS0003 Explicit types with target-typed new()
PDS0004 Correct acronym capitalisation
PDS0008 A BFF's authentication cookie is not set HttpOnly = false
PDS0009 A BFF's authentication cookie is not set SameSite = None

PDS0004 follows .NET naming guidance: well-known framework spellings (Sql, Uuid, Url, Dns, Tcp, Http, Xml, Db, …) are exempt — Db among them, so DbContext, DbConnection and DbSet are never flagged. A small set is still uppercased: Api, Ai, Ui, Io, Os, Cpu, Gpu, Cli, Gui, Ram, Ssh, Dsl. Members mandated by a contract — interface implementations and base-class overrides — are never renamed.

Customise through dotnet_analyzer_configuration.pds0004.allowed_words (exempt segments), .acronym_map (segment renames, e.g. Sql:SQL, or Db:DB to re-enable it) and .allowed_identifiers (brand names, exact or word-boundary prefix, first match wins — CosmosDb covers CosmosDbServer). All three merge with and override the shipped defaults.

The shipped .editorconfig marks generated content (Migrations/, *.g.cs, Generated/, *.Designer.cs, obj/, bin/) as generated_code = true, and suppresses namespace-conflict diagnostics under Extensions/, so no #pragma suppressions are needed there.

Two Visual Studio refactorings ship with them, both described in references/detection.md.

When a classification is wrong

  1. Confirm the computed value with dotnet msbuild <project> -getProperty:<Flag> before changing anything.
  2. Prefer fixing the name or placement so the convention applies; keep the .csproj filename equal to its directory name.
  3. Otherwise set the flag explicitly before the SDK import (IsBffProject and IsClientSideProject can also be set in the project), and say why in a comment.