Skip to content

Commit 9cc867e

Browse files
committed
Let SDK provide the API to avoid a circular dependency
1 parent 3435c86 commit 9cc867e

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/NuGet.Core/NuGet.CommandLine.XPlat/NuGet.CommandLine.XPlat.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.DotNet.ProjectTools" />
2120
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" PrivateAssets="All" />
2221
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" />
2322
<PackageReference Include="Spectre.Console" />

src/NuGet.Core/NuGet.CommandLine.XPlat/NuGetCommands.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System;
77
using System.CommandLine;
88
using System.Linq;
9+
using Microsoft.Build.Construction;
10+
using Microsoft.Build.Evaluation;
911
using NuGet.CommandLine.XPlat.Commands.Package.PackageDownload;
1012
using NuGet.CommandLine.XPlat.Commands.Package.Update;
1113

@@ -16,6 +18,8 @@ namespace NuGet.CommandLine.XPlat;
1618
/// </summary>
1719
public static class NuGetCommands
1820
{
21+
public static IVirtualProjectBuilder? VirtualProjectBuilder { get; set; }
22+
1923
/// <summary>
2024
/// <para>Adds NuGet's dotnet CLI commands to the dotnet CLI RootCommand object</para>
2125
/// </summary>
@@ -47,3 +51,10 @@ public static void Add(RootCommand rootCommand)
4751
Add(rootCommand, interactiveOption);
4852
}
4953
}
54+
55+
public interface IVirtualProjectBuilder
56+
{
57+
bool IsValidEntryPointPath(string entryPointFilePath);
58+
59+
ProjectRootElement CreateProjectRootElement(string entryPointFilePath, ProjectCollection projectCollection);
60+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
#nullable enable
2+
NuGet.CommandLine.XPlat.IVirtualProjectBuilder
3+
NuGet.CommandLine.XPlat.IVirtualProjectBuilder.CreateProjectRootElement(string! entryPointFilePath, Microsoft.Build.Evaluation.ProjectCollection! projectCollection) -> Microsoft.Build.Construction.ProjectRootElement!
4+
NuGet.CommandLine.XPlat.IVirtualProjectBuilder.IsValidEntryPointPath(string! entryPointFilePath) -> bool
5+
static NuGet.CommandLine.XPlat.NuGetCommands.VirtualProjectBuilder.get -> NuGet.CommandLine.XPlat.IVirtualProjectBuilder?
6+
static NuGet.CommandLine.XPlat.NuGetCommands.VirtualProjectBuilder.set -> void

src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using Microsoft.Build.Construction;
1515
using Microsoft.Build.Evaluation;
1616
using Microsoft.Build.Execution;
17-
using Microsoft.DotNet.ProjectTools;
1817
using NuGet.Common;
1918
using NuGet.Frameworks;
2019
using NuGet.LibraryModel;
@@ -1040,13 +1039,10 @@ private static IEnumerable<string> GetProjectFrameworks(Project project)
10401039

10411040
private static ProjectRootElement TryOpenProjectRootElement(string filename)
10421041
{
1043-
if (VirtualProjectBuilder.IsValidEntryPointPath(filename))
1042+
var virtualProjectBuilder = NuGetCommands.VirtualProjectBuilder;
1043+
if (virtualProjectBuilder != null && virtualProjectBuilder.IsValidEntryPointPath(filename))
10441044
{
1045-
// TODO: Don't hardcode TFM.
1046-
return VirtualProjectBuilder.CreateProjectRootElement(
1047-
filePath: filename,
1048-
targetFrameworkVersion: "10.0",
1049-
ProjectCollection.GlobalProjectCollection);
1045+
return virtualProjectBuilder.CreateProjectRootElement(filename, ProjectCollection.GlobalProjectCollection);
10501046
}
10511047

10521048
try

0 commit comments

Comments
 (0)