Exemple #1
0
 public GroupingReferenceNodeProperties(GroupingReferenceNode owner)
     : base(owner)
 {
     this.owner = owner;
 }
        /// <summary>
        /// Adds references to this container from a MSBuild project.
        /// </summary>
        public void LoadReferencesFromBuildProject(Microsoft.Build.Evaluation.Project buildProject)
        {
            Build.Execution.ProjectInstance projectInstanceToSearchExpandedReferences = null;
            // if project uses implicitly expanded list of references,
            // evaluate ImplicitlyExpandTargetFramework target and collect all resolved 'ReferencePath' items
            // later we'll group them and create special reference nodes that represent assembly groupings
            if (ProjectMgr.ImplicitlyExpandTargetFramework)
            {
                var res = ProjectMgr.Build(MsBuildTarget.ImplicitlyExpandTargetFramework);
                if (res.IsSuccessful)
                {
                    projectInstanceToSearchExpandedReferences = res.ProjectInstance;
                }
            }

            // collect groupled framework references
            if (projectInstanceToSearchExpandedReferences != null)
            {
                // fetch all 'ReferencePath' items that were resolved from implicitly expanded references (metadata#ResolvedFrom = ImplicitlyExpandTargetFramework)
                var groupings =
                    projectInstanceToSearchExpandedReferences
                    .GetItems(ProjectFileConstants.ReferencePath)
                    .Where(item => string.Equals(item.GetMetadataValue(ProjectFileConstants.ResolvedFrom), MsBuildTarget.ImplicitlyExpandTargetFramework, StringComparison.OrdinalIgnoreCase))
                    .Select(
                        item =>
                        new
                {
                    referenceGroupingDisplayName = item.GetMetadataValue("ReferenceGroupingDisplayName"),
                    referenceGrouping            = item.GetMetadataValue("ReferenceGrouping"),
                    file = item.EvaluatedInclude
                }
                        )
                    .Where(r =>
                           !string.IsNullOrEmpty(r.referenceGrouping) &&
                           !string.IsNullOrEmpty(r.referenceGroupingDisplayName) &&
                           !string.IsNullOrEmpty(r.file) &&
                           File.Exists(r.file)
                           )
                    .GroupBy(r => r.referenceGrouping);

                foreach (var grouping in groupings)
                {
                    var version = ParseVersionFromReferenceGrouping(grouping.Key);
                    if (version == null)
                    {
                        continue;
                    }
                    // pick property values from the first item - they should be the same for all elements in the grouping
                    var first        = grouping.First();
                    var groupedFiles = grouping.Select(x => x.file).ToArray();

                    var versonText = string.Format(
                        "{0}.{1}.{2}.{3}",
                        version.Major,
                        version.Minor,
                        version.Build != -1 ? version.Build : 0,
                        version.Revision != -1 ? version.Revision : 0
                        );

                    var node = new GroupingReferenceNode(ProjectMgr, first.referenceGroupingDisplayName, first.referenceGrouping, Path.GetDirectoryName(first.file), versonText, groupedFiles);
                    AddChild(node);
                }
            }

            BuildResult buildResult = this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences);

            foreach (string referenceType in SupportedReferenceTypes)
            {
                bool isAssemblyReference = referenceType == ProjectFileConstants.Reference;
                if (isAssemblyReference && !buildResult.IsSuccessful)
                {
                    continue;
                }

                foreach (var item in MSBuildProject.GetItems(buildProject, referenceType))
                {
                    ProjectElement element = new ProjectElement(this.ProjectMgr, item, false);

                    ReferenceNode node = CreateReferenceNode(referenceType, element, buildResult);
                    if (node != null)
                    {
                        this.AddChild(node);
                    }
                    if (isAssemblyReference)
                    {
                        ProjectMgr.UpdateValueOfCanUseTargetFSharpCoreReferencePropertyIfNecessary(node);
                    }
                }
            }
        }
        /// <summary>
        /// Adds references to this container from a MSBuild project.
        /// </summary>
        public void LoadReferencesFromBuildProject(Microsoft.Build.Evaluation.Project buildProject)
        {            
            Build.Execution.ProjectInstance projectInstanceToSearchExpandedReferences = null;
            // if project uses implicitly expanded list of references, 
            // evaluate ImplicitlyExpandTargetFramework target and collect all resolved 'ReferencePath' items
            // later we'll group them and create special reference nodes that represent assembly groupings
            if (ProjectMgr.ImplicitlyExpandTargetFramework)
            {
                var res = ProjectMgr.Build(MsBuildTarget.ImplicitlyExpandTargetFramework);
                if (res.IsSuccessful)
                {
                    projectInstanceToSearchExpandedReferences = res.ProjectInstance;
                }                
            }

            // collect groupled framework references
            if (projectInstanceToSearchExpandedReferences != null)
            {
                // fetch all 'ReferencePath' items that were resolved from implicitly expanded references (metadata#ResolvedFrom = ImplicitlyExpandTargetFramework)
                var groupings =
                    projectInstanceToSearchExpandedReferences
                        .GetItems(ProjectFileConstants.ReferencePath)
                        .Where(item => string.Equals(item.GetMetadataValue(ProjectFileConstants.ResolvedFrom), MsBuildTarget.ImplicitlyExpandTargetFramework, StringComparison.OrdinalIgnoreCase))
                        .Select(
                            item =>
                                new
                                {
                                    referenceGroupingDisplayName = item.GetMetadataValue("ReferenceGroupingDisplayName"),
                                    referenceGrouping = item.GetMetadataValue("ReferenceGrouping"),
                                    file =  item.EvaluatedInclude
                                }
                            )
                        .Where(r =>
                            !string.IsNullOrEmpty(r.referenceGrouping) &&
                            !string.IsNullOrEmpty(r.referenceGroupingDisplayName) &&
                            !string.IsNullOrEmpty(r.file) &&
                            File.Exists(r.file)
                            )
                        .GroupBy(r => r.referenceGrouping);

                foreach (var grouping in groupings)
                {
                    var version = ParseVersionFromReferenceGrouping(grouping.Key);
                    if (version == null)
                    {
                        continue;
                    }
                    // pick property values from the first item - they should be the same for all elements in the grouping
                    var first = grouping.First();
                    var groupedFiles = grouping.Select(x => x.file).ToArray();

                    var versonText = string.Format(
                        "{0}.{1}.{2}.{3}",
                        version.Major,
                        version.Minor,
                        version.Build != -1 ? version.Build : 0,
                        version.Revision != -1 ? version.Revision : 0
                        );

                    var node = new GroupingReferenceNode(ProjectMgr, first.referenceGroupingDisplayName, first.referenceGrouping, Path.GetDirectoryName(first.file), versonText, groupedFiles);
                    AddChild(node);
                }
            }

            BuildResult buildResult = this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences);
            foreach (string referenceType in SupportedReferenceTypes)
            {
                bool isAssemblyReference = referenceType == ProjectFileConstants.Reference;
                if (isAssemblyReference && !buildResult.IsSuccessful)
                {
                    continue;
                }

                foreach (var item in MSBuildProject.GetItems(buildProject, referenceType))
                {
                    ProjectElement element = new ProjectElement(this.ProjectMgr, item, false);

                    ReferenceNode node = CreateReferenceNode(referenceType, element, buildResult);
                    if (node != null)
                    {
                        this.AddChild(node);
                    }
                    if (isAssemblyReference)
                    {
                        ProjectMgr.UpdateValueOfCanUseTargetFSharpCoreReferencePropertyIfNecessary(node);
                    }
                }
            }
        }
 public GroupingReferenceNodeProperties(GroupingReferenceNode owner)
     : base(owner)
 {
     this.owner = owner;
 }