Skip to content

Commit 16b30d6

Browse files
committed
Fixed the issue of missing async generated code when configuring multiple projects separately
1 parent ef11b00 commit 16b30d6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Source/AsyncGenerator/AsyncCodeGenerator.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@ public async Task GenerateAsync(AsyncCodeConfiguration configuration)
3939
throw new ArgumentNullException(nameof(configuration));
4040
}
4141
Logger.Info("Generating async code started");
42-
var props = new Dictionary<string, string>
43-
{
44-
["CheckForSystemRuntimeDependency"] = "true" // needed in order that project references are loaded
45-
};
46-
var workspace = MSBuildWorkspace.Create(props);
4742

4843
foreach (var config in configuration.SolutionConfigurations)
4944
{
45+
var workspace = CreateWorkspace();
5046
Logger.Info($"Configuring solution '{config.Path}' prior analyzation started");
5147
var solutionData = await CreateSolutionData(workspace, config).ConfigureAwait(false);
5248
Logger.Info($"Configuring solution '{config.Path}' prior analyzation completed");
@@ -59,10 +55,12 @@ public async Task GenerateAsync(AsyncCodeConfiguration configuration)
5955
{
6056
await ApplyChanges(workspace, solutionData.Solution).ConfigureAwait(false);
6157
}
58+
workspace.Dispose();
6259
}
6360

6461
foreach (var config in configuration.ProjectConfigurations)
6562
{
63+
var workspace = CreateWorkspace();
6664
Logger.Info($"Configuring project '{config.Path}' prior analyzation started");
6765
var projectData = await CreateProjectData(workspace, config).ConfigureAwait(false);
6866
Logger.Info($"Configuring project '{config.Path}' prior analyzation completed");
@@ -73,11 +71,21 @@ public async Task GenerateAsync(AsyncCodeConfiguration configuration)
7371
{
7472
await ApplyChanges(workspace, projectData.Project.Solution).ConfigureAwait(false);
7573
}
74+
workspace.Dispose();
7675
}
7776

7877
Logger.Info("Generating async code completed");
7978
}
8079

80+
private MSBuildWorkspace CreateWorkspace()
81+
{
82+
var props = new Dictionary<string, string>
83+
{
84+
["CheckForSystemRuntimeDependency"] = "true" // needed in order that project references are loaded
85+
};
86+
return MSBuildWorkspace.Create(props);
87+
}
88+
8189
private async Task GenerateProject(ProjectData projectData)
8290
{
8391
var analyzeConfig = projectData.Configuration.AnalyzeConfiguration;

0 commit comments

Comments
 (0)