Skip to content

Commit 547da40

Browse files
jjonesczgithub-actions
authored andcommitted
Ensure all evaluation data are in binlogs from file-based apps
1 parent d90167a commit 547da40

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ public override int Execute()
201201
}
202202

203203
Dictionary<string, string?> savedEnvironmentVariables = [];
204-
ProjectCollection? projectCollection = null;
205204
try
206205
{
207206
// Set environment variables.
@@ -213,7 +212,7 @@ public override int Execute()
213212

214213
// Set up MSBuild.
215214
ReadOnlySpan<ILogger> binaryLoggers = binaryLogger is null ? [] : [binaryLogger];
216-
projectCollection = new ProjectCollection(
215+
var projectCollection = new ProjectCollection(
217216
MSBuildArgs.GlobalProperties,
218217
[.. binaryLoggers, consoleLogger],
219218
ToolsetDefinitionLocations.Default);
@@ -223,19 +222,23 @@ public override int Execute()
223222
LogTaskInputs = binaryLoggers.Length != 0,
224223
};
225224

225+
// Projects need to be created before BeginBuild is called, otherwise binlog doesn't contain evaluation data.
226+
var restoreProject = NoRestore ? null : CreateProjectInstance(projectCollection, addGlobalProperties: AddRestoreGlobalProperties(MSBuildArgs.RestoreGlobalProperties));
227+
var buildProject = NoBuild ? null : CreateProjectInstance(projectCollection);
228+
229+
BuildManager.DefaultBuildManager.BeginBuild(parameters);
230+
226231
// Do a restore first (equivalent to MSBuild's "implicit restore", i.e., `/restore`).
227232
// See https://github.com/dotnet/msbuild/blob/a1c2e7402ef0abe36bf493e395b04dd2cb1b3540/src/MSBuild/XMake.cs#L1838
228233
// and https://github.com/dotnet/msbuild/issues/11519.
229-
if (!NoRestore)
234+
if (restoreProject != null)
230235
{
231236
var restoreRequest = new BuildRequestData(
232-
CreateProjectInstance(projectCollection, addGlobalProperties: AddRestoreGlobalProperties(MSBuildArgs.RestoreGlobalProperties)),
237+
restoreProject,
233238
targetsToBuild: ["Restore"],
234239
hostServices: null,
235240
BuildRequestDataFlags.ClearCachesAfterBuild | BuildRequestDataFlags.SkipNonexistentTargets | BuildRequestDataFlags.IgnoreMissingEmptyAndInvalidImports | BuildRequestDataFlags.FailOnUnresolvedSdk);
236241

237-
BuildManager.DefaultBuildManager.BeginBuild(parameters);
238-
239242
var restoreResult = BuildManager.DefaultBuildManager.BuildRequest(restoreRequest);
240243
if (restoreResult.OverallResult != BuildResultCode.Success)
241244
{
@@ -244,18 +247,12 @@ public override int Execute()
244247
}
245248

246249
// Then do a build.
247-
if (!NoBuild)
250+
if (buildProject != null)
248251
{
249252
var buildRequest = new BuildRequestData(
250-
CreateProjectInstance(projectCollection),
253+
buildProject,
251254
targetsToBuild: MSBuildArgs.RequestedTargets ?? ["Build"]);
252255

253-
// For some reason we need to BeginBuild after creating BuildRequestData otherwise the binlog doesn't contain Evaluation.
254-
if (NoRestore)
255-
{
256-
BuildManager.DefaultBuildManager.BeginBuild(parameters);
257-
}
258-
259256
var buildResult = BuildManager.DefaultBuildManager.BuildRequest(buildRequest);
260257
if (buildResult.OverallResult != BuildResultCode.Success)
261258
{

test/dotnet.Tests/CommandTests/Run/RunFileTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,8 @@ public void BinaryLog_EvaluationData()
939939
new FileInfo(binaryLogPath).Should().Exist();
940940

941941
var records = BinaryLog.ReadRecords(binaryLogPath).ToList();
942-
records.Any(static r => r.Args is ProjectEvaluationStartedEventArgs).Should().BeTrue();
943-
records.Any(static r => r.Args is ProjectEvaluationFinishedEventArgs).Should().BeTrue();
942+
records.Count(static r => r.Args is ProjectEvaluationStartedEventArgs).Should().Be(2);
943+
records.Count(static r => r.Args is ProjectEvaluationFinishedEventArgs).Should().Be(2);
944944
}
945945

946946
/// <summary>

0 commit comments

Comments
 (0)