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

AddToWorkspace doesn't support source generators #157

Closed
svick opened this issue Dec 3, 2020 · 1 comment · Fixed by #158
Closed

AddToWorkspace doesn't support source generators #157

svick opened this issue Dec 3, 2020 · 1 comment · Fixed by #158

Comments

@svick
Copy link
Contributor

svick commented Dec 3, 2020

Consider the following code (where C:\code\roslyn-sdk is a path to checked out dotnet/roslyn-sdk):

var manager = new AnalyzerManager();
var analyzer = manager.GetProject(@"C:\code\roslyn-sdk\samples\CSharp\SourceGenerators\GeneratedDemo\GeneratedDemo.csproj");
AdhocWorkspace workspace = new AdhocWorkspace();
Project roslynProject = analyzer.AddToWorkspace(workspace);

foreach (var analyzerReference in roslynProject.AnalyzerReferences)
{
    Console.WriteLine(analyzerReference.FullPath);
}

This does not print anything; roslynProject.AnalyzerReferences is empty.

What I expect is that it prints references to source generator assemblies used by the project:

C:\Users\PetrOnderka\.nuget\packages\csvtextfieldparser\1.2.2-preview\lib\netstandard2.0\CsvTextFieldParser.dll
C:\Users\PetrOnderka\.nuget\packages\handlebars.net\1.10.1\lib\netstandard2.0\Handlebars.dll
C:\Users\PetrOnderka\.nuget\packages\newtonsoft.json\12.0.1\lib\netstandard2.0\Newtonsoft.Json.dll
C:\code\roslyn-sdk\artifacts\bin\SourceGeneratorSamples\Debug\netstandard2.0\SourceGeneratorSamples.dll

I plan to submit a PR that fixes this soon.

@daveaglick
Copy link
Collaborator

Cool! Never even considered adding analyzers and generators to the workspace, but if Roslyn tracks them it definitely makes sense to add them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants