Exemplo n.º 1
0
        private void ResolveFromBuiltProject(string assemblyInclude, BuildResult buildResult)
        {
            if (!buildResult.IsSuccessful)
            {
                // ResolveAssemblyReferences build failed.
                return;
            }
            System.Collections.Generic.IEnumerable <ProjectItemInstance> group = buildResult.ProjectInstance.GetItems(ProjectFileConstants.ReferencePath);
            if (group != null)
            {
                foreach (var item in group)
                {
                    // TODO, the logic here is too brittle - if a user adds a 'logical duplicate' assembly with a different name, it may not find resolution
                    // and then wind up with wrong diagnostic later because it failed to resolve (when in fact it would resolve if not for duplicate)
                    if (0 == string.Compare(assemblyInclude, MSBuildItem.GetMetadataValue(item, "OriginalItemSpec"), StringComparison.Ordinal))
                    {
                        var fusionName = MSBuildItem.GetMetadataValue(item, "FusionName");
                        if (!string.IsNullOrEmpty(fusionName))
                        {
                            this.resolvedInfo.ResolvedAssemblyName = new System.Reflection.AssemblyName(fusionName);
                            this.resolvedInfo.AssemblyName         = this.resolvedInfo.ResolvedAssemblyName;
                        }
                        this.resolvedInfo.IsPlatformAssembly      = 0 == string.Compare(MSBuildItem.GetMetadataValue(item, ProjectFileConstants.ResolvedFrom), "{TargetFrameworkDirectory}", StringComparison.OrdinalIgnoreCase);
                        this.resolvedInfo.IsNoPIA                 = 0 == string.Compare(MSBuildItem.GetMetadataValue(item, ProjectFileConstants.EmbedInteropTypes), "true", StringComparison.OrdinalIgnoreCase);
                        this.resolvedInfo.CopyLocalDefault        = 0 == string.Compare(MSBuildItem.GetMetadataValue(item, ProjectFileConstants.CopyLocal), "true", StringComparison.OrdinalIgnoreCase);
                        this.resolvedInfo.WasSuccessfullyResolved = true;
                        this.myAssemblyPath = MSBuildItem.GetEvaluatedInclude(item);

                        if (!Path.IsPathRooted(this.myAssemblyPath))
                        {
                            this.myAssemblyPath = Path.Combine(this.ProjectMgr.ProjectFolder, this.myAssemblyPath);
                        }
                        // finished and found original item
                        return;
                    }
                }
            }
            // finished without finding original item
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set an attribute on the project element
        /// </summary>
        /// <param name="attributeName">Name of the attribute to set</param>
        /// <param name="attributeValue">Value to give to the attribute</param>
        public void SetMetadata(string attributeName, string attributeValue)
        {
            Debug.Assert(String.Compare(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase) != 0, "Use rename as this won't work");

            if (this.IsVirtual)
            {
                // For virtual node, use our virtual property collection
                if (virtualProperties.ContainsKey(attributeName))
                {
                    virtualProperties.Remove(attributeName);
                }
                virtualProperties.Add(attributeName, attributeValue);
                return;
            }

            // Build Action is the type, not a property, so intercept
            if (String.Compare(attributeName, ProjectFileConstants.BuildAction, StringComparison.OrdinalIgnoreCase) == 0)
            {
                item.ItemType = attributeValue;
                return;
            }

            // Check out the project file.
            if (!this.itemProject.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            if (attributeValue == null)
            {
                item.RemoveMetadata(attributeName);
            }
            else
            {
                MSBuildItem.SetMetadataValue(item, attributeName, attributeValue);
            }
            itemProject.SetProjectFileDirty(true);
        }
Exemplo n.º 3
0
 internal override void ResolveReference(BuildResult buildResult)
 {
     Debug.Assert(this.ItemNode != null && this.ItemNode.Item != null, "called ResolveReference before initializing ItemNode");
     this.ResolveFromBuiltProject(MSBuildItem.GetEvaluatedInclude(this.ItemNode.Item), buildResult);
 }