Skip to content

Commit

Permalink
Remove missing project references in static graph-based restore
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Feb 28, 2023
1 parent 1b9af3b commit 2603999
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,9 @@ private DependencyGraphSpec GetDependencyGraphSpec(string entryProjectPath, IDic
// Fix project reference casings to match the original project on case insensitive file systems.
MSBuildRestoreUtility.NormalizePathCasings(projectPathLookup, dependencyGraphSpec);

// Remove references to projects that could not be read by restore.
MSBuildRestoreUtility.RemoveMissingProjects(dependencyGraphSpec);

// Add all entry projects if they support restore. In most cases this is just a single project but if the entry
// project is a solution, then all projects in the solution are added (if they support restore)
foreach (var entryPoint in entryProjects)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,56 @@ public void MsbuildRestore_StaticGraphEvaluation_HandlesInvalidProjectFileExcept
}
}

[PlatformTheory(Platform.Windows)]
[InlineData(true)]
[InlineData(false)]
public void MsbuildRestore_WithMissingProjectReferences_HandlesProjectReferencesToUnsupportedProjects(bool restoreUseStaticGraphEvaluation)
{
// Arrange
using (var pathContext = new SimpleTestPathContext())
{
// Set up solution, project, and packages
var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot);

NuGetFramework targetFramework = NuGetFramework.Parse("net461");

var projectA = new SimpleTestProjectContext("ProjectA", ProjectStyle.PackageReference, pathContext.SolutionRoot)
{
ToolingVersion15 = true
};

var projectB = new SimpleTestProjectContext("b", ProjectStyle.PackageReference, pathContext.SolutionRoot);

var projectAFrameworkContext = new SimpleTestProjectFrameworkContext(targetFramework);

projectAFrameworkContext.ProjectReferences.Add(projectB);

var packageX = new SimpleTestPackageContext()
{
Id = "x",
Version = "1.0.0"
};

projectA.Frameworks.Add(projectAFrameworkContext);

projectA.AddPackageToAllFrameworks(packageX);

solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);

File.WriteAllText(
projectB.ProjectPath,
@"<Project />");

var result = _msbuildFixture.RunMsBuild(pathContext.WorkingDirectory, $"/t:restore /p:RestoreUseStaticGraphEvaluation={restoreUseStaticGraphEvaluation} {projectA.ProjectPath}", ignoreExitCode: true);

// Assert
result.ExitCode.Should().Be(0, result.AllOutput);

//result.AllOutput.Should().Contain($"error MSB4025: The project file could not be loaded. Could not find file '{projectB.ProjectPath}'");
}
}

[PlatformTheory(Platform.Windows)]
[InlineData(true)]
[InlineData(false)]
Expand Down

0 comments on commit 2603999

Please sign in to comment.