예제 #1
0
        private void ReadItems(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            if (_listItems == null || _listItems.Count != 0)
            {
                _listItems = new BuildList <ReferenceVsNetItem>();
            }

            string startElement = reader.Name;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, ReferenceVsNetItem.TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        ReferenceVsNetItem item = new ReferenceVsNetItem();
                        item.ReadXml(reader);

                        this.Add(item);
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, startElement,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// This creates the reference content from the available VS.NET items.
        /// </summary>
        /// <param name="groupContext">
        /// The context of the group which owns this source.
        /// </param>
        /// <returns>
        /// An instance of the <see cref="ReferenceContent"/> if successful;
        /// otherwise, this is <see langword="null"/>.
        /// </returns>
        private ReferenceContent OnCreateContent(BuildGroupContext groupContext)
        {
            Dictionary <string, ProjectSection> projects = new Dictionary <string, ProjectSection>(
                StringComparer.OrdinalIgnoreCase);

            BuildContext context       = groupContext.Context;
            string       platform      = context.TargetPlatform;
            string       configuration = context.TargetConfiguration;

            BuildLogger logger = context.Logger;

            // For each item, create the project sections...
            for (int i = 0; i < _listItems.Count; i++)
            {
                ReferenceVsNetItem vsNetItem = _listItems[i];

                if (vsNetItem != null && !vsNetItem.IsEmpty)
                {
                    HashSet <string> includeSet = new HashSet <string>(
                        vsNetItem.Includes);

                    IList <ProjectSection> sections =
                        ProjectSectionFactory.CreateSections(
                            vsNetItem.SourcePath.Path, platform, configuration,
                            includeSet);

                    if (sections != null && sections.Count != 0)
                    {
                        string useXamlSyntax = vsNetItem.XamlSyntax.ToString();

                        for (int j = 0; j < sections.Count; j++)
                        {
                            ProjectSection section = sections[j];
                            if (!String.IsNullOrEmpty(section.TargetFrameworkVersion) ||
                                !String.IsNullOrEmpty(section.TargetFrameworkIdentifier))
                            {
                                // Since the mapping from the VS.NET items
                                // to the project section is lost after this,
                                // we save this information...
                                section["UseXamlSyntax"] = useXamlSyntax;

                                projects[section.ProjectGuid] = section;
                            }
                        }
                    }
                }
            }

            // This is not expected, no managed project is found...
            if (projects.Count == 0)
            {
                if (logger != null)
                {
                    logger.WriteLine(String.Format(
                                         "The '{0}' reference content source does not contain any valid project.",
                                         this.Title), BuildLoggerLevel.Warn);
                }

                return(null);
            }

            IList <ProjectSection> projectSetions = new List <ProjectSection>(
                projects.Values);

            if (String.IsNullOrEmpty(_targetIdentifier))
            {
                // We are not filtering a particular target framework...
                if (projectSetions.Count > 1)
                {
                    BuildMultiMap <string, ProjectSection> multiSections =
                        new BuildMultiMap <string, ProjectSection>(
                            StringComparer.OrdinalIgnoreCase);

                    for (int i = 0; i < projectSetions.Count; i++)
                    {
                        ProjectSection section          = projectSetions[i];
                        string         targetIdentifier = section.TargetFrameworkIdentifier;
                        if (!String.IsNullOrEmpty(targetIdentifier))
                        {
                            multiSections.Add(targetIdentifier, section);
                        }
                    }

                    List <string> targetIdentifiers = new List <string>(multiSections.Keys);
                    if (targetIdentifiers.Count > 1)
                    {
                        // Error, there are more one target framework identifier.
                        if (logger != null)
                        {
                            StringBuilder builder = new StringBuilder();
                            for (int i = 0; i < targetIdentifiers.Count; i++)
                            {
                                builder.Append(targetIdentifiers[i]);
                                if (i < (targetIdentifiers.Count - 1))
                                {
                                    builder.Append(";");
                                }
                            }

                            logger.WriteLine(String.Format(
                                                 "The project items of '{0}' contain more than one target framework identifier '{1}'.",
                                                 this.Title, builder.ToString()), BuildLoggerLevel.Error);
                        }

                        return(null);
                    }
                }
            }
            else
            {
                IList <ProjectSection> filteredSetions = new List <ProjectSection>(projectSetions.Count);
                for (int i = 0; i < projectSetions.Count; i++)
                {
                    ProjectSection section = projectSetions[i];
                    if (String.Equals(section.TargetFrameworkIdentifier,
                                      _targetIdentifier, StringComparison.OrdinalIgnoreCase))
                    {
                        filteredSetions.Add(section);
                    }
                }

                // We will use the filtered sections
                projectSetions = filteredSetions;
            }

            // This is not expected, no managed project is found...
            if (projectSetions == null || projectSetions.Count == 0)
            {
                if (logger != null)
                {
                    logger.WriteLine(String.Format(
                                         "The '{0}' reference content source does not contain any valid project.",
                                         this.Title), BuildLoggerLevel.Warn);
                }

                return(null);
            }

            ReferenceContent content = new ReferenceContent();

            HashSet <string> dependencyDirs = new HashSet <string>(
                StringComparer.OrdinalIgnoreCase);
            HashSet <string> referencedAssemblies = new HashSet <string>(
                StringComparer.OrdinalIgnoreCase);

            Version frameworkVersion = new Version(1, 0, 0, 0);

            for (int i = 0; i < projectSetions.Count; i++)
            {
                ProjectSection section = projectSetions[i];

                string commentFile = section.CommentFile;
                if (String.IsNullOrEmpty(commentFile) || !File.Exists(commentFile))
                {
                    throw new BuildException(String.Format(
                                                 "The project '{0}' has no comment file.",
                                                 section.ProjectName));
                }
                string assemblyFile = section.OutputFile;
                if (String.IsNullOrEmpty(assemblyFile) || !File.Exists(assemblyFile))
                {
                    throw new BuildException(String.Format(
                                                 "The project '{0}' has no assembly file.",
                                                 section.ProjectName));
                }

                ReferenceItem refItem = new ReferenceItem(commentFile,
                                                          assemblyFile);

                string tempText = section["UseXamlSyntax"];
                if (!String.IsNullOrEmpty(tempText))
                {
                    refItem.XamlSyntax = Convert.ToBoolean(tempText);
                }

                // This should normally be in the format: v2.0, v3.0 etc
                string versionText = section.TargetFrameworkVersion;
                if (versionText != null && versionText.StartsWith("v",
                                                                  StringComparison.OrdinalIgnoreCase))
                {
                    versionText = versionText.Substring(1);
                }
                if (!String.IsNullOrEmpty(versionText))
                {
                    Version version = new Version(versionText);
                    if (version > frameworkVersion)
                    {
                        frameworkVersion = version;
                    }
                }

                content.Add(refItem);

                // Recursively extract the dependent assemblies information...
                CreateDependencies(section, dependencyDirs,
                                   referencedAssemblies);
            }

            // Provide the framework information of the content...
            BuildFrameworkKind frameworkKind   = BuildFrameworkKind.None;
            string             targetIdentifer = projectSetions[0].TargetFrameworkIdentifier;

            if (String.IsNullOrEmpty(targetIdentifer))
            {
                if (logger != null)
                {
                    logger.WriteLine("The target framework identifier is not found. Standard .NET Framework is assumed.",
                                     BuildLoggerLevel.Warn);
                }

                frameworkKind = BuildFrameworkKind.DotNet;
            }
            else
            {
                switch (targetIdentifer.ToLower())
                {
                case ".netframework":
                    frameworkKind = BuildFrameworkKind.DotNet;
                    break;

                case "silverlight":
                    frameworkKind = BuildFrameworkKind.Silverlight;
                    break;

                case ".netportable":
                    frameworkKind = BuildFrameworkKind.Portable;
                    break;

                case "scriptsharp":
                    // For the Script#, the version starts from 1.0 and
                    // does not match the .NET Framework version
                    frameworkVersion = BuildFrameworks.LatestScriptSharpVersion;
                    frameworkKind    = BuildFrameworkKind.ScriptSharp;
                    break;

                case "compact":
                    frameworkKind = BuildFrameworkKind.Compact;
                    break;

                default:
                    frameworkKind = BuildFrameworkKind.DotNet;
                    break;
                }
            }

            // Get the best framework for this content...
            BuildFramework framework = BuildFrameworks.GetFramework(
                frameworkVersion.Major, frameworkVersion.Minor, frameworkKind);

            if (framework == null)
            {
                if (logger != null)
                {
                    logger.WriteLine(String.Format(
                                         "The expected version '{0}' for '{1}', cannot be found.",
                                         frameworkVersion, this.Title), BuildLoggerLevel.Warn);
                }

                framework = BuildFrameworks.LatestFramework;

                if (framework == null)
                {
                    // If not successful, use the default...
                    framework = BuildFrameworks.DefaultFramework;
                }
            }

            content.FrameworkType = framework.FrameworkType;

            // Provide the dependency information for the content...
            DependencyContent          depContents = content.Dependencies;
            IList <BuildDirectoryPath> depPaths    = depContents.Paths;

            foreach (string dependencyDir in dependencyDirs)
            {
                if (String.IsNullOrEmpty(dependencyDir) ||
                    !Directory.Exists(dependencyDir))
                {
                    continue;
                }

                depPaths.Add(new BuildDirectoryPath(dependencyDir));
            }
            foreach (string referencedAssembly in referencedAssemblies)
            {
                depContents.AddItem(referencedAssembly);
            }

            // Provide other user-supplied information to the content...
            content.Comments         = this.Comments;
            content.HierarchicalToc  = this.HierarchicalToc;
            content.TypeFilters      = this.TypeFilters;
            content.AttributeFilters = this.AttributeFilters;

            return(content);
        }
예제 #3
0
        /// <summary>
        /// Removes the specified item from the list of items.
        /// </summary>
        /// <param name="item">The item to be removed from the list.</param>
        /// <returns>
        /// This returns <see langword="true"/> if the item is included in the
        /// list and is successfully removed; otherwise, this returns <see langword="false"/>.
        /// </returns>
        /// <exception cref="item">
        /// If the <paramref name="ArgumentNullException"/> is <see langword="null"/>.
        /// </exception>
        public bool Remove(ReferenceVsNetItem item)
        {
            BuildExceptions.NotNull(item, "item");

            return(_listItems.Remove(item));
        }
예제 #4
0
        /// <summary>
        /// Searches for the specified item and returns the zero-based index
        /// of the first occurrence within the list.
        /// </summary>
        /// <param name="item">The item to locate.</param>
        /// <returns>
        /// This returns the zero-based index of the first occurrence of the
        /// <paramref name="item"/> within the list if found; otherwise, it
        /// returns <c>-1</c>.
        /// </returns>
        /// <exception cref="item">
        /// If the <paramref name="ArgumentNullException"/> is <see langword="null"/>.
        /// </exception>
        public int IndexOf(ReferenceVsNetItem item)
        {
            BuildExceptions.NotNull(item, "item");

            return(_listItems.IndexOf(item));
        }
예제 #5
0
        /// <summary>
        /// Determines whether the specified item is in the list of items.
        /// </summary>
        /// <param name="item">The item to locate in the list.</param>
        /// <returns>
        /// This returns <see langword="true"/> if the specified item is
        /// found in the list; otherwise, it is <see langword="false"/>.
        /// </returns>
        /// <exception cref="item">
        /// If the <paramref name="ArgumentNullException"/> is <see langword="null"/>.
        /// </exception>
        public bool Contains(ReferenceVsNetItem item)
        {
            BuildExceptions.NotNull(item, "item");

            return(_listItems.Contains(item));
        }
예제 #6
0
        /// <summary>
        /// Inserts the given item at the specified index.
        /// </summary>
        /// <param name="index">
        /// The zero-based index at which the <paramref name="item"/> should
        /// be inserted.
        /// </param>
        /// <param name="item">The item to insert.</param>
        /// <exception cref="item">
        /// If the <paramref name="ArgumentNullException"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If the <paramref name="index"/> is less than <c>0</c>.
        /// <para>-or-</para>
        /// The <paramref name="index"/> is greater than the <see cref="ReferenceVsNetSource.Count"/>
        /// </exception>
        public void Insert(int index, ReferenceVsNetItem item)
        {
            BuildExceptions.NotNull(item, "item");

            _listItems.Add(item);
        }
예제 #7
0
        /// <summary>
        /// Adds an item to the end of the list.
        /// </summary>
        /// <param name="item">The item to be added to the list.</param>
        /// <exception cref="item">
        /// If the <paramref name="ArgumentNullException"/> is <see langword="null"/>.
        /// </exception>
        public void Add(ReferenceVsNetItem item)
        {
            BuildExceptions.NotNull(item, "item");

            _listItems.Add(item);
        }