internal static DefaultTemplateEngineHost CreateHost(string hostIdentifier, string?hostVersion = null, Dictionary <string, string>?preferences = null) { if (string.IsNullOrEmpty(hostIdentifier)) { throw new ArgumentException("hostIdentifier cannot be null"); } if (string.IsNullOrEmpty(hostVersion)) { hostVersion = DefaultHostVersion; } if (preferences == null) { preferences = DefaultPreferences; } var builtIns = new List <(Type, IIdentifiedComponent)>(); builtIns.AddRange(TemplateEngine.Edge.Components.AllComponents); builtIns.AddRange(TemplateEngine.Orchestrator.RunnableProjects.Components.AllComponents); // use "dotnetcli" as a fallback host so the correct host specific files are read. DefaultTemplateEngineHost host = new DefaultTemplateEngineHost(hostIdentifier, hostVersion, preferences, builtIns, new[] { "dotnetcli" }); return(host); }
public static DefaultTemplateEngineHost CreateHost(string hostIdentifier, string hostVersion = null, Dictionary <string, string> preferences = null) { if (string.IsNullOrEmpty(hostIdentifier)) { throw new Exception("hostIdentifier cannot be null"); } if (string.IsNullOrEmpty(hostVersion)) { hostVersion = DefaultHostVersion; } if (preferences == null) { preferences = DefaultPreferences; } var builtIns = new AssemblyComponentCatalog(new[] { typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, // RPG typeof(NupkgInstallUnitDescriptorFactory).GetTypeInfo().Assembly, // edge }); // use "dotnetcli" as a fallback host so the correct host specific files are read. DefaultTemplateEngineHost host = new DefaultTemplateEngineHost(hostIdentifier, hostVersion, CultureInfo.CurrentCulture.Name, preferences, builtIns, new[] { "dotnetcli" }); return(host); }
public static int Main(string[] args) { bool emitTimings = args.Any(x => string.Equals(x, "--debug:emit-timings", StringComparison.OrdinalIgnoreCase)); bool debugTelemetry = args.Any(x => string.Equals(x, "--debug:emit-telemetry", StringComparison.OrdinalIgnoreCase)); bool disableSdkTemplates = args.Any(x => string.Equals(x, "--debug:disable-sdk-templates", StringComparison.OrdinalIgnoreCase)); DefaultTemplateEngineHost host = CreateHost(emitTimings, disableSdkTemplates); bool debugAuthoring = args.Any(x => string.Equals(x, "--trace:authoring", StringComparison.OrdinalIgnoreCase)); bool debugInstall = args.Any(x => string.Equals(x, "--trace:install", StringComparison.OrdinalIgnoreCase)); if (debugAuthoring) { AddAuthoringLogger(host); AddInstallLogger(host); } else if (debugInstall) { AddInstallLogger(host); } var callbacks = new New3Callbacks(); return(New3Command.Run(CommandName, host, new TelemetryLogger(null, debugTelemetry), callbacks, args)); }
private static ITemplateEngineHost CreateHost(bool emitTimings) { var preferences = new Dictionary <string, string> { { "prefs:language", "C#" } }; try { string versionString = Dotnet.Version().CaptureStdOut().Execute().StdOut; if (!string.IsNullOrWhiteSpace(versionString)) { preferences["dotnet-cli-version"] = versionString.Trim(); } } catch { } DefaultTemplateEngineHost host = new DefaultTemplateEngineHost(HostIdentifier, HostVersion, CultureInfo.CurrentCulture.Name, preferences, new[] { "dotnetcli" }); if (emitTimings) { host.OnLogTiming = (label, duration, depth) => { string indent = string.Join("", Enumerable.Repeat(" ", depth)); Console.WriteLine($"{indent} {label} {duration.TotalMilliseconds}"); }; } return(host); }
public static DefaultTemplateEngineHost CreateHost(string hostIdentifier, string?hostVersion = null, Dictionary <string, string>?preferences = null) { if (string.IsNullOrEmpty(hostIdentifier)) { throw new ArgumentException("hostIdentifier cannot be null"); } if (string.IsNullOrEmpty(hostVersion)) { hostVersion = DefaultHostVersion; } if (preferences == null) { preferences = DefaultPreferences; } var builtIns = new AssemblyComponentCatalog(new[] { typeof(Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IMacro).GetTypeInfo().Assembly, // RPG typeof(Microsoft.TemplateEngine.Edge.Template.TemplateCreator).GetTypeInfo().Assembly, // edge }); // use "dotnetcli" as a fallback host so the correct host specific files are read. DefaultTemplateEngineHost host = new DefaultTemplateEngineHost(hostIdentifier, hostVersion, preferences, builtIns, new[] { "dotnetcli" }); return(host); }
private static void AddAuthoringLogger(DefaultTemplateEngineHost host) { Action <string, string[]> authoringLogger = (message, additionalInfo) => { Console.WriteLine(string.Format("Authoring: {0}", message)); }; host.RegisterDiagnosticLogger("Authoring", authoringLogger); }
public static DefaultTemplateEngineHost CreateHost(string hostIdentifier) { if (string.IsNullOrEmpty(hostIdentifier)) { throw new ArgumentException("hostIdentifier cannot be null"); } // use "dotnetcli" as a fallback host so the correct host specific files are read. DefaultTemplateEngineHost host = new DefaultTemplateEngineHost(hostIdentifier, DefaultHostVersion, DefaultPreferences, null, new[] { "dotnetcli" }); return(host); }
internal async Task PhysicalConfigurationTest() { var userProfileDir = Environment.GetEnvironmentVariable(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "USERPROFILE" : "HOME"); var hostDir = Path.Combine(userProfileDir, ".templateengine", nameof(PhysicalConfigurationTest).ToString()); try { var builtIns = BuiltInTemplatePackagesProviderFactory.GetComponents(includeTestTemplates: false); var host = new DefaultTemplateEngineHost(nameof(PhysicalConfigurationTest).ToString(), "1.0.0", null, builtIns, Array.Empty <string>()); Bootstrapper bootstrapper = new Bootstrapper(host, virtualizeConfiguration: false, loadDefaultComponents: true); var result = await bootstrapper.GetTemplatesAsync(cancellationToken : default).ConfigureAwait(false);
private ITemplateEngineHost CreateHost() { var preferences = new Dictionary <string, string> { { "prefs:language", "C#" } }; var builtIns = new AssemblyComponentCatalog(new[] { typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Orchestrator.RunnableProjects typeof(AssemblyComponentCatalog).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Edge }); ITemplateEngineHost host = new DefaultTemplateEngineHost(HostIdentifier, HostVersion, CultureInfo.CurrentCulture.Name, preferences, builtIns, null); return(host); }
private static DefaultTemplateEngineHost CreateHost(bool emitTimings) { var preferences = new Dictionary <string, string> { { "prefs:language", "C#" } }; try { string versionString = Dotnet.Version().CaptureStdOut().Execute().StdOut; if (!string.IsNullOrWhiteSpace(versionString)) { preferences["dotnet-cli-version"] = versionString.Trim(); } } catch { } var builtIns = new AssemblyComponentCatalog(new[] { // for assembly: Microsoft.TemplateEngine.Orchestrator.RunnableProjects typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Edge typeof(NupkgInstallUnitDescriptorFactory).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Cli typeof(DotnetRestorePostActionProcessor).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateSearch.Common typeof(NupkgUpdater).GetTypeInfo().Assembly }); ConfigureLocale(); DefaultTemplateEngineHost host = new DefaultTemplateEngineHost(HostIdentifier, HostVersion, preferences, builtIns, new[] { "dotnetcli" }); if (emitTimings) { host.OnLogTiming = (label, duration, depth) => { string indent = string.Join("", Enumerable.Repeat(" ", depth)); Console.WriteLine($"{indent} {label} {duration.TotalMilliseconds}"); }; } return(host); }
private static DefaultTemplateEngineHost CreateHost(bool emitTimings, bool disableSdkTemplates) { var preferences = new Dictionary <string, string> { { "prefs:language", "C#" } }; try { string?versionString = GetCLIVersion(); if (!string.IsNullOrWhiteSpace(versionString)) { preferences["dotnet-cli-version"] = versionString.Trim(); } } catch { } // Keep this in sync with dotnet/sdk repo var builtIns = new List <KeyValuePair <Guid, Func <Type> > >(new AssemblyComponentCatalog(new[] { typeof(Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IMacro).GetTypeInfo().Assembly })); if (!disableSdkTemplates) { builtIns.Add(new KeyValuePair <Guid, Func <Type> >(BuiltInTemplatePackagesProviderFactory.FactoryId, () => typeof(BuiltInTemplatePackagesProviderFactory))); } ConfigureLocale(); DefaultTemplateEngineHost host = new DefaultTemplateEngineHost(HostIdentifier, HostVersion, preferences, builtIns, new[] { V }); if (emitTimings) { host.OnLogTiming = (label, duration, depth) => { string indent = string.Join("", Enumerable.Repeat(" ", depth)); Console.WriteLine($"{indent} {label} {duration.TotalMilliseconds}"); }; } return(host); }
internal static DefaultTemplateEngineHost CreateHost(bool disableSdkTemplates) { var preferences = new Dictionary <string, string> { { "prefs:language", "C#" } }; try { string?versionString = GetCLIVersion(); if (!string.IsNullOrWhiteSpace(versionString)) { preferences["dotnet-cli-version"] = versionString.Trim(); } } catch { } // Keep this in sync with dotnet/sdk repo var builtIns = new List <(Type, IIdentifiedComponent)>(); builtIns.AddRange(Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Components.AllComponents); builtIns.AddRange(Microsoft.TemplateEngine.Edge.Components.AllComponents); builtIns.AddRange(Microsoft.TemplateEngine.Cli.Components.AllComponents); builtIns.AddRange(Microsoft.TemplateSearch.Common.Components.AllComponents); if (!disableSdkTemplates) { builtIns.Add((typeof(ITemplatePackageProviderFactory), new BuiltInTemplatePackagesProviderFactory())); } ConfigureLocale(); DefaultTemplateEngineHost host = new DefaultTemplateEngineHost( HostIdentifier, HostVersion, preferences, builtIns, new[] { "dotnetcli" }); return(host); }