Update convention on how to ref and pack analyzers #78845
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
ProjectReferenceitem 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
AnalyzerReferencewhich is a repo custom item that doesn't tell you that behind the scenes it actually gets converted to aProjectReferencewith the same metadata as if you would declare that yourself as a P2P.To summarize the change: