Skip to content

Commit

Permalink
Revert "Fix ability for individual projects to enable or disable Cent…
Browse files Browse the repository at this point in the history
…ral Package Management (#5866)"

This reverts commit 4153cf1.
  • Loading branch information
kartheekp-ms committed Jul 3, 2024
1 parent 7a1e5b1 commit a4dc191
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ string FindMsbuildWithVsWhere()
internal CommandRunnerResult RunMsBuild(string workingDirectory, string args, bool ignoreExitCode = false, ITestOutputHelper testOutputHelper = null)
{
var restoreDllPath = Path.Combine(_testDir, "NuGet.Build.Tasks.dll");
var nugetRestorePropsPath = Path.Combine(_testDir, "NuGet.props");
var nugetRestoreTargetsPath = Path.Combine(_testDir, "NuGet.targets");

var result = CommandRunner.Run(_msbuildPath.Value,
workingDirectory,
$"/p:NuGetPropsFile={nugetRestorePropsPath} /p:NuGetRestoreTargets={nugetRestoreTargetsPath} /p:RestoreTaskAssemblyFile={restoreDllPath} /p:ImportNuGetBuildTasksPackTargetsFromSdk=true {args}",
$"/p:NuGetRestoreTargets={nugetRestoreTargetsPath} /p:RestoreTaskAssemblyFile={restoreDllPath} /p:ImportNuGetBuildTasksPackTargetsFromSdk=true {args}",
environmentVariables: _processEnvVars,
testOutputHelper: testOutputHelper);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1631,61 +1631,5 @@ await SimpleTestPackageUtility.CreatePackagesAsync(
replayedOutput.Should().Contain($"a known high severity vulnerability", Exactly.Twice());
replayedOutput.Should().Contain($"a known critical severity vulnerability", Exactly.Twice());
}

[Theory]
[InlineData(false, null)] // Disabled in Directory.Build.props, not set in Directory.Packages.props
[InlineData(false, false)] // Disabled in Directory.Build.props, disabled in Directory.Packages.props
[InlineData(null, false)] // Not set in Directory.Build.props, disabled in Directory.Packages.props
public async Task MsBuildRestore_WithCPMDisabled_IndividualProjectCanEnableCPM(bool? enabledInDirectoryBuildProps, bool? enabledInDirectoryPackagesProps)
{
// Arrange
using var pathContext = new SimpleTestPathContext();

var packageX = new SimpleTestPackageContext("x", "1.0.0");

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

// Directory.Build.props disables CPM which happens before Directory.Packages.props is imported
File.WriteAllText(
Path.Combine(pathContext.SolutionRoot, "Directory.Build.props"),
$@"<Project>
<PropertyGroup>
{(enabledInDirectoryBuildProps == true ? "<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>" : enabledInDirectoryBuildProps == false ? "<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>" : "")}
</PropertyGroup>
</Project>");

File.WriteAllText(
Path.Combine(pathContext.SolutionRoot, "Directory.Packages.props"),
$@"<Project>
<PropertyGroup>
{(enabledInDirectoryPackagesProps == true ? "<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>" : enabledInDirectoryPackagesProps == false ? "<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>" : "")}
</PropertyGroup>
<ItemGroup>
<PackageVersion Include=""{packageX.Id}"" Version=""{packageX.Version}"" />
</ItemGroup>
</Project>");

SimpleTestProjectContext projectA = SimpleTestProjectContext.CreateNETCoreWithSDK("a", pathContext.SolutionRoot, FrameworkConstants.CommonFrameworks.Net472.GetShortFolderName());

// The project enables CPM and Directory.Packages.props was already imported even if CPM was diabled
projectA.Properties.Add("ManagePackageVersionsCentrally", bool.TrueString);
projectA.Properties.Add("TreatWarningsAsErrors", bool.TrueString);

projectA.AddPackageToAllFrameworks(new SimpleTestPackageContext()
{
Id = packageX.Id,
Version = null
});

var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot, projectA);

solution.Create(pathContext.SolutionRoot);

// Act
CommandRunnerResult result = _msbuildFixture.RunMsBuild(pathContext.WorkingDirectory, $"/t:restore {projectA.ProjectPath}", ignoreExitCode: true, testOutputHelper: _testOutputHelper);

// Assert
result.Success.Should().BeTrue();
}
}
}

0 comments on commit a4dc191

Please sign in to comment.