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); } string searchPattern = _searchPattern; if (String.IsNullOrEmpty(searchPattern)) { searchPattern = "*.dll"; } string[] fullPaths = Directory.GetFiles(_sourcePath.Path, searchPattern, _isRecursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); if (fullPaths == null || fullPaths.Length == 0) { return(null); } HashSet <string> dependencyDirs = new HashSet <string>( StringComparer.OrdinalIgnoreCase); Dictionary <string, string> assemblies = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (string fullPath in fullPaths) { string fileName = Path.GetFileName(fullPath); if (assemblies.ContainsKey(fileName) || (_excludeSet.Count != 0 && _excludeSet.Contains(fileName))) { continue; } // We will not use the assemblies without comments as // dependencies, since we cannot verify these are .NET DLLs. string commentFile = Path.ChangeExtension(fullPath, ".xml"); if (!File.Exists(commentFile)) { continue; } string dependencyDir = Path.GetDirectoryName(fullPath); if (!dependencyDir.EndsWith("\\")) { dependencyDir += "\\"; } dependencyDirs.Add(dependencyDir); assemblies[fileName] = fullPath; } if (assemblies.Count == 0) { 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; } foreach (KeyValuePair <string, string> pair in assemblies) { string assemblyFile = pair.Value; string commentFile = Path.ChangeExtension(assemblyFile, ".xml"); content.AddItem(commentFile, assemblyFile); } // Provide the dependency information for the content... DependencyContent depContents = content.Dependencies; foreach (string dependencyDir in dependencyDirs) { depContents.Paths.Add(new BuildDirectoryPath(dependencyDir)); } // 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); }
/// <summary> /// The creates the configuration information or settings required by the /// target component for the build process. /// </summary> /// <param name="group"> /// A build group, <see cref="BuildGroup"/>, representing the documentation /// target for configuration. /// </param> /// <param name="writer"> /// An <see cref="XmlWriter"/> object used to create one or more new /// child nodes at the end of the list of child nodes of the current node. /// </param> /// <returns> /// Returns <see langword="true"/> for a successful configuration; /// otherwise, it returns <see langword="false"/>. /// </returns> /// <remarks> /// The <see cref="XmlWriter"/> writer passed to this configuration object /// may be passed on to other configuration objects, so do not close or /// dispose it. /// </remarks> public override bool Configure(BuildGroup group, XmlWriter writer) { BuildExceptions.NotNull(group, "group"); BuildExceptions.NotNull(writer, "writer"); IBuildNamedList <BuildGroupContext> groupContexts = _context.GroupContexts; if (groupContexts == null || groupContexts.Count == 0) { throw new BuildException( "The group context is not provided, and it is required by the build system."); } ReferenceGroupContext groupContext = 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."); } if (!this.Enabled || !this.IsInitialized) { return(false); } BuildFramework framework = groupContext.Framework; BuildFrameworkKind kind = framework.FrameworkType.Kind; ReferenceEngineSettings referenceSettings = _settings.EngineSettings[ BuildEngineType.Reference] as ReferenceEngineSettings; BuildSpecialSdkType webSdkType = referenceSettings.WebMvcSdkType; writer.WriteStartElement("options"); // start - options writer.WriteAttributeString("locale", _settings.CultureInfo.Name.ToLower()); if (kind == BuildFrameworkKind.Silverlight) { writer.WriteAttributeString("version", "VS.95"); } else if (kind == BuildFrameworkKind.Compact) { // The framework 3.5 is the last version of Windows CE... writer.WriteAttributeString("version", "VS.90"); } if (webSdkType != BuildSpecialSdkType.Null && webSdkType != BuildSpecialSdkType.None) { switch (webSdkType.Value) { case 10: // ASP.NET MVC 1.0: Supported in .NET 3.5 writer.WriteAttributeString("mvcVersion", "VS.90"); break; case 20: // ASP.NET MVC 2.0: Supported in .NET 3.5 SP1 // This is currently the default documentation for // the ASP.NET MVC Framework... writer.WriteAttributeString("mvcVersion", ""); break; case 30: // ASP.NET MVC 3.0: Supported in .NET 4.0 writer.WriteAttributeString("mvcVersion", "VS.98"); break; case 40: // ASP.NET MVC 4.0: Supported in .NET 4.5 writer.WriteAttributeString("mvcVersion", "VS.108"); break; } } writer.WriteAttributeString("linkTarget", "_" + _format.ExternalLinkTarget.ToString().ToLower()); writer.WriteEndElement(); // end - options bool isEmbeddedGroup = false; bool frameworkAvailable = false; bool isEmbeddedScript = groupContext.IsEmbeddedGroup; string tempText = _context["$EmbeddedScriptSharp"]; if (!String.IsNullOrEmpty(tempText)) { isEmbeddedScript = Convert.ToBoolean(tempText); } List <DataSource> dataSources = new List <DataSource>(); if (kind == BuildFrameworkKind.Silverlight) { string silverlightDir = groupContext["$SilverlightDataDir"]; if (!String.IsNullOrEmpty(silverlightDir) && Directory.Exists(silverlightDir)) { frameworkAvailable = true; writer.WriteStartElement("targets"); writer.WriteAttributeString("base", silverlightDir); writer.WriteAttributeString("recurse", "false"); writer.WriteAttributeString("system", "true"); writer.WriteAttributeString("files", "*.xml"); writer.WriteAttributeString("type", _format.ExternalLinkType.ToString().ToLower()); // Write the data source... Version latestVersion = BuildFrameworks.LatestSilverlightVersion; if (latestVersion == null) { latestVersion = framework.Version; } this.WriteDataSource(writer, DataSourceType.Silverlight, silverlightDir, latestVersion, true, true, dataSources); writer.WriteEndElement(); } } else if (kind == BuildFrameworkKind.Portable) { string portableDir = groupContext["$PortableDataDir"]; if (!String.IsNullOrEmpty(portableDir) && Directory.Exists(portableDir)) { frameworkAvailable = true; writer.WriteStartElement("targets"); writer.WriteAttributeString("base", portableDir); writer.WriteAttributeString("recurse", "false"); writer.WriteAttributeString("system", "true"); writer.WriteAttributeString("files", "*.xml"); writer.WriteAttributeString("type", _format.ExternalLinkType.ToString().ToLower()); // Write the data source... Version latestVersion = BuildFrameworks.LatestPortableVersion; if (latestVersion == null) { latestVersion = framework.Version; } this.WriteDataSource(writer, DataSourceType.Portable, portableDir, latestVersion, true, false, dataSources); writer.WriteEndElement(); } } else if (kind == BuildFrameworkKind.ScriptSharp) { string scriptSharpDir = groupContext["$ScriptSharpDataDir"]; if (!String.IsNullOrEmpty(scriptSharpDir) && Directory.Exists(scriptSharpDir)) { frameworkAvailable = true; if (!isEmbeddedGroup) { writer.WriteStartElement("targets"); writer.WriteAttributeString("base", scriptSharpDir); writer.WriteAttributeString("recurse", "false"); writer.WriteAttributeString("system", "true"); writer.WriteAttributeString("files", "*.xml"); if (isEmbeddedScript) { writer.WriteAttributeString("type", BuildLinkType.Local.ToString().ToLower()); } else { writer.WriteAttributeString("type", BuildLinkType.None.ToString().ToLower()); } // Write the data source... Version latestVersion = BuildFrameworks.LatestScriptSharpVersion; if (latestVersion == null) { latestVersion = framework.Version; } this.WriteDataSource(writer, DataSourceType.ScriptSharp, scriptSharpDir, latestVersion, true, false, dataSources); writer.WriteEndElement(); } } } // If not specialized framework, then write the default... if (!frameworkAvailable || kind == BuildFrameworkKind.None || kind == BuildFrameworkKind.DotNet || kind == BuildFrameworkKind.Compact) { string dotNetDataDir = Path.GetFullPath( Environment.ExpandEnvironmentVariables(ReferenceEngine.ReflectionDirectory)); writer.WriteStartElement("targets"); writer.WriteAttributeString("base", dotNetDataDir); writer.WriteAttributeString("recurse", "true"); writer.WriteAttributeString("system", "true"); writer.WriteAttributeString("files", "*.xml"); writer.WriteAttributeString("type", _format.ExternalLinkType.ToString().ToLower()); // Write the data source... this.WriteDataSource(writer, DataSourceType.Framework, dotNetDataDir, ReferenceEngine.ReflectionVersion, true, false, dataSources); writer.WriteEndElement(); } // The Portable and ScriptSharp do not support Blend... if (kind != BuildFrameworkKind.Portable && kind != BuildFrameworkKind.Compact && kind != BuildFrameworkKind.ScriptSharp) { string blendDir = groupContext["$BlendDataDir"]; if (!String.IsNullOrEmpty(blendDir) && Directory.Exists(blendDir)) { writer.WriteStartElement("targets"); writer.WriteAttributeString("base", blendDir); writer.WriteAttributeString("recurse", "false"); writer.WriteAttributeString("system", "true"); writer.WriteAttributeString("files", "*.xml"); writer.WriteAttributeString("type", _format.ExternalLinkType.ToString().ToLower()); // Write the data source... BuildSpecialSdk latestBlendSdk = null; if (kind == BuildFrameworkKind.Silverlight) { latestBlendSdk = BuildSpecialSdks.LatestBlendSilverlightSdk; } else { latestBlendSdk = BuildSpecialSdks.LatestBlendWpfSdk; } Version latestVersion = (latestBlendSdk == null) ? null : latestBlendSdk.Version; if (latestVersion == null) { latestVersion = framework.Version; } this.WriteDataSource(writer, DataSourceType.Blend, blendDir, latestVersion, true, kind == BuildFrameworkKind.Silverlight, dataSources); writer.WriteEndElement(); } } IList <string> linkDirs = _context.GetValue( "$ReferenceLinkDirectories") as IList <string>; IList <ReferenceLinkSource> linkSources = _context.GetValue( "$ReferenceLinkSources") as IList <ReferenceLinkSource>; if ((linkDirs != null && linkDirs.Count != 0) && (linkSources != null && linkSources.Count == linkDirs.Count)) { for (int i = 0; i < linkDirs.Count; i++) { ReferenceLinkSource linkSource = linkSources[i]; BuildLinkType sourceLinkType = linkSource.LinkType; writer.WriteStartElement("targets"); writer.WriteAttributeString("base", linkDirs[i]); writer.WriteAttributeString("recurse", "true"); writer.WriteAttributeString("system", "false"); writer.WriteAttributeString("files", "*.xml"); writer.WriteAttributeString("type", sourceLinkType.ToString().ToLower()); writer.WriteEndElement(); } } BuildLinkType linkType = _format.LinkType; string linkTypeText = linkType.ToString().ToLower(); // For the embedded group, we will not link to the other groups... if (!isEmbeddedGroup) { for (int i = 0; i < groupContexts.Count; i++) { ReferenceGroupContext aContext = groupContexts[i] as ReferenceGroupContext; if (aContext == null || aContext.IsLinkGroup) { continue; } if (aContext.GroupType != BuildGroupType.Reference || aContext == groupContext) { continue; } string linkFile = aContext["$ReflectionFile"]; if (!String.IsNullOrEmpty(linkFile)) { writer.WriteStartElement("targets"); writer.WriteAttributeString("base", @".\"); writer.WriteAttributeString("recurse", "false"); writer.WriteAttributeString("system", "false"); writer.WriteAttributeString("files", @".\" + linkFile); writer.WriteAttributeString("type", linkTypeText); writer.WriteEndElement(); } } } //<targets base=".\" recurse="false" // files=".\reflection.xml" type="local" /> writer.WriteStartElement("targets"); writer.WriteAttributeString("base", @".\"); writer.WriteAttributeString("recurse", "false"); writer.WriteAttributeString("system", "false"); writer.WriteAttributeString("files", @".\" + groupContext["$ReflectionFile"]); if (isEmbeddedGroup) { writer.WriteAttributeString("type", BuildLinkType.Local.ToString().ToLower()); } else { writer.WriteAttributeString("type", linkTypeText); } writer.WriteEndElement(); // Provide the information for the MSDN link resolvers... writer.WriteStartElement("linkResolver"); // start - linkResolver writer.WriteAttributeString("storage", _linkStorage.ToString().ToLower()); writer.WriteAttributeString("cache", _cacheLinks ? "true" : "false"); if (dataSources != null && dataSources.Count != 0) { for (int i = 0; i < dataSources.Count; i++) { DataSource dataSource = dataSources[i]; this.WriteDataSource(writer, dataSource.SourceType, dataSource.InputDir, dataSource.Version, dataSource.IsDatabase, dataSource.IsSilverlight, true); } } writer.WriteEndElement(); // end - linkResolver // Finally, provide the information for the conceptual links // in reference documents, if any... bool hasConceptualContext = _settings.BuildConceptual; if (hasConceptualContext) { hasConceptualContext = false; for (int i = 0; i < groupContexts.Count; i++) { BuildGroupContext aContext = groupContexts[i]; if (aContext.GroupType == BuildGroupType.Conceptual) { hasConceptualContext = true; break; } } } if (hasConceptualContext) { ConceptualEngineSettings conceptualSettings = _settings.EngineSettings[ BuildEngineType.Conceptual] as ConceptualEngineSettings; Debug.Assert(conceptualSettings != null, "The settings does not include the reference engine settings."); if (conceptualSettings == null) { return(false); } ConceptualLinkConfiguration linkConfig = conceptualSettings.ConceptualLinks; Debug.Assert(linkConfig != null, "There is no conceptual link configuration available."); if (linkConfig == null) { return(false); } writer.WriteStartElement("conceptualLinks"); //start: conceptualLinks writer.WriteAttributeString("enabled", "true"); writer.WriteAttributeString("showText", linkConfig.ShowLinkText.ToString()); writer.WriteAttributeString("showBrokenLinkText", linkConfig.ShowBrokenLinkText.ToString()); writer.WriteAttributeString("type", linkTypeText); for (int i = 0; i < groupContexts.Count; i++) { BuildGroupContext aContext = groupContexts[i]; if (aContext.GroupType == BuildGroupType.Conceptual) { writer.WriteStartElement("conceptualTargets"); // start - conceptualTargets writer.WriteAttributeString("base", String.Format( @".\{0}", aContext["$DdueXmlCompDir"])); writer.WriteAttributeString("type", linkTypeText); writer.WriteEndElement(); // end - conceptualTargets } } writer.WriteEndElement(); //end: conceptualLinks } return(true); }
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(); }
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); } } }
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); } } }
static void Main(string[] args) { // This is our documentation content and settings definitions BuildDocumenter documenter = new BuildDocumenter(); Console.WriteLine("Installed Frameworks:"); IList <BuildFramework> frameworks = BuildFrameworks.InstalledFrameworks; for (int i = 0; i < frameworks.Count; i++) { BuildFramework framework = frameworks[i]; Console.WriteLine("\t{0}: {1} - {2} ... {3}", i, framework.Version, framework.FrameworkType, framework.AssemblyDir); //if (framework.FrameworkType.Kind == BuildFrameworkKind.Silverlight) //{ // Version version = framework.Version; // if (version.Major >= 5) // { // } //} } Console.WriteLine(); try { BuildSettings settings = documenter.Settings; // Customize the documentation settings... TestOptions options = new TestOptions(settings); // Create default test settings... options.Create(); // Prompt for content options... if (!options.Run()) { Console.WriteLine("--->>Exiting the build process.<<---"); Console.WriteLine(); return; } // Create the documentation contents... // The conceptual topics... ConceptualTopics.Create(documenter, options); // The reference topics... ReferenceTopics.Create(documenter, options); // The local reference topics... //LocalReferenceTopics.Create(documenter, options); // Create custom TOC, if necessary... TestTocOptions.Create(documenter, options); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } // If we get this far, the content is created and we will proceed // to build the help... BuildProject project = null; try { // Create the project, with the documentation data, the type // of system and the type of build... project = new BuildProject(documenter, BuildSystem.Console, BuildType.Testing); //project.TargetPlatform = "Win32"; //project.TargetConfiguration = "Debug"; // Initialize the project, if successful, build it... project.Initialize(); if (project.IsInitialized) { project.Build(); } else { Console.WriteLine( "Error in reference build initialization."); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { // Finally, un-initialize the project and dispose it... if (project != null) { project.Uninitialize(); project.Dispose(); project = null; } } }
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); }
private void OnReferenceContentsItem(string keyword, XPathNavigator navigator) { BuildContext context = this.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."); } BuildFramework framework = groupContext.Framework; if (framework == null) { throw new BuildException("No valid framework is specified."); } BuildFrameworkKind kind = framework.FrameworkType.Kind; //<data base="%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\en\" // recurse="false" files="*.xml" /> //<data files=".\Comments\Project.xml" /> //<data files=".\Comments\TestLibrary.xml" /> XmlWriter writer = navigator.InsertAfter(); string warnOverride = "false"; BuildLoggerVerbosity loggerVerbosity = _settings.Logging.Verbosity; if (loggerVerbosity == BuildLoggerVerbosity.Detailed || loggerVerbosity == BuildLoggerVerbosity.Diagnostic || loggerVerbosity == BuildLoggerVerbosity.Normal) { warnOverride = "true"; } CultureInfo culture = _settings.CultureInfo; string langName = culture.TwoLetterISOLanguageName; IEnumerable <string> commentDirs = framework.CommentDirs; // Store all the framework directories here, we will use this to // eliminate adding comment files directly from these directories... HashSet <string> commentDirSet = new HashSet <string>( StringComparer.OrdinalIgnoreCase); if (commentDirs != null) { writer.WriteComment(" The following are the framework (.NET, Silverlight etc) comment file directories. "); if (kind == BuildFrameworkKind.Silverlight) { this.WriteDataSources(writer, DataSourceType.Silverlight, String.Empty, framework.Version, true, true, langName, commentDirs); } else if (kind == BuildFrameworkKind.Portable) { this.WriteDataSources(writer, DataSourceType.Portable, String.Empty, framework.Version, true, false, langName, commentDirs); } else if (kind == BuildFrameworkKind.ScriptSharp) { this.WriteDataSources(writer, DataSourceType.ScriptSharp, String.Empty, framework.Version, true, false, langName, commentDirs); } else if (kind == BuildFrameworkKind.Compact) { // For the compact framework, the comments files are all // redirected to the system comment files... BuildFramework latestFramework = BuildFrameworks.LatestFramework; commentDirs = latestFramework.CommentDirs; this.WriteDataSources(writer, DataSourceType.Framework, String.Empty, latestFramework.Version, true, false, langName, commentDirs); } else { // Write the data source... this.WriteDataSources(writer, DataSourceType.Framework, String.Empty, framework.Version, true, false, langName, commentDirs); } foreach (string commentDir in commentDirs) { if (!Directory.Exists(commentDir)) { continue; } string finalDir = null; string langDir = Path.Combine(commentDir, langName); writer.WriteStartElement("data"); // start - data if (Directory.Exists(langDir)) { writer.WriteAttributeString("base", langDir); finalDir = langDir; } else { writer.WriteAttributeString("base", commentDir); finalDir = commentDir; } writer.WriteAttributeString("recurse", "false"); writer.WriteAttributeString("system", "true"); writer.WriteAttributeString("warnOverride", warnOverride); writer.WriteAttributeString("files", "*.xml"); writer.WriteEndElement(); // end - data if (!finalDir.EndsWith("\\")) { finalDir += "\\"; } commentDirSet.Add(finalDir); } } IEnumerable <string> commentFiles = framework.CommentFiles; if (commentFiles != null) { writer.WriteComment(" The following are the framework (.NET, Silverlight etc) comment files. "); foreach (string commentFile in commentFiles) { // Try to avoid adding comment files from known framework // directories... string commentDir = Path.GetDirectoryName(commentFile); if (!commentDir.EndsWith("\\")) { commentDir += "\\"; } if (commentDirSet.Contains(commentDir)) { continue; } writer.WriteStartElement("data"); writer.WriteAttributeString("files", commentFile); writer.WriteAttributeString("warnOverride", "false"); writer.WriteEndElement(); } } IList <string> linkCommentFiles = groupContext.LinkCommentFiles; if (linkCommentFiles != null && linkCommentFiles.Count != 0) { writer.WriteComment(" The following are the dependent assembly comment files. "); for (int i = 0; i < linkCommentFiles.Count; i++) { string linkCommentFile = linkCommentFiles[i]; // Try to avoid adding comment files from known framework // directories... string commentDir = Path.GetDirectoryName(linkCommentFile); if (!commentDir.EndsWith("\\")) { commentDir += "\\"; } if (commentDirSet.Contains(commentDir)) { continue; } writer.WriteStartElement("data"); writer.WriteAttributeString("files", linkCommentFile); writer.WriteAttributeString("warnOverride", "false"); writer.WriteEndElement(); } } IList <string> targetCommentFiles = groupContext.CommentFiles; if (targetCommentFiles != null && targetCommentFiles.Count != 0) { writer.WriteComment(" The following are the target comment files. "); for (int i = 0; i < targetCommentFiles.Count; i++) { writer.WriteStartElement("data"); writer.WriteAttributeString("files", targetCommentFiles[i]); writer.WriteAttributeString("warnOverride", "false"); writer.WriteEndElement(); } } writer.Close(); navigator.DeleteSelf(); }
protected void OnReferenceDataItem(string keyword, XPathNavigator navigator) { BuildContext context = this.Context; IBuildNamedList <BuildGroupContext> groupContexts = context.GroupContexts; if (groupContexts == null || groupContexts.Count == 0) { throw new BuildException( "The group context is not provided, and it is required by the build system."); } ReferenceGroupContext groupContext = 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."); } BuildFramework framework = groupContext.Framework; BuildFrameworkKind kind = framework.FrameworkType.Kind; string sandcastleDir = context.SandcastleDirectory; //<data base="%DXROOT%\Data\Reflection" recurse="true" files="*.xml" /> //<data files=".\reflection.xml" /> XmlWriter writer = navigator.InsertAfter(); // For now, lets simply write the default... bool dataAvailable = false; if (kind == BuildFrameworkKind.Silverlight) { string silverlightDir = groupContext["$SilverlightDataDir"]; if (!String.IsNullOrEmpty(silverlightDir) && Directory.Exists(silverlightDir)) { dataAvailable = true; writer.WriteStartElement("data"); // start - data writer.WriteAttributeString("base", silverlightDir); writer.WriteAttributeString("recurse", "true"); // Prevent warning, when the same namespace occurs in different // assemblies... writer.WriteAttributeString("warnOverride", "false"); writer.WriteAttributeString("files", "*.xml"); // Write the data source... Version latestVersion = BuildFrameworks.LatestSilverlightVersion; if (latestVersion == null) { latestVersion = framework.Version; } this.WriteDataSource(writer, DataSourceType.Silverlight, silverlightDir, latestVersion, true, true); writer.WriteEndElement(); // end - data } } else if (kind == BuildFrameworkKind.Portable) { string portableDir = groupContext["$PortableDataDir"]; if (!String.IsNullOrEmpty(portableDir) && Directory.Exists(portableDir)) { dataAvailable = true; writer.WriteStartElement("data"); // start - data writer.WriteAttributeString("base", portableDir); writer.WriteAttributeString("recurse", "true"); // Prevent warning, when the same namespace occurs in different // assemblies... writer.WriteAttributeString("warnOverride", "false"); writer.WriteAttributeString("files", "*.xml"); // Write the data source... Version latestVersion = BuildFrameworks.LatestPortableVersion; if (latestVersion == null) { latestVersion = framework.Version; } this.WriteDataSource(writer, DataSourceType.Portable, portableDir, latestVersion, true, false); writer.WriteEndElement(); // end - data } } else if (kind == BuildFrameworkKind.ScriptSharp) { string scriptSharpDir = groupContext["$ScriptSharpDataDir"]; if (!String.IsNullOrEmpty(scriptSharpDir) && Directory.Exists(scriptSharpDir)) { dataAvailable = true; if (!groupContext.IsEmbeddedGroup) { writer.WriteStartElement("data"); // start - data writer.WriteAttributeString("base", scriptSharpDir); writer.WriteAttributeString("recurse", "true"); // Prevent warning, when the same namespace occurs in different // assemblies... writer.WriteAttributeString("warnOverride", "false"); writer.WriteAttributeString("files", "*.xml"); // Write the data source... Version latestVersion = BuildFrameworks.LatestScriptSharpVersion; if (latestVersion == null) { latestVersion = framework.Version; } this.WriteDataSource(writer, DataSourceType.ScriptSharp, scriptSharpDir, latestVersion, true, false); writer.WriteEndElement(); // end - data } } } if (!dataAvailable || kind == BuildFrameworkKind.None || kind == BuildFrameworkKind.DotNet || kind == BuildFrameworkKind.Compact) { string dotNetDataDir = Path.GetFullPath( Environment.ExpandEnvironmentVariables(ReferenceEngine.ReflectionDirectory)); writer.WriteStartElement("data"); // start - data writer.WriteAttributeString("base", dotNetDataDir); writer.WriteAttributeString("recurse", "true"); // Prevent warning, when the same namespace occurs in different // assemblies... writer.WriteAttributeString("warnOverride", "false"); writer.WriteAttributeString("files", "*.xml"); // Write the data source... this.WriteDataSource(writer, DataSourceType.Framework, dotNetDataDir, ReferenceEngine.ReflectionVersion, true, false); writer.WriteEndElement(); // end - data } // The Portable and ScriptSharp do not support Blend... if (kind != BuildFrameworkKind.Portable && kind != BuildFrameworkKind.Compact && kind != BuildFrameworkKind.ScriptSharp) { string blendDir = groupContext["$BlendDataDir"]; if (!String.IsNullOrEmpty(blendDir) && Directory.Exists(blendDir)) { dataAvailable = true; writer.WriteStartElement("data"); // start - data writer.WriteAttributeString("base", blendDir); writer.WriteAttributeString("recurse", "true"); // Prevent warning, when the same namespace occurs in different // assemblies... writer.WriteAttributeString("warnOverride", "false"); writer.WriteAttributeString("files", "*.xml"); // Write the data source... BuildSpecialSdk latestBlendSdk = null; if (kind == BuildFrameworkKind.Silverlight) { latestBlendSdk = BuildSpecialSdks.LatestBlendSilverlightSdk; } else { latestBlendSdk = BuildSpecialSdks.LatestBlendWpfSdk; } Version latestVersion = (latestBlendSdk == null) ? null : latestBlendSdk.Version; if (latestVersion == null) { latestVersion = framework.Version; } this.WriteDataSource(writer, DataSourceType.Blend, blendDir, latestVersion, true, kind == BuildFrameworkKind.Silverlight); writer.WriteEndElement(); // end - data } } //IList<string> linkDirs = groupContext.LinkDirectories; //if (linkDirs != null && linkDirs.Count != 0) //{ // for (int i = 0; i < linkDirs.Count; i++) // { // writer.WriteStartElement("data"); // start - data // writer.WriteAttributeString("base", linkDirs[i]); // writer.WriteAttributeString("recurse", "true"); // // Prevent warning, when the same namespace occurs in different // // assemblies... // writer.WriteAttributeString("warnOverride", "false"); // writer.WriteAttributeString("files", "*.xml"); // writer.WriteEndElement(); // end - data // } //} writer.WriteStartElement("data"); // start - data writer.WriteAttributeString("files", String.Format(@".\{0}", groupContext["$ReflectionFile"])); writer.WriteEndElement(); // end - data writer.Close(); navigator.DeleteSelf(); }
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); }
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); }
/// <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); }