2015-11-16 11:21:57 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Copyright (c) .NET Foundation and contributors. All rights reserved.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Licensed under the MIT license. See LICENSE file in the project root for full license information.  
						 
					
						
							
								
									
										
										
										
											2015-10-13 14:31:29 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								using  System ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								using  System.Collections.Generic ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								using  System.IO ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								using  System.Linq ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								using  Microsoft.Extensions.ProjectModel.Compilation ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								using  Microsoft.Extensions.ProjectModel.Resolution ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								using  NuGet.Frameworks ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  Microsoft.Extensions.ProjectModel  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // NOTE(anurse): Copied from ApplicationHostContext in DNX. This name seemed more appropriate for this :) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  class  ProjectContext 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  GlobalSettings  GlobalSettings  {  get ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  ProjectDescription  RootProject  {  get ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  NuGetFramework  TargetFramework  {  get ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  string  RuntimeIdentifier  {  get ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-15 12:56:07 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        public  Project  ProjectFile  = >  RootProject . Project ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-13 14:31:29 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        public  string  RootDirectory  = >  GlobalSettings . DirectoryPath ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-15 12:56:07 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        public  string  ProjectDirectory  = >  ProjectFile . ProjectDirectory ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-13 14:31:29 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  string  PackagesDirectory  {  get ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  LibraryManager  LibraryManager  {  get ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        internal  ProjectContext ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            GlobalSettings  globalSettings , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProjectDescription  rootProject , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            NuGetFramework  targetFramework , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            string  runtimeIdentifier , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            string  packagesDirectory , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            LibraryManager  libraryManager ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            GlobalSettings  =  globalSettings ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            RootProject  =  rootProject ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            TargetFramework  =  targetFramework ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            RuntimeIdentifier  =  runtimeIdentifier ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            PackagesDirectory  =  packagesDirectory ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            LibraryManager  =  libraryManager ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  LibraryExporter  CreateExporter ( string  configuration ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  new  LibraryExporter ( RootProject ,  LibraryManager ,  configuration ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// <summary> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// Creates a project context for the project located at <paramref name="projectPath"/>, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// specifically in the context of the framework specified in <paramref name="framework"/> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// </summary> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  static  ProjectContext  Create ( string  projectPath ,  NuGetFramework  framework ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  Create ( projectPath ,  framework ,  Enumerable . Empty < string > ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// <summary> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// Creates a project context for the project located at <paramref name="projectPath"/>, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// specifically in the context of the framework specified in <paramref name="framework"/> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// and the candidate runtime identifiers specified in <param name="runtimeIdentifiers"/> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// </summary> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  static  ProjectContext  Create ( string  projectPath ,  NuGetFramework  framework ,  IEnumerable < string >  runtimeIdentifiers ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if ( projectPath . EndsWith ( Project . FileName ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                projectPath  =  Path . GetDirectoryName ( projectPath ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  new  ProjectContextBuilder ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-29 01:35:23 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        . WithProjectDirectory ( projectPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        . WithTargetFramework ( framework ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        . WithRuntimeIdentifiers ( runtimeIdentifiers ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        . Build ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-13 14:31:29 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// <summary> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// Creates a project context for each framework located in the project at <paramref name="projectPath"/> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        /// </summary> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        public  static  IEnumerable < ProjectContext >  CreateContextForEachFramework ( string  projectPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if ( ! projectPath . EndsWith ( Project . FileName ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                projectPath  =  Path . Combine ( projectPath ,  Project . FileName ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            var  project  =  ProjectReader . GetProject ( projectPath ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            foreach ( var  framework  in  project . GetTargetFrameworks ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                yield  return  new  ProjectContextBuilder ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-29 01:35:23 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                . WithProject ( project ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                . WithTargetFramework ( framework . FrameworkName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                . Build ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-13 14:31:29 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}