コード例 #1
0
        protected virtual void Refresh()
        {
            // Let MSBuild know which configuration we are working with
            ThreadHelper.ThrowIfNotOnUIThread();
            _project.SetConfiguration(_projectCfg.ConfigCanonicalName);

            // Generate dependencies if such a task exist
            if (_project.ProjectInstance.Targets.ContainsKey(ProjectFileConstants.AllProjectOutputGroups))
            {
                bool succeeded = false;
                _project.BuildTarget(ProjectFileConstants.AllProjectOutputGroups, out succeeded);
                // The next line triggers an exception for a customer that works with JetBrains.
                //Debug.Assert(succeeded, "Failed to build target: " + ProjectFileConstants.AllProjectOutputGroups);
            }

            // Rebuild the content of our list of output
            string outputType = _targetName + "Output";

            this._outputs.Clear();
            foreach (MSBuildExecution.ProjectItemInstance assembly in MSBuildProjectInstance.GetItems(_project.ProjectInstance, outputType))
            {
                Output output = new Output(_project, assembly);
                this._outputs.Add(output);

                // See if it is our key output
                if (String.Compare(MSBuildItem.GetMetadataValue(assembly, "IsKeyOutput"), true.ToString(), StringComparison.OrdinalIgnoreCase) == 0)
                {
                    _keyOutput = output;
                }
            }

            _project.SetCurrentConfiguration();

            // Now that the group is built we have to check if it is invalidated by a property
            // change on the project.
            _project.OnProjectPropertyChanged += new EventHandler <ProjectPropertyChangedArgs>(OnProjectPropertyChanged);
        }
コード例 #2
0
        /// <summary>
        /// Adds references to this container from a MSBuild project.
        /// </summary>
        public void LoadReferencesFromBuildProject(MSBuild.Project buildProject)
        {
            XSharpProjectPackage.Instance.UIThread.MustBeCalledFromUIThread();
            List <ReferenceNode> duplicatedNode = new List <ReferenceNode>();
            BuildResult          buildResult    = this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences);

            var children = new List <ReferenceNode>();

            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);

                    if (node != null)
                    {
                        // Make sure that we do not want to add the item twice to the ui hierarchy
                        // We are using here the UI representation of the Node namely the Caption to find that out, in order to
                        // avoid different representation problems.
                        // Example :<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                        //		  <Reference Include="EnvDTE80" />
                        bool found = false;
                        for (HierarchyNode n = this.FirstChild; n != null && !found; n = n.NextSibling)
                        {
                            if (String.Compare(n.Caption, node.Caption, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            this.AddChild(node);
                            children.Add(node);
                        }
                        else
                        {
                            duplicatedNode.Add(node);
                        }
                    }
                }
            }
            // Now manage duplicates
            if (duplicatedNode.Count > 0)
            {
                // Make a backup first
                string original   = buildProject.FullPath;
                string backupName = Path.ChangeExtension(original, ".backup");
                if (Utilities.DeleteFileSafe(backupName))
                {
                    File.Copy(original, backupName);
                }
                foreach (ReferenceNode node in duplicatedNode)
                {
                    //this.RemoveChild( node );
                    node.Remove(false);
                }
                buildProject.Save(original);
            }
            var references = buildResult.ProjectInstance.GetItems(ProjectFileConstants.ReferencePath);

            //var references = MSBuildProjectInstance.GetItems(buildResult.ProjectInstance, ProjectFileConstants.ReferencePath);
            foreach (var reference in references)
            {
                string fullName = MSBuildItem.GetEvaluatedInclude(reference);
                string name     = Path.GetFileNameWithoutExtension(fullName);
                foreach (var child in children)
                {
                    if (child is XSharpAssemblyReferenceNode && child.Caption == name)
                    {
                        var xChild = child as XSharpAssemblyReferenceNode;
                        xChild.AssemblyPath = fullName;
                        xChild.SetHintPathAndPrivateValue(buildResult.ProjectInstance, reference);
                    }
                }
            }
        }