private static ITemplateEngineHost CreateHost(string hostIdentifier, string hostVersion) { 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[] { typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Orchestrator.RunnableProjects typeof(NupkgInstallUnitDescriptorFactory).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Edge typeof(DotnetRestorePostActionProcessor).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Cli typeof(NupkgUpdater).GetTypeInfo().Assembly // for assembly: Microsoft.TemplateSearch.Common }); return(new DefaultTemplateEngineHost(hostIdentifier, hostVersion, CultureInfo.CurrentCulture.Name, preferences, builtIns, new[] { "dotnetcli" })); }
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); }
private static ITemplateEngineHost CreateHost() { 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[] { typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, typeof(ConditionalConfig).GetTypeInfo().Assembly, typeof(NupkgInstallUnitDescriptorFactory).GetTypeInfo().Assembly }); return new DefaultTemplateEngineHost(HostIdentifier, HostVersion, CultureInfo.CurrentCulture.Name, preferences, builtIns, new[] { "dotnetcli" }); }
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 ITemplateEngineHost CreateHost() { var preferences = new Dictionary <string, string> { { "prefs:language", "C#" } }; try { string versionString = GetCLIVersion(); if (!string.IsNullOrWhiteSpace(versionString)) { preferences["dotnet-cli-version"] = versionString.Trim(); } } catch { } var builtIns = new AssemblyComponentCatalog(new[] { typeof(Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IMacro).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Orchestrator.RunnableProjects typeof(Microsoft.TemplateEngine.Edge.AssemblyComponentCatalog).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Edge typeof(New3Command).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Cli typeof(Microsoft.TemplateSearch.Common.NuGetSearchCacheConfig).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateSearch.Common typeof(Program).GetTypeInfo().Assembly }); return(new DefaultTemplateEngineHost(HostIdentifier, HostVersion, preferences, builtIns, new[] { "dotnetcli" })); }
public void TestAllComponents() { var assemblyCatalog = new AssemblyComponentCatalog(new[] { typeof(Components).Assembly }); var expectedTypeNames = assemblyCatalog.Select(pair => pair.Item1.FullName + ";" + pair.Item2.GetType().FullName).OrderBy(name => name); var actualTypeNames = Components.AllComponents.Select(t => t.Type.FullName + ";" + t.Instance.GetType().FullName).OrderBy(name => name); Assert.Equal(expectedTypeNames, actualTypeNames); }
public void TestAllEdgeComponentsAdded() { var environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true, loadDefaultGenerator: false); var componentManager = new ComponentManager( new MockSettingsLoader(environmentSettings), new SettingsStore()); var assemblyCatalog = new AssemblyComponentCatalog(new[] { typeof(ComponentManager).Assembly }); var expectedTypeNames = assemblyCatalog.Select(pair => pair.Value().FullName).OrderBy(name => name); var actualTypeNames = componentManager.ComponentCache.Values.SelectMany(t => t.Values).Select(o => o.GetType().FullName).OrderBy(name => name); Assert.Equal(expectedTypeNames, actualTypeNames); Assert.Equal(2, componentManager.OfType <IInstallerFactory>().Count()); }
private static 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 }); return(new DefaultTemplateEngineHost(HostIdentifier + Guid.NewGuid().ToString(), HostVersion, CultureInfo.CurrentCulture.Name, preferences, builtIns, Array.Empty <string>())); }
private static ITemplateEngineHost CreateHost(string hostIdentifier, string hostVersion) { Dictionary <string, string> preferences = new Dictionary <string, string> { { "prefs:language", DefaultLanguage } }; AssemblyComponentCatalog builtIns = new AssemblyComponentCatalog(new[] { typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Orchestrator.RunnableProjects typeof(NupkgInstallUnitDescriptorFactory).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Edge typeof(DotnetRestorePostActionProcessor).GetTypeInfo().Assembly // for assembly: Microsoft.TemplateEngine.Cli }); return(new DefaultTemplateEngineHost(hostIdentifier, hostVersion, CultureInfo.CurrentCulture.Name, preferences, builtIns, new[] { "dotnetcli" })); }
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 ITemplateEngineHost CreateHost() { var builtIns = new AssemblyComponentCatalog(new[] { typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, typeof(ConditionalConfig).GetTypeInfo().Assembly, }); var preferences = new Dictionary <string, string> { { "prefs:language", "C#" }, { "dotnet-cli-version", Product.Version }, { "RuntimeFrameworkVersion", new Muxer().SharedFxVersion }, { "NetStandardImplicitPackageVersion", new FrameworkDependencyFile().GetNetStandardLibraryVersion() }, }; return(new DefaultTemplateEngineHost(HostIdentifier, "v" + Product.Version, CultureInfo.CurrentCulture.Name, preferences, builtIns)); }
private static ITemplateEngineHost CreateHost() { var builtIns = new AssemblyComponentCatalog(new[] { typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, typeof(ConditionalConfig).GetTypeInfo().Assembly, typeof(NupkgUpdater).GetTypeInfo().Assembly }); string preferredLangEnvVar = Environment.GetEnvironmentVariable("DOTNET_NEW_PREFERRED_LANG"); string preferredLang = string.IsNullOrWhiteSpace(preferredLangEnvVar)? "C#" : preferredLangEnvVar; var preferences = new Dictionary <string, string> { { "prefs:language", preferredLang }, { "dotnet-cli-version", Product.Version }, { "RuntimeFrameworkVersion", new Muxer().SharedFxVersion }, { "NetStandardImplicitPackageVersion", new FrameworkDependencyFile().GetNetStandardLibraryVersion() }, }; return(new DefaultTemplateEngineHost(HostIdentifier, "v" + Product.Version, CultureInfo.CurrentCulture.Name, preferences, builtIns)); }
private static ITemplateEngineHost CreateHost() { var builtIns = new AssemblyComponentCatalog(new[] { typeof(Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IMacro).Assembly, typeof(BuiltInTemplatePackageProviderFactory).Assembly, typeof(FileMetadataSearchSource).Assembly }); string preferredLangEnvVar = Environment.GetEnvironmentVariable("DOTNET_NEW_PREFERRED_LANG"); string preferredLang = string.IsNullOrWhiteSpace(preferredLangEnvVar)? "C#" : preferredLangEnvVar; var preferences = new Dictionary <string, string> { { "prefs:language", preferredLang }, { "dotnet-cli-version", Product.Version }, { "RuntimeFrameworkVersion", new Muxer().SharedFxVersion }, { "NetStandardImplicitPackageVersion", new FrameworkDependencyFile().GetNetStandardLibraryVersion() }, }; return(new DefaultTemplateEngineHost(HostIdentifier, "v" + Product.Version, preferences, builtIns)); }
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 { } var builtIns = new AssemblyComponentCatalog(new[] { typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, typeof(ConditionalConfig).GetTypeInfo().Assembly }); DefaultTemplateEngineHost host = new DefaultTemplateEngineHost(HostIdentifier, HostVersion, CultureInfo.CurrentCulture.Name, 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); }