private void OnPlatformItem(string keyword, XPathNavigator navigator)
        {
            ReferenceGroupContext groupContext =
                _context.GroupContexts[_group.Id] as ReferenceGroupContext;

            if (groupContext == null)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

            ReferenceGroupContext sourceContext = groupContext;

            if (!String.IsNullOrEmpty(_sourceId))
            {
                sourceContext = groupContext.Contexts[_sourceId] as ReferenceGroupContext;
            }
            if (sourceContext == null)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

            BuildFramework framework = sourceContext.Framework;

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

            // For Silverlight/Portable, we use the equivalent .NET Framework
            // version, since the current reflection tool does not directly
            // support Silverlight/Portable.
            BuildFrameworkKind kind = framework.FrameworkType.Kind;

            if (kind == BuildFrameworkKind.Silverlight ||
                kind == BuildFrameworkKind.Portable)
            {
                int major = framework.Version.Major;

                BuildFramework netFramework = null;
                switch (major)
                {
                case 5:
                    netFramework = BuildFrameworks.GetFramework(
                        major, BuildFrameworkKind.DotNet);
                    if (netFramework == null)
                    {
                        // If not found, we move a version down...
                        major = major - 1;
                        goto case 4;
                    }
                    break;

                case 4:
                    netFramework = BuildFrameworks.GetFramework(
                        major, BuildFrameworkKind.DotNet);
                    if (netFramework == null)
                    {
                        // If not found, we move a version down...
                        major = major - 1;
                        goto case 3;
                    }
                    break;

                case 3:
                    netFramework = BuildFrameworks.GetFramework(
                        major, 5, BuildFrameworkKind.DotNet);
                    if (netFramework == null)
                    {
                        netFramework = BuildFrameworks.GetFramework(
                            major, BuildFrameworkKind.DotNet);
                    }
                    if (netFramework == null)
                    {
                        // If not found, we move a version down...
                        major = major - 1;
                        goto case 2;
                    }
                    break;

                case 2:
                    netFramework = BuildFrameworks.GetFramework(
                        major, BuildFrameworkKind.DotNet);
                    break;

                default:
                    throw new BuildException(
                              "The specified Silverlight version is not supported.");
                }

                if (netFramework == null)
                {
                    throw new BuildException(
                              "The equivalent .NET Framework for the specified Silverlight version cannot be found.");
                }

                framework = netFramework;
            }
            else if (kind == BuildFrameworkKind.ScriptSharp)
            {
                int major = framework.Version.Major;

                BuildFramework netFramework = null;
                switch (major)
                {
                case 1:
                    // The current v1.0 is released for .NET 4.0
                    netFramework = BuildFrameworks.GetFramework(
                        4, BuildFrameworkKind.DotNet);
                    if (netFramework == null)
                    {
                        netFramework = BuildFrameworks.LatestFramework;
                    }
                    break;

                default:
                    throw new BuildException(
                              "The specified Silverlight version is not supported.");
                }

                if (netFramework == null)
                {
                    throw new BuildException(
                              "The equivalent .NET Framework for the specified Silverlight version cannot be found.");
                }

                framework = netFramework;
            }

            Version version = framework.Version;

            XmlWriter writer = navigator.InsertAfter();

            // For now, write the default...
            // <platform version="2.0"
            //   path="%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\" />
            writer.WriteStartElement("platform");
            if (version.Major > 2)
            {
                writer.WriteAttributeString("version", "2.0");
                if (version.Major == 3)
                {
                    Version version2 = BuildFrameworks.GetVersion(2, -1,
                                                                  BuildFrameworkKind.DotNet);

                    writer.WriteAttributeString("path", String.Format(
                                                    @"%SystemRoot%\Microsoft.NET\Framework\v{0}\", version2.ToString(3)));
                }
                else
                {
                    string assemPath = Path.GetFullPath(
                        Environment.ExpandEnvironmentVariables(String.Format(
                                                                   @"%SystemRoot%\Microsoft.NET\Framework\{0}\", framework.Folder)));
                    if (!Directory.Exists(assemPath))
                    {
                        assemPath = framework.AssemblyDir;
                    }
                    writer.WriteAttributeString("path", assemPath);
                }
            }
            else
            {
                writer.WriteAttributeString("version", version.ToString(2));
                writer.WriteAttributeString("path", String.Format(
                                                @"%SystemRoot%\Microsoft.NET\Framework\{0}\", framework.Folder));
            }
            writer.WriteEndElement();

            writer.Close();
            navigator.DeleteSelf();
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
        private bool OnExecuteSingle(BuildContext context)
        {
            BuildLogger logger = context.Logger;

            ReferenceGroupContext groupContext =
                context.GroupContexts[_group.Id] as ReferenceGroupContext;

            if (groupContext == null)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

            ReferenceContent content = _group.Content;

            if (content == null)
            {
                if (logger != null)
                {
                    logger.WriteLine("StepReferenceInit: There is no content associated with the reference group.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            BuildFrameworkType frameworkType = content.FrameworkType;

            if (frameworkType == BuildFrameworkType.Null ||
                frameworkType == BuildFrameworkType.None)
            {
                if (logger != null)
                {
                    logger.WriteLine("StepReferenceInit: There is no valid framework type specified for this reference group.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            BuildFramework framework = BuildFrameworks.GetFramework(frameworkType);

            if (framework == null)
            {
                if (logger != null)
                {
                    logger.WriteLine("StepReferenceInit: The specified framework type for this reference group is not installed.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            string workingDir = context.WorkingDirectory;

            groupContext.Framework = framework;

            string commentDir  = groupContext.CommentFolder;
            string assemblyDir = groupContext.AssemblyFolder;

            if (String.IsNullOrEmpty(commentDir))
            {
                commentDir = "Comments";
            }
            if (!Path.IsPathRooted(commentDir))
            {
                commentDir = Path.Combine(workingDir, commentDir);
            }
            if (!Directory.Exists(commentDir))
            {
                Directory.CreateDirectory(commentDir);
            }

            if (String.IsNullOrEmpty(assemblyDir))
            {
                assemblyDir = "Assemblies";
            }
            if (!Path.IsPathRooted(assemblyDir))
            {
                assemblyDir = Path.Combine(workingDir, assemblyDir);
            }
            if (!Directory.Exists(assemblyDir))
            {
                Directory.CreateDirectory(assemblyDir);
            }

            string dependencyDir = groupContext.DependencyFolder;

            if (String.IsNullOrEmpty(dependencyDir))
            {
                dependencyDir = "Dependencies";
            }
            if (!Path.IsPathRooted(dependencyDir))
            {
                dependencyDir = Path.Combine(workingDir, dependencyDir);
            }
            if (!Directory.Exists(dependencyDir))
            {
                Directory.CreateDirectory(dependencyDir);
            }

            groupContext.CommentDir    = commentDir;
            groupContext.AssemblyDir   = assemblyDir;
            groupContext.DependencyDir = dependencyDir;

            // Copy the comments to the expected directory...
            int           itemCount    = content.Count;
            List <string> commentFiles = new List <string>(itemCount);

            CommentContent commentContent = content.Comments;

            if (commentContent != null && !commentContent.IsEmpty)
            {
                string commentFile = Path.Combine(commentDir,
                                                  groupContext["$CommentsFile"]);

                // If there is a valid file or there is an attached file...
                BuildFilePath filePath = commentContent.ContentFile;
                if (filePath != null && filePath.Exists)
                {
                    if (commentContent.IsLoaded)
                    {
                        commentContent.Save();
                    }

                    File.Copy(filePath.Path, commentFile);
                }
                else
                {
                    commentContent.SaveCopyAs(commentFile);
                }
                File.SetAttributes(commentFile, FileAttributes.Normal);

                commentFiles.Add(commentFile);
            }

            for (int i = 0; i < itemCount; i++)
            {
                ReferenceItem item = content[i];
                if (item == null || item.IsEmpty)
                {
                    continue;
                }

                string commentsFile = item.Comments;
                if (!String.IsNullOrEmpty(commentsFile))
                {
                    string fileName = Path.GetFileName(commentsFile);
                    fileName = Path.Combine(commentDir, fileName);
                    if (commentsFile.Length != fileName.Length ||
                        String.Equals(commentsFile, fileName,
                                      StringComparison.OrdinalIgnoreCase) == false)
                    {
                        File.Copy(commentsFile, fileName, true);
                        File.SetAttributes(fileName, FileAttributes.Normal);

                        commentFiles.Add(fileName);
                    }
                }

                string assemblyFile = item.Assembly;
                if (!String.IsNullOrEmpty(assemblyFile))
                {
                    string fileName = Path.GetFileName(assemblyFile);
                    fileName = Path.Combine(assemblyDir, fileName);
                    if (assemblyFile.Length != fileName.Length ||
                        String.Equals(assemblyFile, fileName,
                                      StringComparison.OrdinalIgnoreCase) == false)
                    {
                        File.Copy(assemblyFile, fileName, true);
                        File.SetAttributes(fileName, FileAttributes.Normal);
                    }
                }
            }

            // Finally, store the list of extracted comment file to its context...
            groupContext.CommentFiles = commentFiles;

            // 1. Copy the dependencies to the expected directory...
            ReferenceProjectVisitor dependencyResolver =
                new ReferenceProjectVisitor();

            dependencyResolver.Initialize(context);
            dependencyResolver.Visit(_group);
            dependencyResolver.Uninitialize();

            return(true);
        }
예제 #4
0
        private bool OnExecuteMultiple(BuildContext context)
        {
            ReferenceGroupContext groupContext =
                context.GroupContexts[_group.Id] as ReferenceGroupContext;

            if (groupContext == null)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

            BuildLogger logger = context.Logger;

            for (int v = 0; v < _listVersions.Count; v++)
            {
                ReferenceVersions versions = _listVersions[v];

                for (int j = 0; j < versions.Count; j++)
                {
                    ReferenceVersionSource source = versions[j];

                    ReferenceGroupContext versionsContext =
                        groupContext.Contexts[source.SourceId];

                    string workingDir = versionsContext["$WorkingDir"];

                    ReferenceContent content = source.Content;
                    if (content == null)
                    {
                        if (logger != null)
                        {
                            logger.WriteLine("StepReferenceInit: There is no content associated with the reference group.",
                                             BuildLoggerLevel.Error);
                        }

                        return(false);
                    }

                    BuildFrameworkType frameworkType = content.FrameworkType;
                    if (frameworkType == BuildFrameworkType.Null ||
                        frameworkType == BuildFrameworkType.None)
                    {
                        if (logger != null)
                        {
                            logger.WriteLine("StepReferenceInit: There is no valid framework type specified for this reference group.",
                                             BuildLoggerLevel.Error);
                        }

                        return(false);
                    }

                    BuildFramework framework = BuildFrameworks.GetFramework(frameworkType);
                    if (framework == null)
                    {
                        if (logger != null)
                        {
                            logger.WriteLine("StepReferenceInit: The specified framework type for this reference group is not installed.",
                                             BuildLoggerLevel.Error);
                        }

                        return(false);
                    }

                    versionsContext.Framework = framework;

                    string commentDir  = versionsContext.CommentFolder;
                    string assemblyDir = versionsContext.AssemblyFolder;
                    if (String.IsNullOrEmpty(commentDir))
                    {
                        commentDir = "Comments";
                    }
                    if (!Path.IsPathRooted(commentDir))
                    {
                        commentDir = Path.Combine(workingDir, commentDir);
                    }
                    if (!Directory.Exists(commentDir))
                    {
                        Directory.CreateDirectory(commentDir);
                    }

                    if (String.IsNullOrEmpty(assemblyDir))
                    {
                        assemblyDir = "Assemblies";
                    }
                    if (!Path.IsPathRooted(assemblyDir))
                    {
                        assemblyDir = Path.Combine(workingDir, assemblyDir);
                    }
                    if (!Directory.Exists(assemblyDir))
                    {
                        Directory.CreateDirectory(assemblyDir);
                    }

                    string dependencyDir = versionsContext.DependencyFolder;
                    if (String.IsNullOrEmpty(dependencyDir))
                    {
                        dependencyDir = "Dependencies";
                    }
                    if (!Path.IsPathRooted(dependencyDir))
                    {
                        dependencyDir = Path.Combine(workingDir, dependencyDir);
                    }
                    if (!Directory.Exists(dependencyDir))
                    {
                        Directory.CreateDirectory(dependencyDir);
                    }

                    versionsContext.CommentDir    = commentDir;
                    versionsContext.AssemblyDir   = assemblyDir;
                    versionsContext.DependencyDir = dependencyDir;

                    // Copy the comments to the expected directory...
                    int           itemCount    = content.Count;
                    List <string> commentFiles = new List <string>(itemCount);

                    for (int i = 0; i < itemCount; i++)
                    {
                        ReferenceItem item = content[i];
                        if (item == null || item.IsEmpty)
                        {
                            continue;
                        }

                        string commentsFile = item.Comments;
                        if (!String.IsNullOrEmpty(commentsFile))
                        {
                            string fileName = Path.GetFileName(commentsFile);
                            fileName = Path.Combine(commentDir, fileName);
                            if (commentsFile.Length != fileName.Length ||
                                String.Equals(commentsFile, fileName,
                                              StringComparison.OrdinalIgnoreCase) == false)
                            {
                                File.Copy(commentsFile, fileName, true);
                                File.SetAttributes(fileName, FileAttributes.Normal);

                                commentFiles.Add(fileName);
                            }
                        }

                        string assemblyFile = item.Assembly;
                        if (!String.IsNullOrEmpty(assemblyFile))
                        {
                            string fileName = Path.GetFileName(assemblyFile);
                            fileName = Path.Combine(assemblyDir, fileName);
                            if (assemblyFile.Length != fileName.Length ||
                                String.Equals(assemblyFile, fileName,
                                              StringComparison.OrdinalIgnoreCase) == false)
                            {
                                File.Copy(assemblyFile, fileName, true);
                                File.SetAttributes(fileName, FileAttributes.Normal);
                            }
                        }
                    }

                    //TODO--PAUL: Should the project/namespace summary be included?

                    // Finally, store the list of extracted comment file to its context...
                    versionsContext.CommentFiles = commentFiles;

                    // 1. Copy the dependencies to the expected directory...
                    ReferenceProjectVisitor dependencyResolver =
                        new ReferenceProjectVisitor(source.SourceId, content);
                    dependencyResolver.Initialize(context);
                    dependencyResolver.Visit(_group);
                    dependencyResolver.Uninitialize();
                }
            }

            return(true);
        }
예제 #5
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);
        }