Skip to content

Commit ee66bd5

Browse files
committed
Revert "Enable central package management implicitly when Directory.Packages.props exists (#5572)"
This reverts commit c9b81ab.
1 parent 69ce91e commit ee66bd5

File tree

14 files changed

+245
-191
lines changed

14 files changed

+245
-191
lines changed

src/NuGet.Clients/NuGet.CommandLine/MsBuildUtility.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public static class MsBuildUtility
2323
{
2424
internal const int MsBuildWaitTime = 2 * 60 * 1000; // 2 minutes in milliseconds
2525

26-
private const string NuGetProps = "NuGet.CommandLine.NuGet.props";
2726
private const string NuGetTargets = "NuGet.CommandLine.NuGet.targets";
2827
private static readonly XNamespace MSBuildNamespace = XNamespace.Get("http://schemas.microsoft.com/developer/msbuild/2003");
2928

@@ -104,12 +103,10 @@ public static async Task<DependencyGraphSpec> GetProjectReferencesAsync(
104103
}
105104

106105
using (var inputTargetPath = new TempFile(".nugetinputs.targets"))
107-
using (var nugetPropsPath = new TempFile(".nugetrestore.props"))
108106
using (var entryPointTargetPath = new TempFile(".nugetrestore.targets"))
109107
using (var resultsPath = new TempFile(".output.dg"))
110108
{
111-
// Read NuGet.props and NuGet.targets from nuget.exe and write it to disk for msbuild.exe
112-
ExtractResource(NuGetProps, nugetPropsPath);
109+
// Read NuGet.targets from nuget.exe and write it to disk for msbuild.exe
113110
ExtractResource(NuGetTargets, entryPointTargetPath);
114111

115112
// Build a .targets file of all restore inputs, this is needed to avoid going over the limit on command line arguments.
@@ -118,15 +115,15 @@ public static async Task<DependencyGraphSpec> GetProjectReferencesAsync(
118115
{ "RestoreUseCustomAfterTargets", "true" },
119116
{ "RestoreGraphOutputPath", resultsPath },
120117
{ "RestoreRecursive", recursive.ToString(CultureInfo.CurrentCulture).ToLowerInvariant() },
121-
{ "RestoreProjectFilterMode", "exclusionlist" },
118+
{ "RestoreProjectFilterMode", "exclusionlist" }
122119
};
123120

124121
var inputTargetXML = GetRestoreInputFile(entryPointTargetPath, properties, projectPaths);
125122

126123
inputTargetXML.Save(inputTargetPath);
127124

128125
// Create msbuild parameters and include global properties that cannot be set in the input targets path
129-
var arguments = GetMSBuildArguments(entryPointTargetPath, nugetPropsPath, inputTargetPath, nugetExePath, solutionDirectory, solutionName, restoreConfigFile, sources, packagesDirectory, msbuildToolset, restoreLockProperties, EnvironmentVariableWrapper.Instance);
126+
var arguments = GetMSBuildArguments(entryPointTargetPath, inputTargetPath, nugetExePath, solutionDirectory, solutionName, restoreConfigFile, sources, packagesDirectory, msbuildToolset, restoreLockProperties, EnvironmentVariableWrapper.Instance);
130127

131128
var processStartInfo = new ProcessStartInfo
132129
{
@@ -224,7 +221,6 @@ public static async Task<DependencyGraphSpec> GetProjectReferencesAsync(
224221

225222
public static string GetMSBuildArguments(
226223
string entryPointTargetPath,
227-
string nugetPropsPath,
228224
string inputTargetPath,
229225
string nugetExePath,
230226
string solutionDirectory,
@@ -257,8 +253,6 @@ public static string GetMSBuildArguments(
257253
args.Add($"/v:{msbuildVerbosity} ");
258254
}
259255

260-
AddProperty(args, "NuGetPropsFile", nugetPropsPath);
261-
262256
// Override the target under ImportsAfter with the current NuGet.targets version.
263257
AddProperty(args, "NuGetRestoreTargets", entryPointTargetPath);
264258
AddProperty(args, "RestoreUseCustomAfterTargets", bool.TrueString);

src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191
</ItemGroup>
9292

9393
<ItemGroup>
94-
<EmbeddedResource Include="..\..\NuGet.Core\NuGet.Build.Tasks\NuGet.props">
95-
<Link>NuGet.props</Link>
96-
<SubType>Designer</SubType>
97-
</EmbeddedResource>
9894
<EmbeddedResource Include="..\..\NuGet.Core\NuGet.Build.Tasks\NuGet.targets">
9995
<Link>NuGet.targets</Link>
10096
<SubType>Designer</SubType>

src/NuGet.Core/NuGet.Build.Tasks/NuGet.props

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,33 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
99
Copyright (c) .NET Foundation. All rights reserved.
1010
***********************************************************************************************
1111
-->
12+
1213
<Project>
14+
1315
<!--
14-
Determine the path to the 'Directory.Packages.props' file, if the user did not:
15-
1. Set $(ManagePackageVersionsCentrally) to false
16-
2. Set $(ImportDirectoryPackagesProps) to false
17-
3. Already specify the path to a 'Directory.Packages.props' file via $(DirectoryPackagesPropsPath)
16+
Import 'Directory.Packages.props' which will contain centralized packages for all the projects and solutions under
17+
the directory in which the file is present. This is similar to 'Directory.Build.props/targets' logic which is present
18+
in the common props/targets which serve a similar purpose.
1819
-->
19-
<PropertyGroup Condition="'$(ManagePackageVersionsCentrally)' != 'false' And '$(ImportDirectoryPackagesProps)' != 'false' And '$(DirectoryPackagesPropsPath)' == ''">
20-
<_DirectoryPackagesPropsFile Condition="'$(_DirectoryPackagesPropsFile)' == ''">Directory.Packages.props</_DirectoryPackagesPropsFile>
21-
<_DirectoryPackagesPropsBasePath Condition="'$(_DirectoryPackagesPropsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', '$(_DirectoryPackagesPropsFile)'))</_DirectoryPackagesPropsBasePath>
22-
<DirectoryPackagesPropsPath Condition="'$(_DirectoryPackagesPropsBasePath)' != '' and '$(_DirectoryPackagesPropsFile)' != ''">$([MSBuild]::NormalizePath('$(_DirectoryPackagesPropsBasePath)', '$(_DirectoryPackagesPropsFile)'))</DirectoryPackagesPropsPath>
20+
21+
<PropertyGroup>
22+
<ImportDirectoryPackagesProps Condition="'$(ImportDirectoryPackagesProps)' == ''">true</ImportDirectoryPackagesProps>
2323
</PropertyGroup>
2424

2525
<!--
26-
Default $(ManagePackageVersionsCentrally) to true, import Directory.Packages.props, and set $(CentralPackageVersionsFileImported) to true if the user did not:
27-
1. Set $(ManagePackageVersionsCentrally) to false
28-
2. Set $(ImportDirectoryPackagesProps) to false
29-
3. The path specified in $(DirectoryPackagesPropsPath) exists
26+
Determine the path to the 'Directory.Packages.props' file, if the user did not disable $(ImportDirectoryPackagesProps) and
27+
they did not already specify an absolute path to use via $(DirectoryPackagesPropsPath)
3028
-->
31-
<PropertyGroup Condition="'$(ManagePackageVersionsCentrally)' != 'false' And '$(ImportDirectoryPackagesProps)' != 'false' And Exists('$(DirectoryPackagesPropsPath)')">
32-
<ManagePackageVersionsCentrally Condition="'$(ManagePackageVersionsCentrally)' == ''">true</ManagePackageVersionsCentrally>
29+
<PropertyGroup Condition="'$(ImportDirectoryPackagesProps)' == 'true' and '$(DirectoryPackagesPropsPath)' == ''">
30+
<_DirectoryPackagesPropsFile Condition="'$(_DirectoryPackagesPropsFile)' == ''">Directory.Packages.props</_DirectoryPackagesPropsFile>
31+
<_DirectoryPackagesPropsBasePath Condition="'$(_DirectoryPackagesPropsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', '$(_DirectoryPackagesPropsFile)'))</_DirectoryPackagesPropsBasePath>
32+
<DirectoryPackagesPropsPath Condition="'$(_DirectoryPackagesPropsBasePath)' != '' and '$(_DirectoryPackagesPropsFile)' != ''">$([MSBuild]::NormalizePath('$(_DirectoryPackagesPropsBasePath)', '$(_DirectoryPackagesPropsFile)'))</DirectoryPackagesPropsPath>
3333
</PropertyGroup>
3434

35-
<Import Project="$(DirectoryPackagesPropsPath)" Condition="'$(ManagePackageVersionsCentrally)' != 'false' And '$(ImportDirectoryPackagesProps)' != 'false' And Exists('$(DirectoryPackagesPropsPath)')" />
35+
<Import Project="$(DirectoryPackagesPropsPath)" Condition="'$(ImportDirectoryPackagesProps)' == 'true' and '$(DirectoryPackagesPropsPath)' != '' and Exists('$(DirectoryPackagesPropsPath)')"/>
3636

37-
<PropertyGroup Condition="'$(ManagePackageVersionsCentrally)' != 'false' And '$(ImportDirectoryPackagesProps)' != 'false' And Exists('$(DirectoryPackagesPropsPath)')">
37+
<PropertyGroup Condition="'$(ImportDirectoryPackagesProps)' == 'true' and '$(DirectoryPackagesPropsPath)' != '' and Exists('$(DirectoryPackagesPropsPath)')">
3838
<CentralPackageVersionsFileImported>true</CentralPackageVersionsFileImported>
3939
</PropertyGroup>
40+
4041
</Project>
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
<Project>
2-
<PropertyGroup>
3-
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
4-
</PropertyGroup>
5-
</Project>
1+
<Project />

0 commit comments

Comments
 (0)