Skip to content

Conversation

@ViktorHofer
Copy link
Member

Revival of #69237

d3af492 made it possible to reference and package an analyzer via the same msbuild item by setting custom metadata.

While reviewing other places that could use the AnalyzerReference item, I realized that using this custom item doesn't provide much value and creates an artificial difference to the rest of the stack and our customers as we don't adhere to our own documentation.

Instead, IMHO it makes much more sense to keep using a ProjectReference item with the documented set of required metadata, to reference an analyzer and just define an additional custom metadata to support packaging the analyzer: PackAsAnalyzer.
The reason for that is that the additional metadata explains how the reference works (no assembly output reference, added as an Analyzer output item) vs. the AnalyzerReference which is a repo custom item that doesn't tell you that behind the scenes it actually gets converted to a ProjectReference with the same metadata as if you would declare that yourself as a P2P.

To summarize the change:

  1. Consume an analyzer
<!-- Before -->
<AnalyzerReference Include="..." />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
  1. Pack an analyzer and consume it
<!-- Before -->
<AnalyzerReference Include="..." Pack="true" />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" OutputItemType="Analyzer" PackAsAnalyzer="true" />
  1. Pack an analyzer without consuming it
<!-- Before -->
<AnalyzerReference Include="..." Pack="true" ReferenceAnalyzer="false" />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" PackAsAnalyzer="true" />

@ghost
Copy link

ghost commented Nov 25, 2022

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Issue Details

Revival of #69237

d3af492 made it possible to reference and package an analyzer via the same msbuild item by setting custom metadata.

While reviewing other places that could use the AnalyzerReference item, I realized that using this custom item doesn't provide much value and creates an artificial difference to the rest of the stack and our customers as we don't adhere to our own documentation.

Instead, IMHO it makes much more sense to keep using a ProjectReference item with the documented set of required metadata, to reference an analyzer and just define an additional custom metadata to support packaging the analyzer: PackAsAnalyzer.
The reason for that is that the additional metadata explains how the reference works (no assembly output reference, added as an Analyzer output item) vs. the AnalyzerReference which is a repo custom item that doesn't tell you that behind the scenes it actually gets converted to a ProjectReference with the same metadata as if you would declare that yourself as a P2P.

To summarize the change:

  1. Consume an analyzer
<!-- Before -->
<AnalyzerReference Include="..." />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
  1. Pack an analyzer and consume it
<!-- Before -->
<AnalyzerReference Include="..." Pack="true" />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" OutputItemType="Analyzer" PackAsAnalyzer="true" />
  1. Pack an analyzer without consuming it
<!-- Before -->
<AnalyzerReference Include="..." Pack="true" ReferenceAnalyzer="false" />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" PackAsAnalyzer="true" />
Author: ViktorHofer
Assignees: ViktorHofer
Labels:

area-Infrastructure-libraries

Milestone: -

d3af492 made it possible to reference
and package an analyzer via the same msbuild item by setting custom
metadata.

While reviewing other places that could use the AnalyzerReference item,
I realized that using this custom item doesn't provide much value and
creates an artificial difference to the rest of the stack and our customers
[as we don't adhere to our own documentation](https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/#hello-world-source-generator-edition).

Instead, IMHO it makes much more sense to keep using a
`ProjectReference` item with the documented set of required metadata, to
reference an analyzer and just define an additional custom metadata to
support packaging the analyzer: `PackAsAnalyzer`.
The reason for that is that the additional metadata explains how the
reference works (no assembly output reference, added as an Analyzer
output item) vs. the `AnalyzerReference` which is a repo custom item
that doesn't tell you that behind the scenes it actually gets converted
to a `ProjectReference` with the same metadata as if you would declare
that yourself as a P2P.

To summarize the change:

1. Consume an analyzer
```xml
<!-- Before -->
<AnalyzerReference Include="..." />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
```

2. Pack an analyzer and consume it
```xml
<!-- Before -->
<AnalyzerReference Include="..." Pack="true" />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" OutputItemType="Analyzer" PackAsAnalyzer="true" />
```

3. Pack an analyzer without consuming it
```xml
<!-- Before -->
<AnalyzerReference Include="..." Pack="true" ReferenceAnalyzer="false" />
<!-- After -->
<ProjectReference Include="..." ReferenceOutputAssembly="false" PackAsAnalyzer="true" />
```
@ViktorHofer ViktorHofer force-pushed the ReferenceAnalyzersViaP2P branch from a42bec9 to 751260b Compare November 25, 2022 11:16
@ViktorHofer
Copy link
Member Author

The wasm failures are unrelated.

@ViktorHofer ViktorHofer merged commit 49dc7ba into main Nov 25, 2022
@ViktorHofer ViktorHofer deleted the ReferenceAnalyzersViaP2P branch November 25, 2022 16:06
@ghost ghost locked as resolved and limited conversation to collaborators Dec 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants