-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NuGet and analyzer config scenarios to SG cookbook #45261
Conversation
@dotnet/roslyn-compiler for review please :) |
public void Execute(SourceGeneratorContext context) | ||
{ | ||
// check that the users compilation references the expected library | ||
if(!context.Compilation.ReferencedAssemblyNames.Any(ai => ai.Name.StartsWith("Newtonsoft.Json"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(!context.Compilation.ReferencedAssemblyNames.Any(ai => ai.Name.StartsWith("Newtonsoft.Json"))) | |
if (!context.Compilation.ReferencedAssemblyNames.Any(ai => ai.Name.StartsWith("Newtonsoft.Json"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of StartsWith
should use a full equality check
} | ||
``` | ||
|
||
However, any *compile-time* dependencies, that is, used by the generator while it is is running, must be packaged directly alongside the generator assembly inside the generator NuGet package. There are no automatic facilities for this, and you will need to manually specify the dependencies to include. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this is a bit confusing because there are two interpretations of compile-time here: when the generator is compiled or when the code consuming the generator is compiled. Would be clearer to express this scenario as the generator execution.
No description provided.