예제 #1
0
 /// <summary>
 /// Helper function to parse the ParameterEntryElement
 /// </summary>
 /// <param name="element"></param>
 /// <param name="parentItem"></param>
 /// <returns></returns>
 private Utilities.TaskItem ReadParameterEntryElement(Xml.XmlElement element, Utilities.TaskItem parentItem)
 {
     Debug.Assert(element != null && parentItem != null);
     Utilities.TaskItem taskItem = null;
     if (string.Compare(element.Name, "parameterEntry", System.StringComparison.OrdinalIgnoreCase) == 0)
     {
         taskItem = new Microsoft.Build.Utilities.TaskItem(parentItem);
         taskItem.RemoveMetadata("OriginalItemSpec");
         foreach (Xml.XmlNode attribute in element.Attributes)
         {
             if (attribute != null && attribute.Name != null && attribute.Value != null)
             {
                 string value = DisableEscapeMSBuildVariable ? attribute.Value : Utility.EscapeTextForMSBuildVariable(attribute.Value);
                 taskItem.SetMetadata(attribute.Name, value);
             }
         }
     }
     else if (string.Compare(element.Name, "parameterValidation", System.StringComparison.OrdinalIgnoreCase) == 0)
     {
         taskItem = new Microsoft.Build.Utilities.TaskItem(parentItem);
         taskItem.RemoveMetadata("OriginalItemSpec");
         taskItem.SetMetadata("Element", "parameterValidation");
         foreach (Xml.XmlNode attribute in element.Attributes)
         {
             if (attribute != null && attribute.Name != null && attribute.Value != null)
             {
                 string value = DisableEscapeMSBuildVariable ? attribute.Value : Utility.EscapeTextForMSBuildVariable(attribute.Value);
                 taskItem.SetMetadata(attribute.Name, value);
             }
         }
     }
     return(taskItem);
 }
