1414using Microsoft . Build . Construction ;
1515using Microsoft . Build . Evaluation ;
1616using Microsoft . Build . Execution ;
17+ using Microsoft . DotNet . ProjectTools ;
1718using NuGet . Common ;
1819using NuGet . Frameworks ;
1920using NuGet . LibraryModel ;
@@ -725,7 +726,6 @@ internal static List<FrameworkPackages> GetResolvedVersions(
725726 throw new ArgumentNullException ( nameof ( assetsFile ) ) ;
726727 }
727728
728- var projectPath = project . FullPath ;
729729 var resultPackages = new List < FrameworkPackages > ( ) ;
730730 var requestedTargetFrameworks = assetsFile . PackageSpec . TargetFrameworks ;
731731 var requestedTargets = assetsFile . Targets ;
@@ -781,7 +781,7 @@ internal static List<FrameworkPackages> GetResolvedVersions(
781781
782782 //The packages for the framework that were retrieved with GetRequestedVersions
783783 var frameworkDependencies = tfmInformation . Dependencies ;
784- var projectPackages = GetPackageReferencesFromTargets ( projectPath , tfmInformation . ToString ( ) ) ;
784+ var projectPackages = GetPackageReferencesFromTargets ( project , tfmInformation . ToString ( ) ) ;
785785 var topLevelPackages = new List < InstalledPackageReference > ( ) ;
786786 var transitivePackages = new List < InstalledPackageReference > ( ) ;
787787
@@ -808,7 +808,7 @@ internal static List<FrameworkPackages> GetResolvedVersions(
808808 }
809809 catch ( Exception )
810810 {
811- throw new InvalidOperationException ( string . Format ( CultureInfo . CurrentCulture , Strings . ListPkg_ErrorReadingReferenceFromProject , projectPath ) ) ;
811+ throw new InvalidOperationException ( string . Format ( CultureInfo . CurrentCulture , Strings . ListPkg_ErrorReadingReferenceFromProject , project . FullPath ) ) ;
812812 }
813813 }
814814 else
@@ -900,18 +900,18 @@ private static IEnumerable<ProjectItem> GetPackageReferences(Project project, Li
900900 /// <summary>
901901 /// Returns all package references after invoking the target CollectPackageReferences.
902902 /// </summary>
903- /// <param name="projectPath"> Path to the project for which the package references have to be obtained.</param>
903+ /// <param name="project">The project for which the package references have to be obtained.</param>
904904 /// <param name="framework">Framework to get reference(s) for</param>
905905 /// <returns>List of Items containing the package reference for the package.
906906 /// If the libraryDependency is null then it returns all package references</returns>
907- private static IEnumerable < InstalledPackageReference > GetPackageReferencesFromTargets ( string projectPath , string framework )
907+ private static IEnumerable < InstalledPackageReference > GetPackageReferencesFromTargets ( Project project , string framework )
908908 {
909909 var globalProperties = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase )
910910 {
911911 { "TargetFramework" , framework } ,
912912 { "ExcludeRestorePackageImports" , bool . TrueString }
913913 } ;
914- var newProject = new ProjectInstance ( projectPath , globalProperties , null ) ;
914+ var newProject = new ProjectInstance ( project . Xml , globalProperties , null , ProjectCollection . GlobalProjectCollection ) ;
915915 newProject . Build ( new [ ] { CollectPackageReferences , CollectCentralPackageVersions } , new List < Microsoft . Build . Framework . ILogger > { } , out var targetOutputs ) ;
916916
917917 // Find the first target output that matches `CollectPackageReferences`
@@ -1040,6 +1040,14 @@ private static IEnumerable<string> GetProjectFrameworks(Project project)
10401040
10411041 private static ProjectRootElement TryOpenProjectRootElement ( string filename )
10421042 {
1043+ if ( VirtualProjectBuilder . IsValidEntryPointPath ( filename ) )
1044+ {
1045+ // TODO: Don't hardcode TFM.
1046+ return VirtualProjectBuilder . CreateProjectRootElement (
1047+ filePath : filename ,
1048+ targetFrameworkVersion : "10.0" ) ;
1049+ }
1050+
10431051 try
10441052 {
10451053 // There is ProjectRootElement.TryOpen but it does not work as expected
0 commit comments