Skip to content

Commit fcb913e

Browse files
LSP: Fix batch builds for file-based programs and fix "dotnet.projects.binaryLogPath" throwing an exception (#78644)
Co-authored-by: Joey Robichaud <[email protected]>
1 parent 873ad37 commit fcb913e

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/Workspaces/MSBuild/BuildHost/Build/ProjectBuildManager.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ private static (MSB.Evaluation.Project? project, DiagnosticLog log) LoadProjectC
152152
{
153153
var projectCollection = new MSB.Evaluation.ProjectCollection(
154154
AllGlobalProperties,
155-
_msbuildLogger != null ? [_msbuildLogger] : ImmutableArray<MSB.Framework.ILogger>.Empty,
155+
// https://github.com/dotnet/msbuild/issues/11867: workaround LoggerException when passing binary logger to both evaluation and build
156+
loggers: [],
156157
MSB.Evaluation.ToolsetDefinitionLocations.Default);
157158
try
158159
{
@@ -171,18 +172,26 @@ private static (MSB.Evaluation.Project? project, DiagnosticLog log) LoadProjectC
171172
var log = new DiagnosticLog();
172173
try
173174
{
174-
var projectCollection = new MSB.Evaluation.ProjectCollection(
175-
AllGlobalProperties,
176-
_msbuildLogger != null ? [_msbuildLogger] : ImmutableArray<MSB.Framework.ILogger>.Empty,
177-
MSB.Evaluation.ToolsetDefinitionLocations.Default);
178-
try
175+
if (BatchBuildStarted)
179176
{
180-
return LoadProjectCore(path, readStream, projectCollection, log);
177+
return LoadProjectCore(path, readStream, _batchBuildProjectCollection, log);
181178
}
182-
finally
179+
else
183180
{
184-
// unload project so collection will release global strings
185-
projectCollection.UnloadAllProjects();
181+
var projectCollection = new MSB.Evaluation.ProjectCollection(
182+
AllGlobalProperties,
183+
// https://github.com/dotnet/msbuild/issues/11867: workaround LoggerException when passing binary logger to both evaluation and build
184+
loggers: [],
185+
MSB.Evaluation.ToolsetDefinitionLocations.Default);
186+
try
187+
{
188+
return LoadProjectCore(path, readStream, projectCollection, log);
189+
}
190+
finally
191+
{
192+
// unload project so collection will release global strings
193+
projectCollection.UnloadAllProjects();
194+
}
186195
}
187196
}
188197
catch (Exception e)
@@ -228,7 +237,8 @@ public void StartBatchBuild(IDictionary<string, string>? globalProperties = null
228237
? [_msbuildLogger]
229238
: ImmutableArray<MSB.Framework.ILogger>.Empty;
230239

231-
_batchBuildProjectCollection = new MSB.Evaluation.ProjectCollection(allProperties, loggers, MSB.Evaluation.ToolsetDefinitionLocations.Default);
240+
// Pass empty loggers array to workaround LoggerException when passing binary logger to both evaluation and build. See https://github.com/dotnet/msbuild/issues/11867
241+
_batchBuildProjectCollection = new MSB.Evaluation.ProjectCollection(allProperties, loggers: [], MSB.Evaluation.ToolsetDefinitionLocations.Default);
232242

233243
var buildParameters = new MSB.Execution.BuildParameters(_batchBuildProjectCollection)
234244
{

0 commit comments

Comments
 (0)