public ProjectDescription GetDescription(FrameworkName targetFramework, Project project) { // This never returns null var targetFrameworkInfo = project.GetTargetFramework(targetFramework); var targetFrameworkDependencies = new List<LibraryDependency>(targetFrameworkInfo.Dependencies); if (targetFramework != null && VersionUtility.IsDesktop(targetFramework)) { targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("mscorlib", frameworkReference: true) }); targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("System", frameworkReference: true) }); if (targetFramework.Version >= Constants.Version35) { targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("System.Core", frameworkReference: true) }); if (targetFramework.Version >= Constants.Version40) { targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("Microsoft.CSharp", frameworkReference: true) }); } } } var dependencies = project.Dependencies.Concat(targetFrameworkDependencies).ToList(); var loadableAssemblies = new List<string>(); if (project.IsLoadable) { loadableAssemblies.Add(project.Name); } // Mark the library as unresolved if there were specified frameworks // and none of them resolved bool unresolved = targetFrameworkInfo.FrameworkName == null; return new ProjectDescription( new LibraryRange(project.Name, frameworkReference: false), project, dependencies, loadableAssemblies, targetFrameworkInfo, !unresolved); }
public ProjectDescription GetDescription(FrameworkName targetFramework, Project project) { // This never returns null var targetFrameworkInfo = project.GetTargetFramework(targetFramework); var targetFrameworkDependencies = new List <LibraryDependency>(targetFrameworkInfo.Dependencies); if (targetFramework != null && VersionUtility.IsDesktop(targetFramework)) { targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("mscorlib", frameworkReference: true) }); targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("System", frameworkReference: true) }); if (targetFramework.Version >= Constants.Version35) { targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("System.Core", frameworkReference: true) }); if (targetFramework.Version >= Constants.Version40) { targetFrameworkDependencies.Add(new LibraryDependency { LibraryRange = new LibraryRange("Microsoft.CSharp", frameworkReference: true) }); } } } var dependencies = project.Dependencies.Concat(targetFrameworkDependencies).ToList(); var loadableAssemblies = new List <string>(); if (project.IsLoadable) { loadableAssemblies.Add(project.Name); } // Mark the library as unresolved if there were specified frameworks // and none of them resolved bool unresolved = targetFrameworkInfo.FrameworkName == null; return(new ProjectDescription( new LibraryRange(project.Name, frameworkReference: false), project, dependencies, loadableAssemblies, targetFrameworkInfo, !unresolved)); }
public static LibraryExport ExportProject(Project project, CompilationEngine compilationEngine, string aspect, FrameworkName targetFramework, string configuration) { Logger.TraceInformation($"[{nameof(ProjectExporter)}]: {nameof(ExportProject)}({project.Name}, {aspect}, {targetFramework}, {configuration})"); var targetFrameworkInformation = project.GetTargetFramework(targetFramework); // This is the target framework defined in the project. If there were no target frameworks // defined then this is the targetFramework specified if (targetFrameworkInformation.FrameworkName != null) { targetFramework = targetFrameworkInformation.FrameworkName; } var key = Tuple.Create(project.Name, targetFramework, configuration, aspect); return compilationEngine.CompilationCache.Cache.Get<LibraryExport>(key, ctx => { var metadataReferences = new List<IMetadataReference>(); var sourceReferences = new List<ISourceReference>(); if (!string.IsNullOrEmpty(targetFrameworkInformation.AssemblyPath)) { // Project specifies a pre-compiled binary. We're done! var assemblyPath = ResolvePath(project, configuration, targetFrameworkInformation.AssemblyPath); var pdbPath = ResolvePath(project, configuration, targetFrameworkInformation.PdbPath); metadataReferences.Add(new CompiledProjectMetadataReference(project.ToCompilationContext(targetFramework, configuration, aspect), assemblyPath, pdbPath)); } else { // We need to compile the project. var provider = project.CompilerServices?.ProjectCompiler ?? Project.DefaultCompiler; // Find the project compiler var projectCompiler = compilationEngine.GetCompiler(provider); Logger.TraceInformation("[{0}]: GetProjectReference({1}, {2}, {3}, {4})", provider.TypeName, project.Name, targetFramework, configuration, aspect); // Get the exports for the project dependencies var projectExport = new Lazy<LibraryExport>(() => ExportProjectDependencies(project, targetFramework, configuration, aspect, compilationEngine)); // Resolve the project export IMetadataProjectReference projectReference = projectCompiler.CompileProject( project.ToCompilationContext(targetFramework, configuration, aspect), () => projectExport.Value, () => CompositeResourceProvider.Default.GetResources(project)); metadataReferences.Add(projectReference); // Shared sources foreach (var sharedFile in project.Files.SharedFiles) { sourceReferences.Add(new SourceFileReference(sharedFile)); } } return new LibraryExport(metadataReferences, sourceReferences); }); }
private static DependencyInformation ResolveDependencyInfo(DnxProject project, FrameworkName frameworkName) { var cacheKey = Tuple.Create("DependencyInformation", project.Name, "Debug", frameworkName); return(cache.Get <DependencyInformation>(cacheKey, ctx => { var applicationHostContext = GetApplicationHostContext(project, "Debug", frameworkName); var info = new DependencyInformation { HostContext = applicationHostContext, ProjectReferences = new List <ProjectReference>(), References = new List <string>(), ExportedSourcesFiles = new List <string>() }; foreach (var library in applicationHostContext.LibraryManager.GetLibraryDescriptions()) { // Skip unresolved libraries if (!library.Resolved) { continue; } if (string.Equals(library.Type, "Project") && !string.Equals(library.Identity.Name, project.Name)) { DnxProject referencedProject = GetProject(library.Path); if (referencedProject == null) { // Should never happen continue; } var targetFrameworkInformation = referencedProject.GetTargetFramework(library.Framework); // If this is an assembly reference then treat it like a file reference if (!string.IsNullOrEmpty(targetFrameworkInformation.AssemblyPath) && string.IsNullOrEmpty(targetFrameworkInformation.WrappedProject)) { string assemblyPath = GetProjectRelativeFullPath(referencedProject, targetFrameworkInformation.AssemblyPath); info.References.Add(assemblyPath); } else { string wrappedProjectPath = null; if (!string.IsNullOrEmpty(targetFrameworkInformation.WrappedProject)) { wrappedProjectPath = GetProjectRelativeFullPath(referencedProject, targetFrameworkInformation.WrappedProject); } info.ProjectReferences.Add(new ProjectReference { Name = referencedProject.Name, Framework = library.Framework, Path = library.Path, WrappedProjectPath = wrappedProjectPath, Project = referencedProject }); } } } var libraryExporter = new LibraryExporter( applicationHostContext.LibraryManager, null, "Debug"); var exportWithoutProjects = libraryExporter.GetNonProjectExports(project.Name); foreach (var reference in exportWithoutProjects.MetadataReferences) { var fileReference = reference as IMetadataFileReference; if (fileReference != null) { info.References.Add(fileReference.Path); } } foreach (var sourceFileReference in exportWithoutProjects.SourceReferences.OfType <ISourceFileReference>()) { info.ExportedSourcesFiles.Add(sourceFileReference.Path); } return info; })); }