Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the reading of the legacy algorithm property #5970

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<NuGetAuditMode>$(NuGetAuditMode)</NuGetAuditMode>
<SdkAnalysisLevel>$(SdkAnalysisLevel)</SdkAnalysisLevel>
<UsingMicrosoftNETSdk>$(UsingMicrosoftNETSdk)</UsingMicrosoftNETSdk>
<RestoreUseLegacyDependencyResolver>$(RestoreUseLegacyDependencyResolver)</RestoreUseLegacyDependencyResolver>
</_RestoreGraphEntry>
</ItemGroup>

Expand Down Expand Up @@ -1154,9 +1155,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<TargetPlatformMinVersion>$(TargetPlatformMinVersion)</TargetPlatformMinVersion>
<CLRSupport>$(CLRSupport)</CLRSupport>
<RuntimeIdentifierGraphPath>$(RuntimeIdentifierGraphPath)</RuntimeIdentifierGraphPath>
<WindowsTargetPlatformMinVersion>$(WindowsTargetPlatformMinVersion)</WindowsTargetPlatformMinVersion>
<RestoreUseLegacyDependencyResolver>$(RestoreUseLegacyDependencyResolver)</RestoreUseLegacyDependencyResolver>

<WindowsTargetPlatformMinVersion>$(WindowsTargetPlatformMinVersion)</WindowsTargetPlatformMinVersion>
</_RestoreGraphEntry>
</ItemGroup>
</Target>
Expand Down
2 changes: 1 addition & 1 deletion src/NuGet.Core/NuGet.ProjectModel/PackageSpecWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private static void WriteMetadataBooleans(IObjectWriter writer, ProjectRestoreMe
SetValueIfTrue(writer, "centralPackageVersionOverrideDisabled", msbuildMetadata.CentralPackageVersionOverrideDisabled);
SetValueIfTrue(writer, "CentralPackageTransitivePinningEnabled", msbuildMetadata.CentralPackageTransitivePinningEnabled);
SetValueIfFalse(writer, "UsingMicrosoftNETSdk", msbuildMetadata.UsingMicrosoftNETSdk);
SetValueIfTrue(writer, "restoreUseLegacyDependencyResolver ", msbuildMetadata.UseLegacyDependencyResolver);
SetValueIfTrue(writer, "restoreUseLegacyDependencyResolver", msbuildMetadata.UseLegacyDependencyResolver);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,5 +1822,45 @@ public async Task MsBuildRestore_WithCPMDisabled_IndividualProjectCanEnableCPM(b
// Assert
result.Success.Should().BeTrue();
}

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

var project = SimpleTestProjectContext.CreateLegacyPackageReference(
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse("net472"));

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

project.AddPackageToAllFrameworks(packageX);
solution.Projects.Add(project);
solution.Create(pathContext.SolutionRoot);

await SimpleTestPackageUtility.CreateFolderFeedV3Async(
pathContext.PackageSource,
packageX);

// Act
CommandRunnerResult result = _msbuildFixture.RunMsBuild(pathContext.WorkingDirectory, $"/t:restore {project.ProjectPath} /p:RestoreUseLegacyDependencyResolver=true" +
(isStaticGraphRestore ? " /p:RestoreUseStaticGraphEvaluation=true" : string.Empty),
ignoreExitCode: true,
testOutputHelper: _testOutputHelper);

// Assert
result.Success.Should().BeTrue(because: result.AllOutput);
project.AssetsFile.PackageSpec.RestoreMetadata.UseLegacyDependencyResolver.Should().BeTrue(because: result.AllOutput);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using FluentAssertions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NuGet.Common;
Expand Down Expand Up @@ -189,6 +188,7 @@ public void Write_ReadWriteWarningProperties()
""outputPath"": ""outputPath"",
""projectStyle"": ""PackageReference"",
""crossTargeting"": true,
""restoreUseLegacyDependencyResolver"": true,
""fallbackFolders"": [
""b"",
""a"",
Expand Down Expand Up @@ -817,20 +817,6 @@ public void RestoreMetadataWithMacros_RoundTrips()
var actual = PackageSpecTestUtility.RoundTripJson(json, environmentReader);

// Assert

var metadata = actual.RestoreMetadata;
var userSettingsDirectory = NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);

Assert.NotNull(metadata);
metadata.PackagesPath.Should().Be(@$"{userSettingsDirectory}.nuget\packages");

metadata.ConfigFilePaths.Should().Contain(@$"{userSettingsDirectory}source\code\NuGet.Config");
metadata.ConfigFilePaths.Should().Contain(@"C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config");
metadata.ConfigFilePaths.Should().Contain(@"C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config");
metadata.ConfigFilePaths.Should().Contain(@$"{userSettingsDirectory}AppData\Roaming\NuGet\NuGet.Config");

metadata.FallbackFolders.Should().Contain(@"C:\Program Files\dotnet\sdk\NuGetFallbackFolder");
metadata.FallbackFolders.Should().Contain(@$"{userSettingsDirectory}fallbackFolder");
}

private static string GetJsonString(PackageSpec packageSpec)
Expand Down
Loading