Skip to content
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

Merged
merged 2 commits into from
Jun 20, 2020

Conversation

chsienki
Copy link
Contributor

No description provided.

@chsienki chsienki added this to the 16.8 milestone Jun 17, 2020
@chsienki
Copy link
Contributor Author

@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")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!context.Compilation.ReferencedAssemblyNames.Any(ai => ai.Name.StartsWith("Newtonsoft.Json")))
if (!context.Compilation.ReferencedAssemblyNames.Any(ai => ai.Name.StartsWith("Newtonsoft.Json")))

Copy link
Member

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.
Copy link
Member

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.

@chsienki chsienki merged commit 5ae370f into dotnet:master Jun 20, 2020
@ghost ghost modified the milestones: 16.8, Next Jun 20, 2020
@dibarbet dibarbet modified the milestones: Next, 16.7.P4 Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants