Exemplo n.º 1
0
        /// <summary>
        /// This writes the current state or attributes of this object,
        /// in the <c>XML</c> format, to the media or storage accessible by the given writer.
        /// </summary>
        /// <param name="writer">
        /// The <c>XML</c> writer with which the <c>XML</c> format of this object's state
        /// is written.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void WriteXml(XmlWriter writer)
        {
            BuildExceptions.NotNull(writer, "writer");

            if (!this.IsValid)
            {
                return;
            }

            writer.WriteStartElement(TagName);  // start - TagName
            writer.WriteAttributeString("name", this.Name);

            writer.WriteStartElement("propertyGroup");  // start - propertyGroup
            writer.WriteAttributeString("name", "General");
            writer.WritePropertyElement("Title", this.Title);
            writer.WritePropertyElement("Id", _sourceId);
            writer.WritePropertyElement("LinkType", _linkType.ToString());
            writer.WritePropertyElement("FrameworkType", _frameworkType.ToString());
            writer.WriteEndElement();                   // end - propertyGroup

            // 3. The reference items defining the API content
            writer.WriteComment(" The reference items defining the API content ");
            writer.WriteStartElement("referenceItems");  // start - referenceItems
            for (int i = 0; i < _listItems.Count; i++)
            {
                ReferenceItem item = _listItems[i];
                if (item != null && !item.IsEmpty)
                {
                    item.WriteXml(writer);
                }
            }
            writer.WriteEndElement();                    // end - referenceItems

            // Write the user-defined contents...
            this.WriteContents(writer);

            // Write the filters...
            this.WriteFilters(writer);

            writer.WriteEndElement();           // end - TagName
        }
        private void ResolveDependency(ReferenceGroupContext sourceContext,
                                       ReferenceContent referenceContent)
        {
            BuildContext context = this.Context;
            BuildLogger  logger  = context.Logger;

            BuildFramework framework = sourceContext.Framework;

            if (framework == null)
            {
                throw new BuildException("No valid framework is specified.");
            }

            DependencyContent dependencies = referenceContent.Dependencies;

            _resolveContent = new DependencyContent();
            _listReference  = new List <ReferenceItem>();

            _dictionary = new Dictionary <string, bool>(
                StringComparer.OrdinalIgnoreCase);
            _dictDependency = new Dictionary <string, bool>(
                StringComparer.OrdinalIgnoreCase);
            _dictReference = new Dictionary <string, bool>(
                StringComparer.OrdinalIgnoreCase);

            if (dependencies != null && dependencies.Count != 0)
            {
                for (int i = 0; i < dependencies.Count; i++)
                {
                    DependencyItem depItem = dependencies[i];
                    if (!depItem.IsEmpty)
                    {
                        _dictDependency[depItem.Location] = true;
                    }
                }
            }

            // Index the reference items to prevent cross referencing...
            if (referenceContent != null && referenceContent.Count != 0)
            {
                for (int i = 0; i < referenceContent.Count; i++)
                {
                    ReferenceItem refItem = referenceContent[i];
                    if (!refItem.IsEmpty && !refItem.IsCommentOnly)
                    {
                        string refAssembly = refItem.Assembly;
                        if (!_dictReference.ContainsKey(refAssembly))
                        {
                            _dictReference[refAssembly] = true;
                            _listReference.Add(refItem);
                        }
                    }
                }
            }

            GeneralAssemblyResolver resolver = new GeneralAssemblyResolver();

            // Add the reference item directories, the most likely place to
            // find the dependencies
            for (int i = 0; i < _listReference.Count; i++)
            {
                resolver.AddSearchDirectory(
                    Path.GetDirectoryName(_listReference[i].Assembly));
            }

            // Add specified dependency directories, if any...
            IList <BuildDirectoryPath> dependencyPaths = dependencies.Paths;

            if (dependencyPaths != null && dependencyPaths.Count != 0)
            {
                for (int i = 0; i < dependencyPaths.Count; i++)
                {
                    BuildDirectoryPath dependencyPath = dependencyPaths[i];
                    if (dependencyPath.Exists)
                    {
                        resolver.AddSearchDirectory(dependencyPath);
                    }
                }
            }

            Version version = framework.Version;

            // Add, for the Silverlight, known installation directories...
            BuildFrameworkKind frameworkKind = framework.FrameworkType.Kind;

            if (frameworkKind == BuildFrameworkKind.Silverlight)
            {
                resolver.UseGac = false;

                string programFiles = PathUtils.ProgramFiles32;
                string searchDir    = Path.Combine(programFiles,
                                                   @"Microsoft Silverlight\" + version.ToString());
                if (Directory.Exists(searchDir))
                {
                    resolver.AddSearchDirectory(searchDir);
                }

                searchDir = Path.Combine(programFiles,
                                         @"Reference Assemblies\Microsoft\Framework\Silverlight\v" + version.ToString(2));
                if (Directory.Exists(searchDir))
                {
                    resolver.AddSearchDirectory(searchDir);
                }
                else
                {
                    if (version.Major == 5 && version.Minor > 0)
                    {
                        // For Silverlight 5.1, the assemblies are in different places...
                        searchDir = Path.Combine(programFiles,
                                                 @"Reference Assemblies\Microsoft\Framework\Silverlight\v5.0");
                        if (Directory.Exists(searchDir))
                        {
                            resolver.AddSearchDirectory(searchDir);
                        }
                    }
                }

                searchDir = Path.Combine(programFiles,
                                         @"Microsoft SDKs\Silverlight\v" + version.ToString(2));
                if (!Directory.Exists(searchDir))
                {
                    if (version.Major == 5 && version.Minor > 0)
                    {
                        // For Silverlight 5.1, the assemblies are in different places...
                        searchDir = Path.Combine(programFiles,
                                                 @"Microsoft SDKs\Silverlight\v5.0");
                    }
                }

                if (Directory.Exists(searchDir))
                {
                    resolver.AddSearchDirectory(searchDir);

                    string tempDir = String.Copy(searchDir);
                    searchDir = Path.Combine(tempDir, @"Libraries\Client");
                    if (Directory.Exists(searchDir))
                    {
                        resolver.AddSearchDirectory(searchDir);
                    }
                    searchDir = Path.Combine(tempDir, @"Libraries\Server");
                    if (Directory.Exists(searchDir))
                    {
                        resolver.AddSearchDirectory(searchDir);
                    }
                }

                if (version.Major == 3)
                {
                    // 3. The Expression 3.0 Blend SDK...
                    string otherDir = Path.Combine(programFiles,
                                                   @"Microsoft SDKs\Expression\Blend 3\Interactivity\Libraries\Silverlight");
                    if (Directory.Exists(otherDir))
                    {
                        resolver.AddSearchDirectory(otherDir);
                    }
                    otherDir = Path.Combine(programFiles,
                                            @"Microsoft SDKs\Expression\Blend 3\Prototyping\Libraries\Silverlight");
                    if (Directory.Exists(otherDir))
                    {
                        resolver.AddSearchDirectory(otherDir);
                    }
                }
                else if (version.Major == 4)
                {
                    // Consider the extension libraries...
                    // 1. The RIA Services...
                    string otherDir = Path.Combine(programFiles,
                                                   @"Microsoft SDKs\RIA Services\v1.0\Libraries\Silverlight");
                    if (Directory.Exists(otherDir))
                    {
                        resolver.AddSearchDirectory(otherDir);
                    }
                    // 2. For the Silverlight Toolkit...
                    otherDir = Path.Combine(programFiles,
                                            @"Microsoft SDKs\Silverlight\v4.0\Toolkit");
                    if (Directory.Exists(otherDir))
                    {
                        // Get the latest installed version...
                        string[] dirs = Directory.GetDirectories(otherDir);
                        if (dirs != null && dirs.Length != 0)
                        {
                            string   dir      = String.Empty;
                            DateTime latestDt = DateTime.MinValue;
                            for (int j = 0; j < dirs.Length; j++)
                            {
                                string   latestDir = Path.GetFileName(dirs[j]);
                                DateTime dt;
                                if (DateTime.TryParse(latestDir, out dt))
                                {
                                    if (dt > latestDt)
                                    {
                                        latestDt = dt;
                                        dir      = latestDir;
                                    }
                                }
                            }

                            otherDir = Path.Combine(otherDir, dir + @"\Bin");
                            if (Directory.Exists(otherDir))
                            {
                                resolver.AddSearchDirectory(otherDir);
                            }
                        }
                    }

                    // 3. The Expression 4.0 Blend SDK...
                    otherDir = Path.Combine(programFiles,
                                            @"Microsoft SDKs\Expression\Blend\Silverlight\v4.0\Libraries");
                    if (Directory.Exists(otherDir))
                    {
                        resolver.AddSearchDirectory(otherDir);
                    }
                }
                else if (version.Major == 5)
                {
                    // Consider the extension libraries...
                    // 1. The RIA Services...
                    string otherDir = Path.Combine(programFiles,
                                                   @"Microsoft SDKs\RIA Services\v1.0\Libraries\Silverlight");
                    if (Directory.Exists(otherDir))
                    {
                        resolver.AddSearchDirectory(otherDir);
                    }
                    // 2. For the Silverlight Toolkit...
                    otherDir = Path.Combine(programFiles,
                                            @"Microsoft SDKs\Silverlight\v5.0\Toolkit");
                    if (Directory.Exists(otherDir))
                    {
                        // Get the latest installed version...
                        string[] dirs = Directory.GetDirectories(otherDir);
                        if (dirs != null && dirs.Length != 0)
                        {
                            string   dir      = String.Empty;
                            DateTime latestDt = DateTime.MinValue;
                            for (int j = 0; j < dirs.Length; j++)
                            {
                                string   latestDir = Path.GetFileName(dirs[j]);
                                DateTime dt;
                                if (DateTime.TryParse(latestDir, out dt))
                                {
                                    if (dt > latestDt)
                                    {
                                        latestDt = dt;
                                        dir      = latestDir;
                                    }
                                }
                            }

                            otherDir = Path.Combine(otherDir, dir + @"\Bin");
                            if (Directory.Exists(otherDir))
                            {
                                resolver.AddSearchDirectory(otherDir);
                            }
                        }
                    }

                    // 3. The Expression 5.0 Blend SDK...
                    otherDir = Path.Combine(programFiles,
                                            @"Microsoft SDKs\Expression\Blend\Silverlight\v5.0\Libraries");
                    if (Directory.Exists(otherDir))
                    {
                        resolver.AddSearchDirectory(otherDir);
                    }
                }
            }
            else if (frameworkKind == BuildFrameworkKind.Portable)
            {
                resolver.UseGac = false;
                resolver.AddSearchDirectory(framework.AssemblyDir);
            }
            else if (frameworkKind == BuildFrameworkKind.ScriptSharp)
            {
                resolver.UseGac = false;
                resolver.AddSearchDirectory(framework.AssemblyDir);
            }
            else if (frameworkKind == BuildFrameworkKind.Compact)
            {
                resolver.UseGac = false;
                resolver.AddSearchDirectory(framework.AssemblyDir);
            }
            else if (frameworkKind == BuildFrameworkKind.DotNet)
            {
                string programFiles = Environment.GetFolderPath(
                    Environment.SpecialFolder.ProgramFiles);
                if (version.Major == 3)
                {
                    // 3. The Expression 3.0 Blend SDK...
                    string otherDir = Path.Combine(programFiles,
                                                   @"Microsoft SDKs\Expression\Blend 3\Interactivity\Libraries\.NETFramework");
                    if (Directory.Exists(otherDir))
                    {
                        resolver.AddSearchDirectory(otherDir);
                    }
                }
                else if (version.Major == 4)
                {
                    string otherDir = Path.Combine(programFiles,
                                                   @"Microsoft SDKs\Expression\Blend\.NETFramework\v4.0\Libraries");
                    if (Directory.Exists(otherDir))
                    {
                        resolver.AddSearchDirectory(otherDir);
                    }
                }
            }
            else
            {
                throw new NotSupportedException(String.Format(
                                                    "The framework kind '{0}' is not supported.", frameworkKind.ToString()));
            }

            // Finally, we look inside the binding sources if we are dealing
            // with link sources...
            if (sourceContext.IsLinkGroup || sourceContext.IsEmbeddedGroup)
            {
                IList <string> bindingSources = sourceContext.BindingSources;
                if (bindingSources != null && bindingSources.Count != 0)
                {
                    foreach (string bindingSource in bindingSources)
                    {
                        if (!String.IsNullOrEmpty(bindingSource) &&
                            Directory.Exists(bindingSource))
                        {
                            resolver.AddSearchDirectory(bindingSource);
                        }
                    }
                }
            }

            for (int i = 0; i < _listReference.Count; i++)
            {
                ReferenceItem      refItem = _listReference[i];
                AssemblyDefinition asmDef  = AssemblyDefinition.ReadAssembly(
                    refItem.Assembly);

                ModuleDefinition modDef = asmDef.MainModule;

                // Try resolving all the dependencies...
                if (modDef.HasAssemblyReferences)
                {
                    IList <AssemblyNameReference> asmRefs = modDef.AssemblyReferences;

                    if (asmRefs != null && asmRefs.Count != 0)
                    {
                        for (int j = 0; j < asmRefs.Count; j++)
                        {
                            this.Resolve(logger, asmRefs[j], resolver,
                                         frameworkKind);
                        }
                    }
                }

                // Try resolving all the XmlnsDefinitionAttribute attributes...
                if (asmDef.HasCustomAttributes && refItem.XamlSyntax)
                {
                    this.ResolveXmlnsDefinitions(sourceContext, asmDef, modDef.Name);
                }
            }

            string[] searchDirs = resolver.GetSearchDirectories();
            if (searchDirs != null && searchDirs.Length != 0)
            {
                if (_searchDirectories == null)
                {
                    _searchDirectories = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                }

                for (int i = 0; i < searchDirs.Length; i++)
                {
                    string searchDir = Path.GetFullPath(String.Copy(searchDirs[i]));
                    if (!searchDir.EndsWith("\\"))
                    {
                        searchDir += "\\";
                    }

                    _searchDirectories.Add(searchDir);
                }
            }
        }
Exemplo n.º 3
0
        private void CreateLinkGroups(BuildContext context)
        {
            context["$EmbeddedScriptSharp"] = Boolean.FalseString;

            if (_listGroups == null || _listGroups.Count == 0)
            {
                return;
            }

            BuildLogger logger = context.Logger;

            List <ReferenceGroup>     buildGroups   = new List <ReferenceGroup>();
            IList <BuildGroupContext> groupContexts = context.GroupContexts;

            bool hasScriptSharp = false;
            BuildFrameworkType latestScriptSharp = BuildFrameworkType.None;

            int itemCount = _listGroups.Count;
            int index     = 0;

            for (int i = 0; i < itemCount; i++)
            {
                ReferenceGroup group = _listGroups[i];

                ReferenceContent content = group.Content;
                if (content != null)
                {
                    BuildFrameworkType frameworkType = content.FrameworkType;

                    if (frameworkType.Kind == BuildFrameworkKind.ScriptSharp)
                    {
                        hasScriptSharp = true;

                        if (frameworkType > latestScriptSharp)
                        {
                            latestScriptSharp = frameworkType;
                        }
                    }
                }
            }

            // Include contents from the Script# framework for correct
            // linking, since there is MSDN links for the Script#...
            if (hasScriptSharp && _engineSettings.EmbedScriptSharpFramework &&
                latestScriptSharp.Kind == BuildFrameworkKind.ScriptSharp)
            {
                BuildFramework framework = BuildFrameworks.GetFramework(latestScriptSharp);
                if (framework == null)
                {
                    framework = BuildFrameworks.LatestScriptSharp;
                }

                if (framework != null)
                {
                    ReferenceGroup buildGroup = new ReferenceGroup(
                        "Embedded ScriptSharp - " + ReferenceGroup.NextGroupName(),
                        Guid.NewGuid().ToString());

                    ReferenceContent content = buildGroup.Content;

                    string[] assemblies = Directory.GetFiles(framework.AssemblyDir,
                                                             "*.dll", SearchOption.AllDirectories);

                    for (int i = 0; i < assemblies.Length; i++)
                    {
                        string assembly = assemblies[i];
                        string comments = Path.ChangeExtension(assembly, ".xml");

                        if (File.Exists(comments))
                        {
                            content.AddItem(comments, assembly);
                        }
                    }

                    buildGroup.ExcludeToc = true;
                    buildGroup.SyntaxType = BuildSyntaxType.CSharp | BuildSyntaxType.JavaScript;

                    buildGroups.Add(buildGroup);

                    // Create the group context...
                    ReferenceGroupContext buildGroupContext =
                        new ReferenceGroupContext(buildGroup);
                    buildGroupContext.IsEmbeddedGroup = true;
                    groupContexts.Add(buildGroupContext);

                    string indexText = (itemCount + index + 1).ToString();

                    // Create the build dynamic properties...
                    buildGroupContext.CreateProperties(indexText);

                    // This has no effect, since the newly created group will
                    // not have any content source.
                    buildGroup.BeginSources(context);

                    context["$EmbeddedScriptSharp"] = Boolean.TrueString;
                }
            }

            if (buildGroups.Count != 0)
            {
                _listGroups.Add(buildGroups);
            }

            // Process the user-provided link sources...
            List <ReferenceLinkSource>  linkSources = null;
            IList <ReferenceLinkSource> listSources = _engineSettings.LinkSources as IList <ReferenceLinkSource>;

            if (listSources != null && listSources.Count != 0)
            {
                for (int i = 0; i < listSources.Count; i++)
                {
                    ReferenceLinkSource linkSource = listSources[i];

                    if (linkSource == null || !linkSource.IsValid)
                    {
                        if (logger != null)
                        {
                            string title = linkSource.Title;
                            if (title == null)
                            {
                                title = String.Empty;
                            }
                            logger.WriteLine(String.Format(
                                                 "A provided reference link source titled = '{0}', at index = '{1}' is invalid.",
                                                 title, i), BuildLoggerLevel.Warn);
                        }

                        continue;
                    }

                    if (linkSources == null)
                    {
                        linkSources = new List <ReferenceLinkSource>();
                    }

                    linkSources.Add(linkSource);
                }
            }

            // Process the automatic link sources...
            BuildSpecialSdkType webMvcSdkType = _engineSettings.WebMvcSdkType;

            if (webMvcSdkType != BuildSpecialSdkType.None &&
                webMvcSdkType != BuildSpecialSdkType.Null)
            {
                BuildSpecialSdk webSdk = BuildSpecialSdks.GetSdk(webMvcSdkType,
                                                                 BuildFrameworkKind.DotNet);

                if (webSdk != null)
                {
                    ReferenceLinkSource linkSource = new ReferenceLinkSource();
                    linkSource.LinkType      = BuildLinkType.Msdn;
                    linkSource.Title         = webMvcSdkType.Label;
                    linkSource.FrameworkType =
                        BuildFrameworks.LatestFramework.FrameworkType;

                    string aspMVCDir = webSdk.AssemblyDir;

                    string[] assemblyFiles = Directory.GetFiles(
                        webSdk.AssemblyDir, "*.dll", SearchOption.TopDirectoryOnly);

                    for (int i = 0; i < assemblyFiles.Length; i++)
                    {
                        string assemblyFile = assemblyFiles[i];
                        string commentFile  = Path.ChangeExtension(assemblyFile,
                                                                   ".xml");
                        if (File.Exists(commentFile))
                        {
                            ReferenceItem refItem = new ReferenceItem(
                                commentFile, assemblyFile);
                            refItem.XamlSyntax = false;
                            linkSource.Add(refItem);
                        }
                    }

                    if (linkSource.IsValid)
                    {
                        if (linkSources == null)
                        {
                            linkSources = new List <ReferenceLinkSource>();
                        }

                        linkSources.Add(linkSource);
                    }
                }
            }

            if (linkSources != null && linkSources.Count != 0)
            {
                context.SetValue("$ReferenceLinkSources", linkSources);

                itemCount = linkSources.Count;
                if (_linkGroups == null)
                {
                    _linkGroups = new BuildList <ReferenceGroup>();
                }

                for (int i = 0; i < itemCount; i++)
                {
                    ReferenceLinkSource linkSource = linkSources[i];

                    ReferenceGroup linkGroup = new ReferenceGroup(
                        "Reference Links - " + ReferenceGroup.NextGroupName(),
                        linkSource.SourceId, linkSource);

                    linkGroup.ExcludeToc = true;

                    _linkGroups.Add(linkGroup);

                    // Create the group context...
                    ReferenceGroupContext linkGroupContext =
                        new ReferenceGroupContext(linkGroup);
                    linkGroupContext.IsLinkGroup = true;
                    groupContexts.Add(linkGroupContext);

                    string indexText = String.Empty;
                    if (itemCount > 1)
                    {
                        indexText = (i + 1).ToString();
                    }

                    // Create the build dynamic properties...
                    linkGroupContext.CreateProperties(indexText);

                    // This has no effect, since the newly created group will
                    // not have any content source.
                    linkGroup.BeginSources(context);
                }
            }
        }
Exemplo n.º 4
0
        public void Insert(int index, ReferenceItem item)
        {
            BuildExceptions.NotNull(item, "item");

            _listItems.Insert(index, item);
        }
Exemplo n.º 5
0
        public void Add(ReferenceItem item)
        {
            BuildExceptions.NotNull(item, "item");

            _listItems.Add(item);
        }
Exemplo n.º 6
0
        public override ReferenceContent Create(BuildGroupContext groupContext)
        {
            BuildExceptions.NotNull(groupContext, "groupContext");

            BuildContext context = groupContext.Context;
            BuildLogger  logger  = null;

            if (context != null)
            {
                logger = context.Logger;
            }

            if (!this.IsInitialized)
            {
                throw new BuildException(String.Format(
                                             "The content source '{0}' is not yet initialized.", this.Title));
            }
            if (!this.IsValid)
            {
                if (logger != null)
                {
                    logger.WriteLine(String.Format(
                                         "The content group source '{0}' is invalid.", this.Title),
                                     BuildLoggerLevel.Warn);
                }

                return(null);
            }

            ReferenceContent content = new ReferenceContent();

            // Set the framework version...
            if (_frameworkType == BuildFrameworkType.Null ||
                _frameworkType == BuildFrameworkType.None)
            {
                BuildFramework framework = BuildFrameworks.LatestFramework;

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

                content.FrameworkType = framework.FrameworkType;
            }
            else
            {
                content.FrameworkType = _frameworkType;
            }

            for (int i = 0; i < _listItems.Count; i++)
            {
                ReferenceItem item = _listItems[i];
                if (item != null && !item.IsEmpty)
                {
                    content.Add(item);
                }
            }

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

            return(content);
        }
Exemplo n.º 7
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);
        }