File tree Expand file tree Collapse file tree
src/NuGet.Core/NuGet.CommandLine.XPlat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66using System ;
77using System . CommandLine ;
8+ using System . IO ;
89using System . Linq ;
10+ using System . Reflection ;
911using Microsoft . Build . Construction ;
1012using Microsoft . Build . Evaluation ;
1113using NuGet . CommandLine . XPlat . Commands . Package . PackageDownload ;
@@ -18,8 +20,6 @@ namespace NuGet.CommandLine.XPlat;
1820/// </summary>
1921public static class NuGetCommands
2022{
21- public static IVirtualProjectBuilder ? VirtualProjectBuilder { get ; set ; }
22-
2323 /// <summary>
2424 /// <para>Adds NuGet's dotnet CLI commands to the dotnet CLI RootCommand object</para>
2525 /// </summary>
@@ -57,4 +57,19 @@ public interface IVirtualProjectBuilder
5757 bool IsValidEntryPointPath ( string entryPointFilePath ) ;
5858
5959 ProjectRootElement CreateProjectRootElement ( string entryPointFilePath , ProjectCollection projectCollection ) ;
60+
61+ internal static IVirtualProjectBuilder ? TryLoad ( )
62+ {
63+ var assemblyPath = Path . Join ( AppContext . BaseDirectory , "dotnet.dll" ) ;
64+
65+ if ( ! File . Exists ( assemblyPath ) )
66+ {
67+ return null ;
68+ }
69+
70+ var type = Assembly . LoadFile ( assemblyPath )
71+ . GetExportedTypes ( )
72+ . FirstOrDefault ( static t => t . IsAssignableTo ( typeof ( IVirtualProjectBuilder ) ) ) ;
73+ return type != null ? ( IVirtualProjectBuilder ? ) Activator . CreateInstance ( type ) : null ;
74+ }
6075}
Original file line number Diff line number Diff line change 22NuGet.CommandLine.XPlat.IVirtualProjectBuilder
33NuGet.CommandLine.XPlat.IVirtualProjectBuilder.CreateProjectRootElement(string! entryPointFilePath, Microsoft.Build.Evaluation.ProjectCollection! projectCollection) -> Microsoft.Build.Construction.ProjectRootElement!
44NuGet.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
Original file line number Diff line number Diff line change @@ -1039,7 +1039,7 @@ private static IEnumerable<string> GetProjectFrameworks(Project project)
10391039
10401040 private static ProjectRootElement TryOpenProjectRootElement ( string filename )
10411041 {
1042- var virtualProjectBuilder = NuGetCommands . VirtualProjectBuilder ;
1042+ var virtualProjectBuilder = IVirtualProjectBuilder . TryLoad ( ) ;
10431043 if ( virtualProjectBuilder != null && virtualProjectBuilder . IsValidEntryPointPath ( filename ) )
10441044 {
10451045 return virtualProjectBuilder . CreateProjectRootElement ( filename , ProjectCollection . GlobalProjectCollection ) ;
You can’t perform that action at this time.
0 commit comments