|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
| 4 | +#nullable enable |
| 5 | + |
4 | 6 | using System.Diagnostics; |
5 | 7 | using Microsoft.Build.Evaluation; |
6 | 8 | using Microsoft.Build.Exceptions; |
@@ -275,6 +277,8 @@ private void EnsureProjectIsBuilt(out Func<ProjectCollection, ProjectInstance>? |
275 | 277 | } |
276 | 278 | else |
277 | 279 | { |
| 280 | + Debug.Assert(ProjectFileFullPath is not null); |
| 281 | + |
278 | 282 | projectFactory = null; |
279 | 283 | buildResult = new RestoringCommand( |
280 | 284 | RestoreArgs.Prepend(ProjectFileFullPath), |
@@ -336,9 +340,14 @@ static ProjectInstance EvaluateProject(string? projectFilePath, Func<ProjectColl |
336 | 340 | AddUserPassedProperties(globalProperties, restoreArgs); |
337 | 341 |
|
338 | 342 | var collection = new ProjectCollection(globalProperties: globalProperties, loggers: binaryLogger is null ? null : [binaryLogger], toolsetDefinitionLocations: ToolsetDefinitionLocations.Default); |
339 | | - return projectFilePath is not null |
340 | | - ? collection.LoadProject(projectFilePath).CreateProjectInstance() |
341 | | - : projectFactory(collection); |
| 343 | + |
| 344 | + if (projectFilePath is not null) |
| 345 | + { |
| 346 | + return collection.LoadProject(projectFilePath).CreateProjectInstance(); |
| 347 | + } |
| 348 | + |
| 349 | + Debug.Assert(projectFactory is not null); |
| 350 | + return projectFactory(collection); |
342 | 351 | } |
343 | 352 |
|
344 | 353 | static void ValidatePreconditions(ProjectInstance project) |
@@ -608,9 +617,10 @@ private static void ThrowUnableToRunError(ProjectInstance project) |
608 | 617 |
|
609 | 618 | private static string? DiscoverProjectFilePath(string? projectFileOrDirectoryPath, ref string[] args, out string? entryPointFilePath) |
610 | 619 | { |
611 | | - bool emptyProjectOption = string.IsNullOrWhiteSpace(projectFileOrDirectoryPath); |
612 | | - if (emptyProjectOption) |
| 620 | + bool emptyProjectOption = false; |
| 621 | + if (string.IsNullOrWhiteSpace(projectFileOrDirectoryPath)) |
613 | 622 | { |
| 623 | + emptyProjectOption = true; |
614 | 624 | projectFileOrDirectoryPath = Directory.GetCurrentDirectory(); |
615 | 625 | } |
616 | 626 |
|
|
0 commit comments