예제 #2
0
        /// <summary>
        /// Set metadata on the items which will be output from RAR.
        /// </summary>
        private ITaskItem SetItemMetadata(ArrayList relatedItems, ArrayList satelliteItems, ArrayList serializationAssemblyItems, ArrayList scatterItems, string fusionName, Reference reference, AssemblyNameExtension assemblyName, FileExists fileExists)
        {
            // Set up the main item.
            ITaskItem referenceItem = new TaskItem();
            referenceItem.ItemSpec = reference.FullPath;
            referenceItem.SetMetadata(ItemMetadataNames.resolvedFrom, reference.ResolvedSearchPath);

            // Set the CopyLocal metadata.
            if (reference.IsCopyLocal)
            {
                referenceItem.SetMetadata(ItemMetadataNames.copyLocal, "true");
            }
            else
            {
                referenceItem.SetMetadata(ItemMetadataNames.copyLocal, "false");
            }

            // Set the FusionName metadata.
            referenceItem.SetMetadata(ItemMetadataNames.fusionName, fusionName);

            // Set the Redist name metadata.
            if (!String.IsNullOrEmpty(reference.RedistName))
            {
                referenceItem.SetMetadata(ItemMetadataNames.redist, reference.RedistName);
            }

            if (Reference.IsFrameworkFile(reference.FullPath, _frameworkPaths) || (_installedAssemblies != null && _installedAssemblies.FrameworkAssemblyEntryInRedist(assemblyName)))
            {
                if (!IsAssemblyRemovedFromDotNetFramework(assemblyName, reference.FullPath, _frameworkPaths, _installedAssemblies))
                {
                    referenceItem.SetMetadata(ItemMetadataNames.frameworkFile, "true");
                }
            }

            if (!String.IsNullOrEmpty(reference.ImageRuntime))
            {
                referenceItem.SetMetadata(ItemMetadataNames.imageRuntime, reference.ImageRuntime);
            }

            if (reference.IsWinMDFile)
            {
                referenceItem.SetMetadata(ItemMetadataNames.winMDFile, "true");

                // The ImplementationAssembly is only set if the implementation file exits on disk
                if (reference.ImplementationAssembly != null)
                {
                    if (VerifyArchitectureOfImplementationDll(reference.ImplementationAssembly, reference.FullPath))
                    {
                        referenceItem.SetMetadata(ItemMetadataNames.winmdImplmentationFile, Path.GetFileName(reference.ImplementationAssembly));

                        // Add the implementation item as a related file
                        ITaskItem item = new TaskItem(reference.ImplementationAssembly);
                        // Clone metadata.
                        referenceItem.CopyMetadataTo(item);
                        // Related files don't have a fusion name.
                        item.SetMetadata(ItemMetadataNames.fusionName, "");
                        RemoveNonForwardableMetadata(item);

                        // Add the related item.
                        relatedItems.Add(item);
                    }
                }

                if (reference.IsManagedWinMDFile)
                {
                    referenceItem.SetMetadata(ItemMetadataNames.winMDFileType, "Managed");
                }
                else
                {
                    referenceItem.SetMetadata(ItemMetadataNames.winMDFileType, "Native");
                }
            }

            // Set the IsRedistRoot metadata
            if (reference.IsRedistRoot == true)
            {
                referenceItem.SetMetadata(ItemMetadataNames.isRedistRoot, "true");
            }
            else if (reference.IsRedistRoot == false)
            {
                referenceItem.SetMetadata(ItemMetadataNames.isRedistRoot, "false");
            }
            else
            {
                // This happens when the redist root is "null". This means there
                // was no IsRedistRoot flag in the Redist XML (or there was no 
                // redist XML at all for this item).
            }

            // If there was a primary source item, then forward metadata from it.
            // It's important that the metadata from the primary source item
            // win over the same metadata from other source items, so that's
            // why we put this first.  (CopyMetadataTo will never override an 
            // already existing metadata.)  For example, if this reference actually
            // came directly from an item declared in the project file, we'd
            // want to use the metadata from it, not some other random item in
            // the project file that happened to have this reference as a dependency.
            if (reference.PrimarySourceItem != null)
            {
                reference.PrimarySourceItem.CopyMetadataTo(referenceItem);
            }
            else
            {
                bool hasImplementationFile = referenceItem.GetMetadata(ItemMetadataNames.winmdImplmentationFile).Length > 0;
                bool hasImageRuntime = referenceItem.GetMetadata(ItemMetadataNames.imageRuntime).Length > 0;
                bool hasWinMDFile = referenceItem.GetMetadata(ItemMetadataNames.winMDFile).Length > 0;

                // If there were non-primary source items, then forward metadata from them.
                ICollection sourceItems = reference.GetSourceItems();
                foreach (ITaskItem sourceItem in sourceItems)
                {
                    sourceItem.CopyMetadataTo(referenceItem);
                }

                // If the item originally did not have the implementation file metadata then we do not want to get it from the set of primary source items
                // since the implementation file is something specific to the source item and not supposed to be propigated.
                if (!hasImplementationFile)
                {
                    referenceItem.RemoveMetadata(ItemMetadataNames.winmdImplmentationFile);
                }

                // If the item originally did not have the ImageRuntime metadata then we do not want to get it from the set of primary source items
                // since the ImageRuntime is something specific to the source item and not supposed to be propigated.
                if (!hasImageRuntime)
                {
                    referenceItem.RemoveMetadata(ItemMetadataNames.imageRuntime);
                }

                // If the item originally did not have the WinMDFile metadata then we do not want to get it from the set of primary source items
                // since the WinMDFile is something specific to the source item and not supposed to be propigated
                if (!hasWinMDFile)
                {
                    referenceItem.RemoveMetadata(ItemMetadataNames.winMDFile);
                }
            }

            if (reference.ReferenceVersion != null)
            {
                referenceItem.SetMetadata(ItemMetadataNames.version, reference.ReferenceVersion.ToString());
            }
            else
            {
                referenceItem.SetMetadata(ItemMetadataNames.version, String.Empty);
            }

            // Now clone all properties onto the related files.
            foreach (string relatedFileExtension in reference.GetRelatedFileExtensions())
            {
                ITaskItem item = new TaskItem(reference.FullPathWithoutExtension + relatedFileExtension);
                // Clone metadata.
                referenceItem.CopyMetadataTo(item);
                // Related files don't have a fusion name.
                item.SetMetadata(ItemMetadataNames.fusionName, "");
                RemoveNonForwardableMetadata(item);

                // Add the related item.
                relatedItems.Add(item);
            }

            // Set up the satellites.
            foreach (string satelliteFile in reference.GetSatelliteFiles())
            {
                ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, satelliteFile));
                // Clone metadata.
                referenceItem.CopyMetadataTo(item);
                // Set the destination directory.
                item.SetMetadata(ItemMetadataNames.destinationSubDirectory, FileUtilities.EnsureTrailingSlash(Path.GetDirectoryName(satelliteFile)));
                // Satellite files don't have a fusion name.
                item.SetMetadata(ItemMetadataNames.fusionName, "");
                RemoveNonForwardableMetadata(item);

                // Add the satellite item.
                satelliteItems.Add(item);
            }

            // Set up the serialization assemblies
            foreach (string serializationAssemblyFile in reference.GetSerializationAssemblyFiles())
            {
                ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, serializationAssemblyFile));
                // Clone metadata.
                referenceItem.CopyMetadataTo(item);
                // serialization assemblies files don't have a fusion name.
                item.SetMetadata(ItemMetadataNames.fusionName, "");
                RemoveNonForwardableMetadata(item);

                // Add the serialization assembly item.
                serializationAssemblyItems.Add(item);
            }

            // Set up the scatter files.
            foreach (string scatterFile in reference.GetScatterFiles())
            {
                ITaskItem item = new TaskItem(Path.Combine(reference.DirectoryName, scatterFile));
                // Clone metadata.
                referenceItem.CopyMetadataTo(item);
                // We don't have a fusion name for scatter files.
                item.SetMetadata(ItemMetadataNames.fusionName, "");
                RemoveNonForwardableMetadata(item);

                // Add the satellite item.
                scatterItems.Add(item);
            }

            // As long as the item has not come from somewhere else say it came from rar (p2p's can come from somewhere else).
            if (referenceItem.GetMetadata(ItemMetadataNames.msbuildReferenceSourceTarget).Length == 0)
            {
                referenceItem.SetMetadata(ItemMetadataNames.msbuildReferenceSourceTarget, "ResolveAssemblyReference");
            }

            if (referenceItem.GetMetadata(ItemMetadataNames.msbuildReferenceSourceTarget).Equals("ProjectReference"))
            {
                if (reference.PrimarySourceItem != null)
                {
                    referenceItem.SetMetadata(ItemMetadataNames.projectReferenceOriginalItemSpec, reference.PrimarySourceItem.GetMetadata("OriginalItemSpec"));
                }
            }

            return referenceItem;
        }
예제 #3
0
        public void CannotRemoveModifiers()
        {
            TaskItem t = new TaskItem("foor");

            try
            {
                t.RemoveMetadata(FileUtilities.ItemSpecModifiers.RootDir);
            }
            catch (Exception e)
            {
                // so I can see the exception message in NUnit's "Standard Out" window
                Console.WriteLine(e.Message);
                throw;
            }
        }