internal override IServiceProvider TryGetServiceProvider(IConsole console) { // Gather all the values supplied by the user in command line SourceDir = string.IsNullOrEmpty(SourceDir) ? Directory.GetCurrentDirectory() : Path.GetFullPath(SourceDir); // NOTE: Order of the following is important. So a command line provided value has higher precedence // than the value provided in a configuration file of the repo. var config = new ConfigurationBuilder() .AddIniFile(Path.Combine(SourceDir, Constants.BuildEnvironmentFileName), optional: true) .AddEnvironmentVariables() .Build(); // Override the GetServiceProvider() call in CommandBase to pass the IConsole instance to // ServiceProviderBuilder and allow for writing to the console if needed during this command. var serviceProviderBuilder = new ServiceProviderBuilder(LogFilePath, console) .ConfigureServices(services => { // Configure Options related services // We first add IConfiguration to DI so that option services like // `DotNetCoreScriptGeneratorOptionsSetup` services can get it through DI and read from the config // and set the options. services .AddSingleton <IConfiguration>(config) .AddOptionsServices() .Configure <BuildScriptGeneratorOptions>(options => { // These values are not retrieve through the 'config' api since we do not expect // them to be provided by an end user. options.SourceDir = SourceDir; }); }); return(serviceProviderBuilder.Build()); }
internal virtual IServiceProvider GetServiceProvider() { var serviceProviderBuilder = new ServiceProviderBuilder(LogFilePath) .ConfigureScriptGenerationOptions(opts => ConfigureBuildScriptGeneratorOptions(opts)); return(serviceProviderBuilder.Build()); }
internal virtual IServiceProvider GetServiceProvider(IConsole console) { // Don't use the IConsole instance in this method -- override this method in the command // and pass IConsole through to ServiceProviderBuilder to write to the output. var serviceProviderBuilder = new ServiceProviderBuilder(LogFilePath) .ConfigureScriptGenerationOptions(opts => ConfigureBuildScriptGeneratorOptions(opts)); return(serviceProviderBuilder.Build()); }
internal virtual IServiceProvider TryGetServiceProvider(IConsole console) { // Don't use the IConsole instance in this method -- override this method in the command // and pass IConsole through to ServiceProviderBuilder to write to the output. var serviceProviderBuilder = new ServiceProviderBuilder(this.LogFilePath) .ConfigureServices(services => { // Add an empty and default configuration to prevent some commands from breaking since options // setup expect this from DI. var configuration = new ConfigurationBuilder().Build(); services.AddSingleton <IConfiguration>(configuration); }) .ConfigureScriptGenerationOptions(opts => this.ConfigureBuildScriptGeneratorOptions(opts)); return(serviceProviderBuilder.Build()); }
internal override IServiceProvider TryGetServiceProvider(IConsole console) { // NOTE: Order of the following is important. So a command line provided value has higher precedence // than the value provided in a configuration file of the repo. var config = new ConfigurationBuilder() .AddEnvironmentVariables() .Build(); // Override the GetServiceProvider() call in CommandBase to pass the IConsole instance to // ServiceProviderBuilder and allow for writing to the console if needed during this command. var serviceProviderBuilder = new ServiceProviderBuilder(LogFilePath, console) .ConfigureServices(services => { // Configure Options related services // We first add IConfiguration to DI so that option services like // `DotNetCoreScriptGeneratorOptionsSetup` services can get it through DI and read from the config // and set the options. services .AddSingleton <IConfiguration>(config) .AddOptionsServices(); }); return(serviceProviderBuilder.Build()); }
internal override IServiceProvider TryGetServiceProvider(IConsole console) { if (!IsValidInput(console)) { return(null); } // NOTE: Order of the following is important. So a command line provided value has higher precedence // than the value provided in a configuration file of the repo. var configBuilder = new ConfigurationBuilder(); if (string.IsNullOrEmpty(PlatformsAndVersionsFile)) { // Gather all the values supplied by the user in command line SourceDir = string.IsNullOrEmpty(SourceDir) ? Directory.GetCurrentDirectory() : Path.GetFullPath(SourceDir); configBuilder.AddIniFile(Path.Combine(SourceDir, Constants.BuildEnvironmentFileName), optional: true); } else { string versionsFilePath; if (PlatformsAndVersionsFile.StartsWith("/")) { versionsFilePath = Path.GetFullPath(PlatformsAndVersionsFile); } else { versionsFilePath = Path.Combine( Directory.GetCurrentDirectory(), Path.GetFullPath(PlatformsAndVersionsFile)); } if (!File.Exists(versionsFilePath)) { throw new FileNotFoundException( $"Could not find the file provided to the '{PlatformsAndVersionsFileTemplate}' switch.", versionsFilePath); } configBuilder.AddIniFile(versionsFilePath, optional: false); } configBuilder .AddEnvironmentVariables() .Add(GetCommandLineConfigSource()); var config = configBuilder.Build(); // Override the GetServiceProvider() call in CommandBase to pass the IConsole instance to // ServiceProviderBuilder and allow for writing to the console if needed during this command. var serviceProviderBuilder = new ServiceProviderBuilder(LogFilePath, console) .ConfigureServices(services => { // Configure Options related services // We first add IConfiguration to DI so that option services like // `DotNetCoreScriptGeneratorOptionsSetup` services can get it through DI and read from the config // and set the options. services .AddSingleton <IConfiguration>(config) .AddOptionsServices() .Configure <BuildScriptGeneratorOptions>(options => { // These values are not retrieve through the 'config' api since we do not expect // them to be provided by an end user. options.SourceDir = SourceDir; }); }); return(serviceProviderBuilder.Build()); }