Commit d751cbe
[cDAC] Pack DataGenerator as analyzer asset in Abstractions nupkg (#128903)
> [!NOTE]
> This PR description was AI-generated with GitHub Copilot CLI.
## Summary
Packs the cDAC source generator
(`Microsoft.Diagnostics.DataContractReader.DataGenerator`) as an
analyzer asset inside the
`Microsoft.Diagnostics.DataContractReader.Abstractions` transport NuGet
package, so downstream consumers pick the generator up automatically via
`PackageReference` — no in-repo `ProjectReference` to the generator
csproj required.
## Changes
- **Moved**
`src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.DataGenerator/`
→ `src/native/managed/cdac/gen/`. The repo-wide `Directory.Build.props`
auto-detects projects under `gen/` and sets `IsGeneratorProject=true`,
which imports `eng/generatorProjects.targets` (providing the
`GetAnalyzerPackFiles` target that `PackAsAnalyzer="true"` relies on).
- **Wired** the generator into `Abstractions.csproj` via
`<ProjectReference ... ReferenceOutputAssembly="false"
PackAsAnalyzer="true" />`. The compiled generator dll ships under
`analyzers/dotnet/cs/` in the transport nupkg.
- **Cleanup** in the generator csproj: dropped `IsSourceProject=false`
and `EnforceExtendedAnalyzerRules=true` overrides that are now redundant
under the `gen/` convention.
- **Updated** `Contracts.csproj` and `DataGeneratorTests.csproj`
`ProjectReference` paths to the new location.
## Generator bug fixes (uncovered by external `PackageReference`
consumption)
1. `LayoutPair` / `TypeNameResolver` emission gate used
`GetTypeByMetadataName(...) is null`, which suppressed emission whenever
the type was *present in metadata* even if **not accessible** to the
current compilation (internal type in a referenced assembly without
`InternalsVisibleTo`). Replaced with an `IsSymbolAccessibleWithin` check
so external consumers get their own internal copy generated.
2. The singular `GetTypeByMetadataName` returns null on cross-assembly
duplicates (more than one referenced assembly exposes the same internal
helper). Switched to plural `GetTypesByMetadataName` + `Any(accessible)`
so the gate behaves correctly in that case.
These bugs do not affect the in-repo `Contracts` build (it has
`InternalsVisibleTo` to itself and sees a single copy), only external
`PackageReference` consumers.
## Validation
- In-repo cDAC build and `DataGeneratorTests` continue to use the
generator via `ProjectReference OutputItemType="Analyzer"` (unchanged
behavior).
- Abstractions nupkg now contains
`analyzers/dotnet/cs/Microsoft.Diagnostics.DataContractReader.DataGenerator.dll`.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 5341027 commit d751cbe
13 files changed
Lines changed: 47 additions & 11 deletions
File tree
- src/native/managed/cdac
- Microsoft.Diagnostics.DataContractReader.Abstractions
- Microsoft.Diagnostics.DataContractReader.Contracts
- gen
- tests/DataGenerator
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
14 | 29 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
Lines changed: 20 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
70 | 88 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
3 | 9 | | |
4 | 10 | | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
8 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
9 | 17 | | |
10 | 18 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 19 | | |
16 | | - | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
0 commit comments