private PackageDependency CreateDependencyFromProject(Project project) { try { var projectFactory = new ProjectFactory(project); projectFactory.Build = Build; projectFactory.ProjectProperties = ProjectProperties; projectFactory.BuildProject(); var builder = new PackageBuilder(); try { AssemblyMetadataExtractor.ExtractMetadata(builder, projectFactory.TargetPath); } catch { projectFactory.ExtractMetadataFromProject(builder); } projectFactory.InitializeProperties(builder); projectFactory.ProcessNuspec(builder, null); return(new PackageDependency( builder.Id, VersionUtility.ParseVersionSpec(builder.Version.ToString()))); } catch (Exception ex) { var message = string.Format( CultureInfo.InvariantCulture, NuGetResources.Error_ProcessingNuspecFile, project.FullPath, ex.Message); throw new CommandLineException(message, ex); } }
/// <summary> /// Recursively execute the specified action on the current project and /// projects referenced by the current project. /// </summary> /// <param name="action">The action to be executed.</param> /// <param name="alreadyAppliedProjects">The collection of projects that have been processed. /// It is used to avoid processing the same project more than once.</param> private void RecursivelyApply(Action <ProjectFactory> action, ProjectCollection alreadyAppliedProjects) { action(this); foreach (var item in _project.GetItems(ProjectReferenceItemType)) { string fullPath = item.GetMetadataValue("FullPath"); if (!string.IsNullOrEmpty(fullPath) && !NuspecFileExists(fullPath) && alreadyAppliedProjects.GetLoadedProjects(fullPath).IsEmpty()) { var project = new Project( fullPath, globalProperties: null, toolsVersion: null, projectCollection: alreadyAppliedProjects); var referencedProject = new ProjectFactory(project); referencedProject.Logger = _logger; referencedProject.IncludeSymbols = IncludeSymbols; referencedProject.Build = Build; referencedProject.IncludeReferencedProjects = IncludeReferencedProjects; referencedProject.ProjectProperties = ProjectProperties; referencedProject.TargetFramework = TargetFramework; referencedProject.BuildProject(); referencedProject.RecursivelyApply(action, alreadyAppliedProjects); } } }
private PackageDependency CreateDependencyFromProject(Project project) { try { var projectFactory = new ProjectFactory(project); projectFactory.Build = Build; projectFactory.ProjectProperties = ProjectProperties; projectFactory.BaseTargetPath = BaseTargetPath; projectFactory.SolutionName = SolutionName; projectFactory.BuildProject(); var builder = new PackageBuilder(); try { AssemblyMetadataExtractor.ExtractMetadata(builder, projectFactory.TargetPath); } catch { projectFactory.ExtractMetadataFromProject(builder); } projectFactory.InitializeProperties(builder); projectFactory.ProcessNuspec(builder, null); return new PackageDependency( builder.Id, VersionUtility.ParseVersionSpec(builder.Version.ToString())); } catch (Exception ex) { var message = string.Format( CultureInfo.InvariantCulture, LocalizedResourceManager.GetString("Error_ProcessingNuspecFile"), project.FullPath, ex.Message); throw new CommandLineException(message, ex); } }
/// <summary> /// Recursively execute the specified action on the current project and /// projects referenced by the current project. /// </summary> /// <param name="action">The action to be executed.</param> /// <param name="alreadyAppliedProjects">The collection of projects that have been processed. /// It is used to avoid processing the same project more than once.</param> private void RecursivelyApply(Action<ProjectFactory> action, ProjectCollection alreadyAppliedProjects) { action(this); foreach (var item in _project.GetItems(ProjectReferenceItemType)) { string fullPath = item.GetMetadataValue("FullPath"); if (!string.IsNullOrEmpty(fullPath) && !NuspecFileExists(fullPath) && alreadyAppliedProjects.GetLoadedProjects(fullPath).IsEmpty()) { var project = new Project( fullPath, globalProperties: null, toolsVersion: null, projectCollection: alreadyAppliedProjects); var referencedProject = new ProjectFactory(project); referencedProject.Logger = _logger; referencedProject.IncludeSymbols = IncludeSymbols; referencedProject.Build = Build; referencedProject.IncludeReferencedProjects = IncludeReferencedProjects; referencedProject.ProjectProperties = ProjectProperties; referencedProject.TargetFramework = TargetFramework; referencedProject.BaseTargetPath = BaseTargetPath; referencedProject.SolutionName = SolutionName; referencedProject.BuildProject(); referencedProject.RecursivelyApply(action, alreadyAppliedProjects); } } }