Skip to content

Commit cab1a35

Browse files
Sergio0694Copilot
andcommitted
Correct reference assembly mechanism in skills/instructions
Update copilot-instructions.md and the interop-generator and update-copilot-instructions skills to describe the actual mechanism used to build the WinRT.Runtime reference assembly: the WINDOWS_RUNTIME_REFERENCE_ASSEMBLY and WINDOWS_RUNTIME_IMPLEMENTATION_ASSEMBLY define constants, the [WindowsRuntimeImplementationOnlyMember] attribute (which triggers MSBuild file removal), the #define WINDOWS_RUNTIME_IMPLEMENTATION_ONLY_FILE opt-out, and the wholesale folder removals. Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 22558e8 commit cab1a35

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ The runtime library (`WinRT.Runtime.dll`) provides all common infrastructure for
167167
- **Warnings as errors**: release only. `EnforceCodeStyleInBuild` enabled, `AnalysisLevelStyle` = `latest-all`.
168168
- **Strong-name signed** with `key.snk`
169169
- **AOT compatible**: `IsAotCompatible = true`
170-
- **Reference assembly**: the project is built twice for NuGet packaging. With `CsWinRTBuildReferenceAssembly=true`, it produces a reference assembly (for `ref\net10.0\` in the NuGet) that strips all private implementation detail types and members via `#if !REFERENCE_ASSEMBLY`. The normal build produces the full implementation assembly (for `lib\net10.0\`). This replaces the previous approach of marking implementation details with `[Obsolete]` and `[EditorBrowsable(Never)]` attributes.
170+
- **Reference assembly**: the project is built twice for NuGet packaging. With `CsWinRTBuildReferenceAssembly=true`, it produces a reference assembly (for `ref\net10.0\` in the NuGet) that strips all private implementation detail types and members. The normal build produces the full implementation assembly (for `lib\net10.0\`) and defines `WINDOWS_RUNTIME_IMPLEMENTATION_ASSEMBLY`; the reference assembly build defines `WINDOWS_RUNTIME_REFERENCE_ASSEMBLY` instead. Stripping is driven primarily by the `[WindowsRuntimeImplementationOnlyMember]` attribute (a `[Conditional("WINDOWS_RUNTIME_REFERENCE_ASSEMBLY")]` marker on top-level types) plus an MSBuild target that removes any source file containing that attribute, any file with a top-of-file `#define WINDOWS_RUNTIME_IMPLEMENTATION_ONLY_FILE`, and entire implementation-only folders (e.g. `ABI\`, `NativeObjects\`, most `InteropServices\` subfolders). Method bodies remaining in the reference assembly are stubbed with `throw null`. This replaces the previous approach of marking implementation details with `[Obsolete]` and `[EditorBrowsable(Never)]` attributes.
171171

172172
**Directory structure:**
173173

.github/skills/interop-generator/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ The `WinRT.Interop.dll` assembly is produced by `cswinrtinteropgen`, which is a
3232
- If a project **does not** reference CsWinRT, then `cswinrtinteropgen` is loaded from the Windows SDK projections targeting pack.
3333
- If CsWinRT **is** referenced (directly or transitively), then `cswinrtinteropgen` is loaded from that package, but only if the `WinRT.Runtime.dll` binary from that package has a higher version than the one in the Windows SDK projections package being referenced. This correctly handles cases where a dependent project might have a reference to an outdated CsWinRT package.
3434

35-
This version matching is critical because `cswinrtinteropgen` relies on internal implementation detail APIs in `WinRT.Runtime.dll` — APIs which are public in the implementation assembly but excluded from the reference assembly (via `#if !REFERENCE_ASSEMBLY`), and which are exclusively meant to be consumed by generated code produced by `cswinrtinteropgen`. These APIs might change at any time without following semantic versioning for CsWinRT. For instance, they are crucial to support marshalling generic Windows Runtime collection interfaces, and the code in `WinRT.Interop.dll` makes heavy use of them in this scenario.
35+
This version matching is critical because `cswinrtinteropgen` relies on internal implementation detail APIs in `WinRT.Runtime.dll` — APIs which are public in the implementation assembly but excluded from the reference assembly (via the `[WindowsRuntimeImplementationOnlyMember]` attribute and related MSBuild stripping, controlled by the `WINDOWS_RUNTIME_REFERENCE_ASSEMBLY` / `WINDOWS_RUNTIME_IMPLEMENTATION_ASSEMBLY` define constants), and which are exclusively meant to be consumed by generated code produced by `cswinrtinteropgen`. These APIs might change at any time without following semantic versioning for CsWinRT. For instance, they are crucial to support marshalling generic Windows Runtime collection interfaces, and the code in `WinRT.Interop.dll` makes heavy use of them in this scenario.
3636

3737
### Private implementation detail APIs
3838

39-
`WinRT.Runtime.dll` is shipped as two assemblies in the CsWinRT NuGet package: a **reference assembly** (in `ref\net10.0\`) that exposes only the versioned public API surface, and an **implementation assembly** (in `lib\net10.0\`) that contains the full set of types and members. Many types in the implementation assembly are "public" only because generated code in other assemblies (produced by `cswinrt.exe` and `cswinrtinteropgen`) needs to call them — they are not part of the stable API contract. These types are stripped from the reference assembly via `#if !REFERENCE_ASSEMBLY`, so consumers never see them.
39+
`WinRT.Runtime.dll` is shipped as two assemblies in the CsWinRT NuGet package: a **reference assembly** (in `ref\net10.0\`) that exposes only the versioned public API surface, and an **implementation assembly** (in `lib\net10.0\`) that contains the full set of types and members. Many types in the implementation assembly are "public" only because generated code in other assemblies (produced by `cswinrt.exe` and `cswinrtinteropgen`) needs to call them — they are not part of the stable API contract. These types are stripped from the reference assembly via the `[WindowsRuntimeImplementationOnlyMember]` attribute (a `[Conditional("WINDOWS_RUNTIME_REFERENCE_ASSEMBLY")]` marker that triggers an MSBuild target to remove the entire source file), an opt-in `#define WINDOWS_RUNTIME_IMPLEMENTATION_ONLY_FILE` directive at the top of a source file, or wholesale folder removals (e.g. `ABI\`, `NativeObjects\`, most `InteropServices\` subfolders), so consumers never see them. Method bodies that remain in the reference assembly are stubbed with `throw null`.
4040

4141
The interop generator receives a reference to the **implementation** `WinRT.Runtime.dll` (not the reference assembly) so that it can resolve and emit calls to these internal APIs. Examples of private implementation detail types that the interop generator uses heavily include:
4242

.github/skills/update-copilot-instructions/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Launch parallel explore agents for each of the 8 CsWinRT 3.0 projects listed in
2626
- Key types listed still exist and have the described purposes
2727
- T4 templates (`.tt` files) are accurately listed
2828
- Project settings (TFM, language version, nullable, unsafe, etc.) are current
29-
- Reference assembly build setup (`CsWinRTBuildReferenceAssembly`, `#if !REFERENCE_ASSEMBLY`) is accurately described
29+
- Reference assembly build setup (`CsWinRTBuildReferenceAssembly`, `WINDOWS_RUNTIME_REFERENCE_ASSEMBLY` / `WINDOWS_RUNTIME_IMPLEMENTATION_ASSEMBLY` defines, `[WindowsRuntimeImplementationOnlyMember]` attribute, `#define WINDOWS_RUNTIME_IMPLEMENTATION_ONLY_FILE` opt-out) is accurately described
3030
- Namespace organization matches
3131

3232
2. **WinRT.SourceGenerator2 (`src/Authoring/WinRT.SourceGenerator2/`)**

0 commit comments

Comments
 (0)