diff --git a/src/NuGet.Core/NuGet.Build.Tasks/NuGet.props b/src/NuGet.Core/NuGet.Build.Tasks/NuGet.props
index fe44d8077cb..cec99ecbab5 100644
--- a/src/NuGet.Core/NuGet.Build.Tasks/NuGet.props
+++ b/src/NuGet.Core/NuGet.Build.Tasks/NuGet.props
@@ -9,32 +9,33 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
+
+
-
- <_DirectoryPackagesPropsFile Condition="'$(_DirectoryPackagesPropsFile)' == ''">Directory.Packages.props
- <_DirectoryPackagesPropsBasePath Condition="'$(_DirectoryPackagesPropsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', '$(_DirectoryPackagesPropsFile)'))
- $([MSBuild]::NormalizePath('$(_DirectoryPackagesPropsBasePath)', '$(_DirectoryPackagesPropsFile)'))
+
+
+ true
-
- true
+
+ <_DirectoryPackagesPropsFile Condition="'$(_DirectoryPackagesPropsFile)' == ''">Directory.Packages.props
+ <_DirectoryPackagesPropsBasePath Condition="'$(_DirectoryPackagesPropsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', '$(_DirectoryPackagesPropsFile)'))
+ $([MSBuild]::NormalizePath('$(_DirectoryPackagesPropsBasePath)', '$(_DirectoryPackagesPropsFile)'))
-
+
-
+
true
+
diff --git a/test/EndToEnd/Directory.Packages.props b/test/EndToEnd/Directory.Packages.props
index 5f9708a97f3..42309161647 100644
--- a/test/EndToEnd/Directory.Packages.props
+++ b/test/EndToEnd/Directory.Packages.props
@@ -1,5 +1 @@
-
-
- false
-
-
+
\ No newline at end of file
diff --git a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs
index de825b2c0a8..785fe705cfa 100644
--- a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs
+++ b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs
@@ -9186,6 +9186,7 @@ public async Task RestoreNetCore_CPVMProject_DirectDependencyCentralVersionChang
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse("net46"));
+ projectA.Properties.Add("ManagePackageVersionsCentrally", "true");
projectA.Properties.Add("RestoreLockedMode", "true");
projectA.Properties.Add("RestorePackagesWithLockFile", "true");
@@ -9270,6 +9271,7 @@ public async Task RestoreNetCore_CPVMProject_TransitiveDependencyCentralVersionC
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse("net46"));
+ projectA.Properties.Add("ManagePackageVersionsCentrally", "true");
projectA.Properties.Add("RestoreLockedMode", "true");
projectA.Properties.Add("RestorePackagesWithLockFile", "true");
@@ -9352,6 +9354,7 @@ public async Task RestoreNetCore_CPVMProject_RemovedCentralDirectDependency_Fail
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse("net46"));
+ projectA.Properties.Add("ManagePackageVersionsCentrally", "true");
projectA.Properties.Add("RestoreLockedMode", "true");
projectA.Properties.Add("RestorePackagesWithLockFile", "true");
@@ -9425,6 +9428,7 @@ public async Task RestoreNetCore_CPVMProject_RemovedCentralTransitiveDependency_
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse("net46"));
+ projectA.Properties.Add("ManagePackageVersionsCentrally", "true");
projectA.Properties.Add("RestoreLockedMode", "true");
projectA.Properties.Add("RestorePackagesWithLockFile", "true");
@@ -9498,6 +9502,7 @@ public async Task RestoreNetCore_CPVMProject_MoveTransitiveDependnecyToCentralFi
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse("net46"));
+ projectA.Properties.Add("ManagePackageVersionsCentrally", "true");
projectA.Properties.Add("RestoreLockedMode", "true");
projectA.Properties.Add("RestorePackagesWithLockFile", "true");
@@ -9570,6 +9575,7 @@ public async Task RestoreNetCore_CPVMProject_AddRemoveNotProjectRelatedEntriesTo
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse("net46"));
+ projectA.Properties.Add("ManagePackageVersionsCentrally", "true");
projectA.Properties.Add("RestoreLockedMode", "true");
projectA.Properties.Add("RestorePackagesWithLockFile", "true");
@@ -9672,16 +9678,19 @@ public async Task RestoreNetCore_CPVMProject_DowngradedByCentralDirectDependency
"a",
pathContext.SolutionRoot,
netcoreapp2);
+ projectA.Properties.Add("ManagePackageVersionsCentrally", "true");
var projectB = SimpleTestProjectContext.CreateNETCore(
"b",
pathContext.SolutionRoot,
netcoreapp2);
+ projectB.Properties.Add("ManagePackageVersionsCentrally", "true");
var projectC = SimpleTestProjectContext.CreateNETCore(
"c",
pathContext.SolutionRoot,
netcoreapp2);
+ projectC.Properties.Add("ManagePackageVersionsCentrally", "true");
var packageX100 = new SimpleTestPackageContext()
{
@@ -9814,7 +9823,8 @@ SimpleTestPackageContext createTestPackage(string name, string version, List $"{l.Name}.{l.Version}").OrderBy(n => n).ToList();
Assert.Equal(expectedLibraries, libraries);
- var centralFileDependencyGroups = assetsFile
+ var centralfileDependencyGroups = assetsFile
.CentralTransitiveDependencyGroups
.SelectMany(g => g.TransitiveDependencies.Select(t => $"{g.FrameworkName}_{t.LibraryRange.Name}.{t.LibraryRange.VersionRange.OriginalString}")).ToList();
- var expectedCentralFileDependencyGroups = new List() { $"{framework.DotNetFrameworkName}_P.[3.0.0, )", $"{framework.DotNetFrameworkName}_S.[3.0.0, )" };
+ var expectedCentralfileDependencyGroups = new List() { $"{framework.DotNetFrameworkName}_P.[3.0.0, )", $"{framework.DotNetFrameworkName}_S.[3.0.0, )" };
- Assert.Equal(expectedCentralFileDependencyGroups, centralFileDependencyGroups);
+ Assert.Equal(expectedCentralfileDependencyGroups, centralfileDependencyGroups);
}
}
@@ -10064,6 +10074,7 @@ SimpleTestPackageContext createTestPackage(string name, string version, List $"{l.Name}.{l.Version}").OrderBy(n => n).ToList();
Assert.Equal(expectedLibraries, libraries);
- var centralFileDependencyGroups = assetsFile
+ var centralfileDependencyGroups = assetsFile
.CentralTransitiveDependencyGroups
.SelectMany(g => g.TransitiveDependencies.Select(t => $"{g.FrameworkName}_{t.LibraryRange.Name}.{t.LibraryRange.VersionRange.OriginalString}")).ToList();
- Assert.Equal(0, centralFileDependencyGroups.Count);
- }
- }
-
- [Theory]
- [InlineData(false)]
- [InlineData(true)]
- [InlineData(null)]
- public async Task RestoreNetCore_CPVMProject_ManagePackageVersionsCentrally_CanBeDisabled(bool? managePackageVersionsCentrally)
- {
- // Arrange
- using var pathContext = new SimpleTestPathContext();
-
- var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot);
-
- var packageA = new SimpleTestPackageContext("A", "1.0.0");
-
- await SimpleTestPackageUtility.CreateFolderFeedV3Async(pathContext.PackageSource, packageA);
-
- var projectA = SimpleTestProjectContext.CreateNETCore("projectA", pathContext.SolutionRoot, "net472");
-
- if (managePackageVersionsCentrally is null || managePackageVersionsCentrally == true)
- {
- packageA.Version = null;
- }
-
- projectA.AddPackageToAllFrameworks(packageA);
-
- solution.CentralPackageVersionsManagementFile = CentralPackageVersionsManagementFile.Create(pathContext.SolutionRoot, managePackageVersionsCentrally)
- .SetPackageVersion("A", "1.0.0");
-
- solution.Projects.Add(projectA);
- solution.Create(pathContext.SolutionRoot);
-
- // Act
- var result = Util.RestoreSolution(pathContext, testOutputHelper: _testOutputHelper);
-
- // Assert
- result.Success.Should().BeTrue();
-
- var assetFileReader = new LockFileFormat();
- var assetsFile = assetFileReader.Read(projectA.AssetsFileOutputPath);
-
- assetsFile.Libraries.Select(l => $"{l.Name}.{l.Version}").Should().BeEquivalentTo(new string[] { "A.1.0.0" });
-
- var targetFramework = assetsFile.PackageSpec.TargetFrameworks.Should().ContainSingle();
-
- if (managePackageVersionsCentrally is null || managePackageVersionsCentrally == true)
- {
- targetFramework.Subject.Dependencies.Should().ContainSingle()
- .Which.VersionCentrallyManaged.Should().BeTrue();
-
- targetFramework.Subject.CentralPackageVersions.Should().ContainSingle()
- .Which.Value.Should().Be(new CentralPackageVersion("A", VersionRange.Parse("1.0.0")));
- }
- else
- {
- targetFramework.Subject.Dependencies.Should().ContainSingle()
- .Which.VersionCentrallyManaged.Should().BeFalse();
- targetFramework.Subject.CentralPackageVersions.Should().BeEmpty();
+ Assert.Equal(0, centralfileDependencyGroups.Count);
}
}
@@ -10298,6 +10250,8 @@ public async Task RestoreNetCore_CPVMProject_WithVersionOverride_Succeeds()
var projectA = SimpleTestProjectContext.CreateNETCore("projectA", pathContext.SolutionRoot, framework);
+ projectA.Properties.Add("ManagePackageVersionsCentrally", "true");
+
await SimpleTestPackageUtility.CreateFolderFeedV3Async(
pathContext.PackageSource,
new[]
@@ -10356,11 +10310,11 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
var libraries = assetsFile.Libraries.Select(l => $"{l.Name}.{l.Version}").OrderBy(n => n).ToList();
Assert.Equal(expectedLibraries, libraries);
- var centralFileDependencyGroups = assetsFile
+ var centralfileDependencyGroups = assetsFile
.CentralTransitiveDependencyGroups
.SelectMany(g => g.TransitiveDependencies.Select(t => $"{g.FrameworkName}_{t.LibraryRange.Name}.{t.LibraryRange.VersionRange.OriginalString}")).ToList();
- Assert.Equal(0, centralFileDependencyGroups.Count);
+ Assert.Equal(0, centralfileDependencyGroups.Count);
}
}
@@ -10377,6 +10331,7 @@ public async Task RestoreNetCore_CPVMProject_WithVersionOverrideDisabled_Fails()
var projectA = SimpleTestProjectContext.CreateNETCore("projectA", pathContext.SolutionRoot, framework);
+ projectA.Properties.Add(ProjectBuildProperties.ManagePackageVersionsCentrally, bool.TrueString);
projectA.Properties.Add(ProjectBuildProperties.CentralPackageVersionOverrideEnabled, bool.FalseString);
await SimpleTestPackageUtility.CreateFolderFeedV3Async(
@@ -11377,6 +11332,11 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
var xml = projectA.GetXML();
+ ProjectFileUtils.AddProperty(
+ xml,
+ "ManagePackageVersionsCentrally",
+ "true");
+
ProjectFileUtils.AddItem(
xml,
"PackageReference",
@@ -11587,6 +11547,7 @@ SimpleTestProjectContext CreateProject(SimpleTestPathContext pathContext, string
pathContext.SolutionRoot,
"net472");
+ projectContext.Properties.Add("ManagePackageVersionsCentrally", "true");
projectContext.Properties.Add("CentralPackageTransitivePinningEnabled", centralPackageTransitivePinningEnabled.ToString());
if (referencedProject != null)
diff --git a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
index 32e03f76378..74dc77038ee 100644
--- a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
+++ b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetAddPackageTests.cs
@@ -697,7 +697,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100,
packageX200);
- var propsFile = @$"";
+ var propsFile = @$"
+
+ true
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -740,7 +745,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100,
packageX200);
- var propsFile = @$"";
+ var propsFile = @$"
+
+ true
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -781,10 +791,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX200);
var propsFile = @$"
-
-
-
-";
+
+ true
+
+
+
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -828,10 +842,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX200);
var propsFile = @$"
-
-
-
-";
+
+ true
+
+
+
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -874,6 +892,9 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100);
var propsFile = @$"
+
+ true
+
@@ -928,7 +949,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100,
packageX200);
- var propsFile = @$"";
+ var propsFile = @$"
+
+ true
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -985,7 +1011,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100,
packageX200);
- var propsFile = @$"";
+ var propsFile = @$"
+
+ true
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1043,10 +1074,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX200);
var propsFile = @$"
-
-
-
-";
+
+ true
+
+
+
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1068,11 +1103,13 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
File.WriteAllText(Path.Combine(pathContext.SolutionRoot, "projectA", "projectA.csproj"), projectContent);
//Act
- var result = _fixture.RunDotnetExpectSuccess(projectADirectory, $"add {projectA.ProjectPath} package {packageX}", testOutputHelper: _testOutputHelper);
+ var result = _fixture.RunDotnetExpectFailure(projectADirectory, $"add {projectA.ProjectPath} package {packageX} ", testOutputHelper: _testOutputHelper);
// Assert
Assert.DoesNotContain("error: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: X", result.Output);
- Assert.Contains(@$"", File.ReadAllText(Path.Combine(pathContext.SolutionRoot, "Directory.Packages.props")));
+ Assert.Contains(@$"
+
+ ", File.ReadAllText(Path.Combine(pathContext.SolutionRoot, "Directory.Packages.props")));
Assert.Contains(@$"
", File.ReadAllText(Path.Combine(projectADirectory, "projectA.csproj")));
@@ -1102,10 +1139,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX200);
var propsFile = @$"
-
-
-
-";
+
+ true
+
+
+
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1158,7 +1199,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100,
packageX200);
- var propsFile = @$"";
+ var propsFile = @$"
+
+ true
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1215,7 +1261,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100,
packageX200);
- var propsFile = @$"";
+ var propsFile = @$"
+
+ true
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1272,10 +1323,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX200);
var propsFile = @$"
-
-
-
-";
+
+ true
+
+
+
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1301,7 +1356,9 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
// Assert
Assert.DoesNotContain("error: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: X", result.Output);
- Assert.Contains(@$"", File.ReadAllText(Path.Combine(pathContext.SolutionRoot, "Directory.Packages.props")));
+ Assert.Contains(@$"
+
+ ", File.ReadAllText(Path.Combine(pathContext.SolutionRoot, "Directory.Packages.props")));
Assert.Contains(@$"
", File.ReadAllText(Path.Combine(projectADirectory, "projectA.csproj")));
@@ -1331,10 +1388,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX200);
var propsFile = @$"
-
-
-
-";
+
+ true
+
+
+
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1391,10 +1452,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX200);
var propsFile = @$"
-
-
-
-";
+
+ true
+
+
+
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1451,11 +1516,15 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX200);
var propsFile = @$"
-
-
-
-
-";
+
+ true
+
+
+
+
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1507,7 +1576,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100,
packageX200);
- var propsFile = @$"";
+ var propsFile = @$"
+
+ true
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
@@ -1564,7 +1638,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
packageX100,
packageX200);
- var propsFile = @$"";
+ var propsFile = @$"
+
+ true
+
+
+ ";
solution.Projects.Add(projectA);
solution.Create(pathContext.SolutionRoot);
diff --git a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs
index 597cc9ef255..45f713fd9a2 100644
--- a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs
+++ b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs
@@ -108,7 +108,10 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
var propsFile =
@$"
-
+
+ true
+
+
";
@@ -159,6 +162,9 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
var propsFile =
@$"
+
+ true
+
@@ -208,6 +214,9 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
var propsFile =
@$"
+
+ true
+
diff --git a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetRestoreTests.cs b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetRestoreTests.cs
index 2d442df98e5..781328ee3ee 100644
--- a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetRestoreTests.cs
+++ b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetRestoreTests.cs
@@ -1771,6 +1771,10 @@ public async Task DotnetRestore_WithDuplicatePackageVersion_WarnsWithNU1506()
using (var stream = File.Open(projectFile, FileMode.Open, FileAccess.ReadWrite))
{
var xml = XDocument.Load(stream);
+ ProjectFileUtils.AddProperty(
+ xml,
+ "ManagePackageVersionsCentrally",
+ "true");
ProjectFileUtils.AddItem(
xml,
@@ -2317,6 +2321,10 @@ public async Task DotnetRestore_WithDuplicatePackageVersion_WithTreatWarningsAsE
using (var stream = File.Open(projectFile, FileMode.Open, FileAccess.ReadWrite))
{
var xml = XDocument.Load(stream);
+ ProjectFileUtils.AddProperty(
+ xml,
+ "ManagePackageVersionsCentrally",
+ "true");
ProjectFileUtils.AddItem(
xml,
@@ -2502,6 +2510,7 @@ public async Task DotnetRestore_CentralPackageVersionManagement_NoOps()
{
var xml = XDocument.Load(stream);
ProjectFileUtils.SetTargetFrameworkForProject(xml, "TargetFrameworks", Constants.DefaultTargetFramework.GetShortFolderName());
+ ProjectFileUtils.AddProperty(xml, "ManagePackageVersionsCentrally", "true");
ProjectFileUtils.AddItem(
xml,
diff --git a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs
index 4e562dd691d..3f70cab3b3a 100644
--- a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs
+++ b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs
@@ -5198,10 +5198,10 @@ public void PackCommand_WhenUsingSemver2Version_NU5105_IsNotRaised()
}
[PlatformTheory(Platform.Windows)]
- [InlineData(false)]
- [InlineData(true)]
+ [InlineData("false")]
+ [InlineData("true")]
[InlineData(null)]
- public void PackCommand_PackProjectWithCentralTransitiveDependencies(bool? centralPackageTransitivePinningEnabled)
+ public void PackCommand_PackProjectWithCentralTransitiveDependencies(string CentralPackageTransitivePinningEnabled)
{
using (var testDirectory = _dotnetFixture.CreateTestDirectory())
{
@@ -5224,24 +5224,33 @@ public void PackCommand_PackProjectWithCentralTransitiveDependencies(bool? centr
new Dictionary(),
new Dictionary());
- if (centralPackageTransitivePinningEnabled.HasValue)
+ ProjectFileUtils.AddProperty(
+ xml,
+ ProjectBuildProperties.ManagePackageVersionsCentrally,
+ "true");
+
+ if (CentralPackageTransitivePinningEnabled != null)
{
ProjectFileUtils.AddProperty(
xml,
ProjectBuildProperties.CentralPackageTransitivePinningEnabled,
- centralPackageTransitivePinningEnabled.ToString());
+ CentralPackageTransitivePinningEnabled);
}
ProjectFileUtils.WriteXmlToFile(xml, stream);
}
// The test depends on the presence of these packages and their versions.
- var directoryPackagesPropsName = Path.Combine(workingDirectory, "Directory.Packages.props");
+ // Change to Directory.Packages.props when new cli that supports NuGet.props will be downloaded
+ var directoryPackagesPropsName = Path.Combine(workingDirectory, $"Directory.Build.props");
var directoryPackagesPropsContent = @"
-
-
+
+
+
+ true
+
";
File.WriteAllText(directoryPackagesPropsName, directoryPackagesPropsContent);
@@ -5262,7 +5271,7 @@ public void PackCommand_PackProjectWithCentralTransitiveDependencies(bool? centr
Assert.Equal(1, dependencyGroups.Count);
Assert.Equal(FrameworkConstants.CommonFrameworks.NetStandard20, dependencyGroups[0].TargetFramework);
var packages = dependencyGroups[0].Packages.ToList();
- if (centralPackageTransitivePinningEnabled == true)
+ if (CentralPackageTransitivePinningEnabled == "true")
{
Assert.Equal(2, packages.Count);
var moqPackage = packages.Where(p => p.Id.Equals("Moq", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
diff --git a/test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildIntegrationTestFixture.cs b/test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildIntegrationTestFixture.cs
index 09007fa0fb9..dadd4df3b59 100644
--- a/test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildIntegrationTestFixture.cs
+++ b/test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildIntegrationTestFixture.cs
@@ -99,11 +99,12 @@ 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:NuGetRestoreTargets={nugetRestoreTargetsPath} /p:RestoreTaskAssemblyFile={restoreDllPath} /p:ImportNuGetBuildTasksPackTargetsFromSdk=true {args}",
+ $"/p:NuGetPropsFile={nugetRestorePropsPath} /p:NuGetRestoreTargets={nugetRestoreTargetsPath} /p:RestoreTaskAssemblyFile={restoreDllPath} /p:ImportNuGetBuildTasksPackTargetsFromSdk=true {args}",
environmentVariables: _processEnvVars,
testOutputHelper: testOutputHelper);
diff --git a/test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildRestoreTaskTests.cs b/test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildRestoreTaskTests.cs
index 1f25fee3c7d..f4f2b0da0dd 100644
--- a/test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildRestoreTaskTests.cs
+++ b/test/NuGet.Core.FuncTests/Msbuild.Integration.Test/MsbuildRestoreTaskTests.cs
@@ -1308,6 +1308,9 @@ public void MsbuildRestore_WithLegacyCsproj_GlobalPackageReferencesAreProcessed(
File.WriteAllText(
Path.Combine(pathContext.SolutionRoot, "Directory.Packages.props"),
@$"
+
+ true
+
diff --git a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/MSBuildAPIUtilityTests.cs b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/MSBuildAPIUtilityTests.cs
index f181c136e7c..f93fa3c0bff 100644
--- a/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/MSBuildAPIUtilityTests.cs
+++ b/test/NuGet.Core.Tests/NuGet.CommandLine.Xplat.Tests/MSBuildAPIUtilityTests.cs
@@ -46,7 +46,13 @@ public void GetDirectoryBuildPropsRootElementWhenItExists_Success()
ProjectCollection = projectCollection
};
- File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), @$"");
+ var propsFile =
+@$"
+
+ true
+
+";
+ File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), propsFile);
string projectContent =
@$"
@@ -200,7 +206,13 @@ public void AddPackageVersionIntoPropsFileWhenItemGroupDoesNotExist_Success()
};
// Arrange Directory.Packages.props file
- File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), "");
+ var propsFile =
+@$"
+
+ true
+
+";
+ File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), propsFile);
// Arrange project file
string projectContent =
@@ -261,8 +273,11 @@ public void AddPackageVersionIntoPropsFileWhenItemGroupExists_Success()
// Arrange Directory.Packages.props file
var propsFile =
@$"
+
+ true
+
-
+
";
File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), propsFile);
@@ -327,8 +342,11 @@ public void UpdatePackageVersionInPropsFileWhenItExists_Success()
// Arrange Directory.Packages.props file
var propsFile =
@$"
+
+ true
+
-
+
";
File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), propsFile);
@@ -393,8 +411,11 @@ public void UpdateVersionOverrideInPropsFileWhenItExists_Success()
// Arrange Directory.Packages.props file
var propsFile =
@$"
+
+ true
+
-
+
";
File.WriteAllText(Path.Combine(testDirectory, "Directory.Packages.props"), propsFile);
diff --git a/test/TestUtilities/Test.Utility/CentralPackageVersionsManagementFile.cs b/test/TestUtilities/Test.Utility/CentralPackageVersionsManagementFile.cs
index 590786e0027..14d6be8b377 100644
--- a/test/TestUtilities/Test.Utility/CentralPackageVersionsManagementFile.cs
+++ b/test/TestUtilities/Test.Utility/CentralPackageVersionsManagementFile.cs
@@ -17,7 +17,7 @@ public class CentralPackageVersionsManagementFile
{
private const string DirectoryPackagesProps = "Directory.Packages.props";
- private readonly bool? _managePackageVersionsCentrally;
+ private readonly bool _managePackageVersionsCentrally;
private readonly Dictionary _packageVersions = new Dictionary(StringComparer.OrdinalIgnoreCase);
@@ -25,7 +25,7 @@ public class CentralPackageVersionsManagementFile
private readonly FileInfo _path;
- private CentralPackageVersionsManagementFile(string directoryPath, bool? managePackageVersionsCentrally)
+ private CentralPackageVersionsManagementFile(string directoryPath, bool managePackageVersionsCentrally)
{
_path = new FileInfo(Path.Combine(directoryPath, DirectoryPackagesProps));
_managePackageVersionsCentrally = managePackageVersionsCentrally;
@@ -47,7 +47,7 @@ private CentralPackageVersionsManagementFile(string directoryPath, bool? manageP
/// The path to a directory to create the central package management in.
/// to enable central package management (default), or to disable it.
///
- public static CentralPackageVersionsManagementFile Create(string directoryPath, bool? managePackageVersionsCentrally = null)
+ public static CentralPackageVersionsManagementFile Create(string directoryPath, bool managePackageVersionsCentrally = true)
{
return new CentralPackageVersionsManagementFile(directoryPath, managePackageVersionsCentrally);
}
@@ -59,11 +59,6 @@ public static CentralPackageVersionsManagementFile Create(string directoryPath,
/// The current .
public CentralPackageVersionsManagementFile RemovePackageVersion(string packageId)
{
- if (_managePackageVersionsCentrally == false)
- {
- return this;
- }
-
_packageVersions.Remove(packageId);
IsDirty = true;
@@ -76,13 +71,10 @@ public CentralPackageVersionsManagementFile RemovePackageVersion(string packageI
///
public void Save()
{
- XElement managePackageVersionsCentrallyProperty = _managePackageVersionsCentrally is null
- ? null
- : new XElement("PropertyGroup", new XElement(ProjectBuildProperties.ManagePackageVersionsCentrally, new XText(_managePackageVersionsCentrally.ToString())));
-
XDocument directoryPackagesPropsXml = new XDocument(
new XElement("Project",
- managePackageVersionsCentrallyProperty,
+ new XElement("PropertyGroup",
+ new XElement(ProjectBuildProperties.ManagePackageVersionsCentrally, new XText(_managePackageVersionsCentrally.ToString()))),
new XElement("ItemGroup", _packageVersions.Select(i => new XElement("PackageVersion", new XAttribute("Include", i.Key), new XAttribute("Version", i.Value)))),
new XElement("ItemGroup", _globalPackageReferences.Select(i => new XElement("GlobalPackageReference", new XAttribute("Include", i.Key), new XAttribute("Version", i.Value))))));
@@ -99,11 +91,6 @@ public void Save()
/// The current .
public CentralPackageVersionsManagementFile SetPackageVersion(string packageId, string packageVersion)
{
- if (_managePackageVersionsCentrally == false)
- {
- return this;
- }
-
_packageVersions[packageId] = packageVersion;
IsDirty = true;
@@ -113,11 +100,6 @@ public CentralPackageVersionsManagementFile SetPackageVersion(string packageId,
public CentralPackageVersionsManagementFile SetGlobalPackageReference(string packageId, string packageVersion)
{
- if (_managePackageVersionsCentrally == false)
- {
- return this;
- }
-
_globalPackageReferences[packageId] = packageVersion;
IsDirty = true;
diff --git a/test/TestUtilities/Test.Utility/TestDotnetCLiUtility.cs b/test/TestUtilities/Test.Utility/TestDotnetCLiUtility.cs
index 1c3b88fbbfb..523c20b598e 100644
--- a/test/TestUtilities/Test.Utility/TestDotnetCLiUtility.cs
+++ b/test/TestUtilities/Test.Utility/TestDotnetCLiUtility.cs
@@ -194,7 +194,7 @@ private static void UpdateCliWithLatestNuGetAssemblies(string cliDirectory)
private static void CopyRestoreArtifacts(string artifactsDirectory, string pathToSdkInCli, string configuration)
{
- var fileExtensions = new[] { ".dll", ".pdb", ".targets", ".props" };
+ var fileExtensions = new[] { ".dll", ".pdb", ".targets" };
var sdkDependencies = new List { "NuGet.Build.Tasks.Console", "NuGet.CommandLine.XPlat" };
diff --git a/test/TestUtilities/Test.Utility/TestFileSystemUtility.cs b/test/TestUtilities/Test.Utility/TestFileSystemUtility.cs
index 42ec646e680..c68da08a1ac 100644
--- a/test/TestUtilities/Test.Utility/TestFileSystemUtility.cs
+++ b/test/TestUtilities/Test.Utility/TestFileSystemUtility.cs
@@ -54,13 +54,7 @@ private static string GetRootDirectory()
File.WriteAllText(Path.Combine(testDirectory.FullName, "Directory.Solution.props"), "");
File.WriteAllText(Path.Combine(testDirectory.FullName, "Directory.Solution.targets"), "");
File.WriteAllText(Path.Combine(testDirectory.FullName, "Directory.Build.rsp"), string.Empty);
- File.WriteAllText(
- Path.Combine(testDirectory.FullName, "Directory.Packages.props"),
- @"
-
- false
-
-");
+ File.WriteAllText(Path.Combine(testDirectory.FullName, "Directory.Packages.props"), "");
}
catch (Exception)
{