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


            if (project.ProjectInstance.Targets.ContainsKey(ProjectFileConstants.AllProjectOutputGroups))
            {
                bool succeeded = false;
                project.BuildTarget(ProjectFileConstants.AllProjectOutputGroups, out succeeded);
                Debug.Assert(succeeded, "Failed to build target: " + ProjectFileConstants.AllProjectOutputGroups);
            }

            // Rebuild the content of our list of output
            string outputType = this.targetName + "KeyOutput";

            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>
        /// Does the actual job of resolving an assembly reference. We need a private method that does not violate
        /// calling virtual method from the constructor.
        /// </summary>
        protected internal virtual void ResolveAssemblyReference()
        {
            if (this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return;
            }
            ThreadHelper.ThrowIfNotOnUIThread();

            var instance = this.ProjectMgr.ProjectInstance;
            // must call MsBuild again
            var group = MSBuildProjectInstance.GetItems(instance, ProjectFileConstants.ReferencePath).ToArray();

            // RvdH Only call ResolveAsemblyReferences when we cannot find any items
            if (group == null || group.Length == 0)
            {
                BuildInstance(this.ProjectMgr, instance, MsBuildTarget.ResolveAssemblyReferences, out var submission);
                group = MSBuildProjectInstance.GetItems(instance, ProjectFileConstants.ReferencePath).ToArray();
            }
            if (group != null)
            {
                foreach (var item in group)
                {
                    string fullPath = item.GetMetadataValue("fullpath");
                    if (!File.Exists(fullPath))
                    {
                        continue;
                    }
                    AssemblyName name = AssemblyName.GetAssemblyName(fullPath);

                    // Try with full assembly name and then with weak assembly name.
                    if (String.Compare(name.FullName, this.assemblyName.FullName, StringComparison.OrdinalIgnoreCase) == 0 ||
                        String.Compare(name.Name, this.assemblyName.Name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (!NativeMethods.IsSamePath(fullPath, this.assemblyPath))
                        {
                            // set the full path now.
                            this.assemblyPath = fullPath;

                            // We have a new item to listen too, since the assembly reference is resolved from a different place.
                            this.ObserveItem(assemblyPath);
                        }
                        this.resolvedAssemblyName = name;
                        // No hint path is needed since the assembly path will always be resolved.

                        // cache the propertynames and the item.
                        resolvedProperties = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                        foreach (var str in item.MetadataNames)
                        {
                            resolvedProperties.Add(str);
                        }
                        prjitem = item;
                        return;
                    }
                }
                // when we get here then the assembly was not resolved by MsBuild. Maybe the reference was not persisted yet ?
                return;
            }
        }
コード例 #3
0
        internal override void ResolveAssemblyReference()
        {
            if (this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return;
            }

            var instance = this.ProjectMgr.ProjectInstance;
            // do not call MsBuild again that will slow down things a lot.
            var group = MSBuildProjectInstance.GetItems(instance, ProjectFileConstants.ReferencePath);

            if (group != null)
            {
                foreach (var item in group)
                {
                    string fullPath = item.GetMetadataValue("fullpath");
                    if (!File.Exists(fullPath))
                    {
                        continue;
                    }
                    AssemblyName name = AssemblyName.GetAssemblyName(fullPath);

                    // Try with full assembly name and then with weak assembly name.
                    if (String.Compare(name.FullName, this.AssemblyName.FullName, StringComparison.OrdinalIgnoreCase) == 0 ||
                        String.Compare(name.Name, this.AssemblyName.Name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (!NativeMethods.IsSamePath(fullPath, this.AssemblyPath))
                        {
                            // set the full path now.
                            this.AssemblyPath = fullPath;

                            // We have a new item to listen too, since the assembly reference is resolved from a different place.
                            this.fileChangeListener.ObserveItem(this.AssemblyPath);
                        }
                        this.ResolvedAssembly = name;
                        // No hint path is needed since the assembly path will always be resolved.
                        // cache the propertynames and the item.
                        resolvedProperties = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                        foreach (var str in item.MetadataNames)
                        {
                            resolvedProperties.Add(str);
                        }
                        prjitem = item;

                        return;
                    }
                }
                // when we get here then the assembly was not resolved by MsBuild. Maybe the reference was not persisted yet ?
                var xnode = ProjectMgr as XSharpProjectNode;
                if (xnode != null && !xnode.IsLoading)
                {
                    base.ResolveAssemblyReference();
                }

                return;
            }
        }
コード例 #4
0
        // added to make sure our key output is picked up properly
        protected override void Refresh()
        {
            // Let MSBuild know which configuration we are working with
            this.Project.SetConfiguration(this.ProjectCfg.ConfigCanonicalName);
            ThreadHelper.ThrowIfNotOnUIThread();

            // Generate dependencies if such a task exist
            if (this.Project.ProjectInstance.Targets.ContainsKey(ProjectFileConstants.AllProjectOutputGroups))
            {
                bool succeeded = false;
                this.Project.BuildTarget(ProjectFileConstants.AllProjectOutputGroups, out succeeded);
                if (!succeeded)
                {
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        Debug.WriteLine("Failed to build target {0}", this.TargetName);
                    }
                    this.Outputs.Clear();
                    return;
                }
            }
            // Rebuild the content of our list of output
            string outputType = this.TargetName + "Output";

            if (TargetName == "BuiltProjectOutputGroup")
            {
                outputType = this.TargetName + "KeyOutput";
            }
            this.Outputs.Clear();
            foreach (MSBuildExecution.ProjectItemInstance item in MSBuildProjectInstance.GetItems(this.Project.ProjectInstance, outputType))
            {
                Output output = new Output(this.Project, item);
                this.Outputs.Add(output);

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

            this.Project.SetCurrentConfiguration();

            // Now that the group is built we have to check if it is invalidated by a property
            // change on the project.
            this.Project.OnProjectPropertyChanged += new EventHandler <ProjectPropertyChangedArgs>(OnProjectPropertyChanged);
        }
コード例 #5
0
        protected internal virtual void SetHintPathAndPrivateValue(ProjectInstance instance)
        {
            // Private means local copy; we want to know if it is already set to not override the default
            string privateValue = this.ItemNode.GetMetadata(ProjectFileConstants.Private);

            ThreadHelper.ThrowIfNotOnUIThread();

            // Get the list of items which require HintPath
            IEnumerable <ProjectItemInstance> references = MSBuildProjectInstance.GetItems(instance, MsBuildGeneratedItemType.ReferenceCopyLocalPaths);

            // Remove the HintPath, we will re-add it below if it is needed
            if (!String.IsNullOrEmpty(this.assemblyPath))
            {
                this.ItemNode.SetMetadata(ProjectFileConstants.HintPath, null);
            }

            // Now loop through the generated References to find the corresponding one
            foreach (ProjectItemInstance reference in references)
            {
                string fileName = Path.GetFileNameWithoutExtension(MSBuildItem.GetEvaluatedInclude(reference));
                if (String.Compare(fileName, this.assemblyName.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // We found it, now set some properties based on this.

                    string hintPath = MSBuildItem.GetMetadataValue(reference, ProjectFileConstants.HintPath);
                    if (!String.IsNullOrEmpty(hintPath))
                    {
                        if (Path.IsPathRooted(hintPath))
                        {
                            hintPath = PackageUtilities.GetPathDistance(this.ProjectMgr.BaseURI.Uri, new Uri(hintPath));
                        }

                        this.ItemNode.SetMetadata(ProjectFileConstants.HintPath, hintPath);
                        // If this is not already set, we default to true
                        if (String.IsNullOrEmpty(privateValue))
                        {
                            this.ItemNode.SetMetadata(ProjectFileConstants.Private, true.ToString());
                        }
                    }
                    break;
                }
            }
        }
コード例 #6
0
        private void SetProjectItemsThatRelyOnReferencesToBeResolved(bool renameItemNode)
        {
            // Call MSBuild to build the target ResolveComReferences
            bool success;

            ErrorHandler.ThrowOnFailure(this.ProjectMgr.BuildTarget(MsBuildTarget.ResolveComReferences, out success));
            if (!success)
            {
                throw new InvalidOperationException();
            }

            // Now loop through the generated COM References to find the corresponding one
            var instance = this.ProjectMgr.ProjectInstance;

            AssemblyReferenceNode.BuildInstance(this.ProjectMgr, instance, MsBuildTarget.ResolveAssemblyReferences);
            var comReferences = MSBuildProjectInstance.GetItems(instance, MsBuildGeneratedItemType.ComReferenceWrappers);

            foreach (var reference in comReferences)
            {
                if (String.Compare(MSBuildItem.GetMetadataValue(reference, ProjectFileConstants.Guid), this.typeGuid.ToString("B"), StringComparison.OrdinalIgnoreCase) == 0 &&
                    String.Compare(MSBuildItem.GetMetadataValue(reference, ProjectFileConstants.VersionMajor), this.majorVersionNumber, StringComparison.OrdinalIgnoreCase) == 0 &&
                    String.Compare(MSBuildItem.GetMetadataValue(reference, ProjectFileConstants.VersionMinor), this.minorVersionNumber, StringComparison.OrdinalIgnoreCase) == 0 &&
                    String.Compare(MSBuildItem.GetMetadataValue(reference, ProjectFileConstants.Lcid), this.lcid, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    string name = MSBuildItem.GetEvaluatedInclude(reference);
                    if (Path.IsPathRooted(name))
                    {
                        this.projectRelativeFilePath = name;
                    }
                    else
                    {
                        this.projectRelativeFilePath = Path.Combine(this.ProjectMgr.ProjectFolder, name);
                    }

                    if (renameItemNode)
                    {
                        this.ItemNode.Rename(Path.GetFileNameWithoutExtension(name));
                    }
                    break;
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Does the actual job of resolving an assembly reference. We need a private method that does not violate
        /// calling virtual method from the constructor.
        /// </summary>
        private void ResolveAssemblyReference()
        {
            if (this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return;
            }

            var instance = this.ProjectMgr.ProjectInstance;

            BuildInstance(this.ProjectMgr, instance, MsBuildTarget.ResolveAssemblyReferences);
            IEnumerable <ProjectItemInstance> group = MSBuildProjectInstance.GetItems(instance, ProjectFileConstants.ReferencePath);

            if (group != null)
            {
                foreach (var item in group)
                {
                    string fullPath = this.GetFullPathFromPath(MSBuildItem.GetEvaluatedInclude(item));
                    System.Reflection.AssemblyName name = System.Reflection.AssemblyName.GetAssemblyName(fullPath);

                    // Try with full assembly name and then with weak assembly name.
                    if (String.Compare(name.FullName, this.assemblyName.FullName, StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(name.Name, this.assemblyName.Name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (!NativeMethods.IsSamePath(fullPath, this.assemblyPath))
                        {
                            // set the full path now.
                            this.assemblyPath = fullPath;

                            // We have a new item to listen too, since the assembly reference is resolved from a different place.
                            this.fileChangeListener.ObserveItem(this.assemblyPath);
                        }

                        this.resolvedAssemblyName = name;

                        // No hint path is needed since the assembly path will always be resolved.
                        return;
                    }
                }
            }
        }
コード例 #8
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);
        }
コード例 #9
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 = 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);
                    }
                }
            }
        }