Exemplo n.º 1
0
        /// <summary>
        /// Helper for metadata escaping tests
        /// </summary>
        private void SpecialCharactersInMetadataValueTests(Microsoft.Build.Evaluation.ProjectItem item)
        {
            Assert.AreEqual("%3B", item.GetMetadata("EscapedSemicolon").UnevaluatedValue);
            Assert.AreEqual(";", item.GetMetadata("EscapedSemicolon").EvaluatedValue);
            Assert.AreEqual(";", item.GetMetadataValue("EscapedSemicolon"));

            Assert.AreEqual("%24", item.GetMetadata("EscapedDollarSign").UnevaluatedValue);
            Assert.AreEqual("$", item.GetMetadata("EscapedDollarSign").EvaluatedValue);
            Assert.AreEqual("$", item.GetMetadataValue("EscapedDollarSign"));
        }
Exemplo n.º 2
0
 private static bool? GetPublishSetting(Microsoft.Build.Execution.ProjectItemInstance item)
 {
     bool? publish = null;
     string pubValue = item.GetMetadataValue("Publish");
     bool pubSetting;
     if (!String.IsNullOrWhiteSpace(pubValue) && Boolean.TryParse(pubValue, out pubSetting)) {
         publish = pubSetting;
     }
     return publish;
 }
Exemplo n.º 3
0
 string GetAssemblyFileNameFromHintPath(Microsoft.Build.Evaluation.Project p, Microsoft.Build.Evaluation.ProjectItem item)
 {
     string assemblyFileName = null;
     if (item.HasMetadata("HintPath"))
     {
         assemblyFileName = _fileSystem.Path.Combine(p.DirectoryPath, item.GetMetadataValue("HintPath")).ForceNativePathSeparator();
         _logger.Info("Looking for assembly from HintPath at " + assemblyFileName);
         if (!_fileSystem.File.Exists(assemblyFileName))
         {
             _logger.Info("Did not find assembly from HintPath");
             assemblyFileName = null;
         }
     }
     return assemblyFileName;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get the parent node of an msbuild item
        /// </summary>
        /// <param name="item">msbuild item</param>
        /// <returns>parent node</returns>
        private HierarchyNode GetItemParentNode(Microsoft.Build.Evaluation.ProjectItem item)
        {
            HierarchyNode currentParent = this;
            string strPath = item.EvaluatedInclude;
            string link = item.GetMetadataValue(ProjectFileConstants.Link);
            if (!String.IsNullOrEmpty(link))
            {
                strPath = link;
            }

            strPath = Path.GetDirectoryName(strPath);
            if (strPath.Length > 0)
            {
                // Use the relative to verify the folders...
                currentParent = this.CreateFolderNodes(strPath);
            }
            return currentParent;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add an item to the hierarchy based on the item path
        /// </summary>
        /// <param name="item">Item to add</param>
        /// <returns>Added node</returns>
        private HierarchyNode AddIndependentFileNode(Microsoft.Build.Evaluation.ProjectItem item)
        {
            bool shouldLink = false;
            // Remove any redundant "." directories from the Include path.
            string includePath = item.Xml.Include.Replace("/./", "/").Replace("\\.\\", "\\");
            while (includePath.StartsWith("./", StringComparison.Ordinal) || includePath.StartsWith(".\\", StringComparison.Ordinal))
            {
                includePath = includePath.Substring(2);
            }

            // Don't set the property unless necessary to avoid dirtying the project.
            if (includePath != item.Xml.Include)
            {
                item.Xml.Include = includePath;
            }

            // Make sure the item is within the project folder hierarchy. If not, link it.
            string linkPath = item.GetMetadataValue(ProjectFileConstants.Link);
            if (String.IsNullOrEmpty(linkPath))
            {
                string projectFolder = new Uri(this.ProjectFolder).LocalPath;
                string itemPath = new Uri(Path.Combine(this.ProjectFolder, item.Xml.Include)).LocalPath;
                if (!itemPath.StartsWith(projectFolder, StringComparison.OrdinalIgnoreCase))
                {
                    shouldLink = true;
                }
            }

            HierarchyNode currentParent;
            // If the file is outside of the project dir, link to it and place
            // it under the project node. Do not attempt to create a '..'
            // folder node.
            if (shouldLink)
            {
                currentParent = this;
            }
            else
            {
                currentParent = GetItemParentNode(item);
            }

            HierarchyNode newNode = AddFileNodeToNode(item, currentParent);

            if (shouldLink)
            {
                linkPath = Path.GetFileName(item.Xml.Include);
                newNode.ItemNode.SetMetadata(ProjectFileConstants.Link, linkPath);
            }

            return newNode;
        }
Exemplo n.º 6
0
 public static string GetMetadataValue(Microsoft.Build.Execution.ProjectItemInstance item, string name)
 {
     return item.GetMetadataValue(name);
 }
Exemplo n.º 7
0
 public static string GetMetadataValue(Microsoft.Build.Evaluation.ProjectItem item, string name)
 {
     return item.GetMetadataValue(name);
 }