Exemplo n.º 1
0
        /// <summary>
        /// Get the value of an attribute on a project element
        /// </summary>
        /// <param name="attributeName">Name of the attribute to get the value for</param>
        /// <returns>Value of the attribute</returns>
        public string GetMetadata(string attributeName)
        {
            if (this.IsVirtual)
            {
                // For virtual items, use our virtual property collection
                if (!virtualProperties.ContainsKey(attributeName))
                {
                    return(String.Empty);
                }
                return(virtualProperties[attributeName]);
            }

            // cannot ask MSBuild for Include, so intercept it and return the corresponding property
            if (String.Compare(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(MSBuildItem.GetEvaluatedInclude(item));
            }

            // Build Action is the type, not a property, so intercept this one as well
            if (String.Compare(attributeName, ProjectFileConstants.BuildAction, StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(MSBuildItem.GetItemType(item));
            }

            return(MSBuildItem.GetMetadataValue(item, attributeName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the nested project information in the project file.
        /// </summary>
        /// <param name="newFileName"></param>
        public /*protected, but public for FSharp.Project.dll*/ virtual void SaveNestedProjectItemInProjectFile(string newFileName)
        {
            string existingInclude      = MSBuildItem.GetEvaluatedInclude(this.ItemNode.Item);
            string existingRelativePath = Path.GetDirectoryName(existingInclude);
            string newRelativePath      = Path.Combine(existingRelativePath, newFileName);

            this.ItemNode.Rename(newRelativePath);
        }
Exemplo n.º 3
0
 public int get_CanonicalName(out string pbstrCanonicalName)
 {
     pbstrCanonicalName = MSBuildItem.GetEvaluatedInclude(output);
     // Make sure we have a full path
     if (!System.IO.Path.IsPathRooted(pbstrCanonicalName))
     {
         pbstrCanonicalName = new Url(project.BaseURI, pbstrCanonicalName).AbsoluteUrl;
     }
     return(VSConstants.S_OK);
 }
Exemplo n.º 4
0
        private void BindFromBuildResult(Build.Evaluation.ProjectItem element, BuildResult buildResult)
        {
            var include = MSBuildItem.GetEvaluatedInclude(element);

            fsprojIncludeHasFilename = (include.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
                                        include.EndsWith(".exe", StringComparison.OrdinalIgnoreCase));

            ResolveFromBuiltProject(include, buildResult);
            if (!fsprojIncludeHasFilename)
            {
                InitializeAssemblyName(include);
            }
            InitializeFileChangeEvents();
        }
Exemplo n.º 5
0
        /// <summary>
        /// This path must start with file:/// if it wants other project
        /// to be able to reference the output on disk.
        /// If the output is not on disk, then this requirement does not
        /// apply as other projects probably don't know how to access it.
        /// </summary>
        public virtual int get_DeploySourceURL(out string pbstrDeploySourceURL)
        {
            string path = MSBuildItem.GetEvaluatedInclude(output);

            if (string.IsNullOrEmpty(path))
            {
                throw new InvalidOperationException();
            }
            if (path.Length < 9 || String.Compare(path.Substring(0, 8), "file:///", StringComparison.OrdinalIgnoreCase) != 0)
            {
                path = "file:///" + path;  // Does not work with '#' char.
            }
            pbstrDeploySourceURL = path;
            return(VSConstants.S_OK);
        }
Exemplo n.º 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.BuildProject.CreateProjectInstance();

            AssemblyReferenceNode.BuildInstance(this.ProjectMgr, ref instance, MsBuildTarget.ResolveAssemblyReferences);
            var comReferences = instance.GetItems(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;
                }
            }
        }
        private void ResolveFromBuiltProject(string assemblyInclude, BuildResult buildResult)
        {
            Action <string> Trace = (s) => FSharpTrace.PrintLine("ProjectSystemReferenceResolution", () => "ResolveAssemblyReferenceCore: " + s);

            Trace("starting: \"" + assemblyInclude + "\"");
            if (!buildResult.IsSuccessful)
            {
                Trace("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);
                        }
                        Trace("finished and found original item: \"" + assemblyInclude + "\"");
                        return;
                    }
                }
            }
            Trace("finished without finding original item: \"" + assemblyInclude + "\"");
        }
Exemplo n.º 8
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);
 }