private App(NuGetPackageInstaller packageInstaller, ILogger logger, HttpClient httpClient, bool disposeNested) { _packageInstaller = packageInstaller ?? throw new ArgumentNullException(nameof(packageInstaller)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _disposeNested = disposeNested; }
public AgentHostBackgroundService(IApplicationSettingsStore applicationSettingsStore, ILogger logger, NuGetPackageInstaller packageInstaller) { _applicationSettingsStore = applicationSettingsStore; _logger = logger; _packageInstaller = packageInstaller; }
public async Task GetAllPackageVersionsDefaultConfig() { var nuGetPackageInstaller = new NuGetPackageInstaller(); string?configFile = Path.Combine(VcsTestPathHelper.TryFindVcsRootPath(), "tests", "Arbor.Tooler.Tests.Integration", "DefaultConfig", "nuget.config"); var packageVersions = await nuGetPackageInstaller.GetAllVersions(new NuGetPackageId("Newtonsoft.Json"), nugetConfig : configFile); packageVersions.Should().NotBeEmpty(); }
public async Task GetAllPackageVersions() { var nuGetPackageInstaller = new NuGetPackageInstaller(); Directory.SetCurrentDirectory(VcsTestPathHelper.TryFindVcsRootPath()); var packageVersions = await nuGetPackageInstaller.GetAllVersions(new NuGetPackageId("Newtonsoft.Json")); packageVersions.Should().NotBeEmpty(); }
public async Task It_installs_nuget_package() { var packageId = "Humanizer"; var packageVersion = "2.6.2"; var logger = new NuGetTestLogger(); var installer = new NuGetPackageInstaller(Directory.GetCurrentDirectory(), logger); var packagePath = await installer.InstallPackageAsync(new PackageId(packageId), new NuGetVersion(packageVersion)); logger.Errors.Should().Be(0); logger.Warnings.Should().Be(0); packagePath.Should().ContainEquivalentOf(packageId); packagePath.Should().Contain(packageVersion); File.Exists(packagePath).Should().BeTrue(); }
public PackageService( [NotNull] NuGetListConfiguration deploymentConfiguration, [NotNull] IKeyValueConfiguration keyValueConfiguration, [NotNull] ILogger logger, [NotNull] NuGetConfiguration nuGetConfiguration, [NotNull] NuGetPackageInstaller packageInstaller) { _deploymentConfiguration = deploymentConfiguration ?? throw new ArgumentNullException(nameof(deploymentConfiguration)); _keyValueConfiguration = keyValueConfiguration ?? throw new ArgumentNullException(nameof(keyValueConfiguration)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _nuGetConfiguration = nuGetConfiguration ?? throw new ArgumentNullException(nameof(nuGetConfiguration)); _packageInstaller = packageInstaller ?? throw new ArgumentNullException(nameof(packageInstaller)); }
public async Task CreateMultiPlatformProjectFromTemplateWithPCLOnly() { string templateId = "MonoDevelop.Packaging.CrossPlatformLibrary"; var template = ProjectTemplate.ProjectTemplates.FirstOrDefault(t => t.Id == templateId); var dir = Util.CreateTmpDir(template.Id); var cinfo = new ProjectCreateInformation { ProjectBasePath = dir, ProjectName = "ProjectName", SolutionName = "SolutionName", SolutionPath = dir }; cinfo.Parameters["ProjectName"] = cinfo.ProjectName; cinfo.Parameters["CreatePortableProject"] = bool.TrueString; cinfo.Parameters["PackageAuthors"] = "authors"; cinfo.Parameters["PackageId"] = "ProjectName"; cinfo.Parameters["PackageDescription"] = "Description"; cinfo.Parameters["PackageVersion"] = "1.0.0"; var workspaceItem = template.CreateWorkspaceItem(cinfo); var wizard = new TestableCrossPlatformLibraryTemplateWizard(); wizard.Parameters = cinfo.Parameters; wizard.ItemsCreated(new [] { workspaceItem }); var project = ((Solution)workspaceItem).GetAllProjects().First(); project.MSBuildProject.GetGlobalPropertyGroup().SetValue("PackOnBuild", "true"); string solutionFileName = Path.Combine(dir, "SolutionName.sln"); await workspaceItem.SaveAsync(solutionFileName, Util.GetMonitor()); await NuGetPackageInstaller.InstallPackages((Solution)workspaceItem, template.PackageReferencesForCreatedProjects); var solution = (Solution)await Ide.Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solutionFileName); project = solution.GetAllProjects().First(); BuildResult cr = await solution.Build(Util.GetMonitor(), "Debug"); Assert.IsNotNull(cr); Assert.AreEqual(0, cr.ErrorCount); Assert.AreEqual(0, cr.WarningCount); string packageFileName = Path.Combine(dir, "bin", "Debug", "ProjectName.1.0.0.nupkg"); bool packageCreated = File.Exists(packageFileName); Assert.IsTrue(packageCreated, "NuGet package not created."); }
public void Dispose() { if (_disposeNested) { _packageInstaller = null; _httpClient?.Dispose(); _httpClient = null; if (_logger is IDisposable disposable) { disposable.Dispose(); } _logger = null; } }
public static Task <App> CreateAsync( string[] args, ILogger logger = default, HttpClient httpClient = default, bool disposeNested = true, CancellationToken cancellationToken = default) { if (args == null) { throw new ArgumentNullException(nameof(args)); } var appArgs = args.ToImmutableArray(); if (logger is null) { var loggerConfiguration = new LoggerConfiguration().WriteTo.Console(); string correlationId = GetCorrelationId(appArgs); if (!string.IsNullOrWhiteSpace(correlationId)) { loggerConfiguration.Enrich.WithProperty("CorrelationId", correlationId); } logger = loggerConfiguration.CreateLogger(); } string nugetSource = GetNuGetSource(appArgs); string nugetConfig = GetNuGetConfig(appArgs); string nugetExePath = GetNuGetExePath(appArgs); httpClient ??= new HttpClient(); var nuGetDownloadClient = new NuGetDownloadClient(); var nuGetCliSettings = new NuGetCliSettings(nugetSource, nugetConfig, nugetExePath); var nuGetDownloadSettings = new NuGetDownloadSettings(); var nuGetPackageInstaller = new NuGetPackageInstaller( nuGetDownloadClient, nuGetCliSettings, nuGetDownloadSettings, logger); return(Task.FromResult(new App(nuGetPackageInstaller, logger, httpClient, disposeNested))); }
public async Task It_extracts_nuget_package() { var packageId = "Newtonsoft.Json"; var packageVersion = "12.0.3"; var logger = new NuGetTestLogger(); var installer = new NuGetPackageInstaller(Directory.GetCurrentDirectory(), logger); var packagePath = await installer.InstallPackageAsync(new PackageId(packageId), new NuGetVersion(packageVersion)); var targetPath = Path.Combine(Directory.GetCurrentDirectory(), "ExtractedPackage"); var result = await installer.ExtractPackageAsync(packagePath, targetPath); var resultPath = Path.Combine(targetPath, $"{packageId}.{packageVersion}"); Directory.Exists(resultPath).Should().BeTrue(); var extractedFiles = Directory.GetFiles(resultPath, "*", SearchOption.AllDirectories); extractedFiles.Should().Contain(Path.Combine(resultPath, $"{packageId}.nuspec")); extractedFiles.Should().BeEquivalentTo(result); }
public async Task BuildPackagingProjectFromTemplate() { string templateId = "MonoDevelop.Packaging.Project"; var template = ProjectTemplate.ProjectTemplates.FirstOrDefault(t => t.Id == templateId); var dir = Util.CreateTmpDir(template.Id); var cinfo = new ProjectCreateInformation { ProjectBasePath = dir, ProjectName = "ProjectName", SolutionName = "SolutionName", SolutionPath = dir }; cinfo.Parameters["PackageAuthors"] = "authors"; cinfo.Parameters["PackageId"] = "ProjectName"; cinfo.Parameters["PackageDescription"] = "Description"; cinfo.Parameters["PackageVersion"] = "1.0.0"; var workspaceItem = await template.CreateWorkspaceItem(cinfo); string solutionFileName = Path.Combine(dir, "SolutionName.sln"); await workspaceItem.SaveAsync(solutionFileName, Util.GetMonitor()); await NuGetPackageInstaller.InstallPackages((Solution)workspaceItem, template.PackageReferencesForCreatedProjects); var solution = (Solution)await Ide.Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solutionFileName); // Ensure readme.txt has metadata to include it in the NuGet package. var wizard = new TestablePackagingProjectTemplateWizard(); wizard.ItemsCreated(new [] { solution }); BuildResult cr = await solution.Build(Util.GetMonitor(), "Debug"); Assert.IsNotNull(cr); Assert.AreEqual(0, cr.ErrorCount); Assert.AreEqual(0, cr.WarningCount); string packageFileName = Path.Combine(dir, "bin", "Debug", "ProjectName.1.0.0.nupkg"); bool packageCreated = File.Exists(packageFileName); Assert.IsTrue(packageCreated, "NuGet package not created."); }
public DeploymentService( DeployerConfiguration deployerConfiguration, ILogger logger, [NotNull] IKeyValueConfiguration keyValueConfiguration, IWebDeployHelper webDeployHelper, Func <DeploymentExecutionDefinition, IIisManager> iisManager, NuGetPackageInstaller nugetPackageInstaller, IFtpHandlerFactory ftpHandlerFactor) { if (logger is null) { throw new ArgumentNullException(nameof(logger)); } if (keyValueConfiguration is null) { throw new ArgumentNullException(nameof(keyValueConfiguration)); } DeployerConfiguration = deployerConfiguration ?? throw new ArgumentNullException(nameof(deployerConfiguration)); _directoryCleaner = new DirectoryCleaner(logger); _packageInstaller = new PackageInstaller(logger, deployerConfiguration, keyValueConfiguration); _fileMatcher = new FileMatcher(logger); _xmlTransformer = new XmlTransformer(logger, _fileMatcher); _logger = logger; _webDeployHelper = webDeployHelper; _iisManager = iisManager; _nugetPackageInstaller = nugetPackageInstaller; _ftpHandlerFactory = ftpHandlerFactor; }
public static async Task <DeployerApp> BuildAppAsync([NotNull] string[] inputArgs, ILogger?logger = null, CancellationToken cancellationToken = default) { if (inputArgs is null) { throw new ArgumentNullException(nameof(inputArgs)); } var args = inputArgs.ToImmutableArray(); bool hasDefinedLogger = logger is {}; string outputTemplate = GetOutputTemplate(args); var levelSwitch = new LoggingLevelSwitch(); logger ??= new LoggerConfiguration() .WriteTo.Console(outputTemplate: outputTemplate, standardErrorFromLevel: LogEventLevel.Error) .MinimumLevel.ControlledBy(levelSwitch) .CreateLogger(); logger.Verbose("Using output template {Template}", outputTemplate); try { string?machineSettings = GetMachineSettingsFile(new DirectoryInfo(Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "tools", "Milou.Deployer"))); AppSettingsBuilder appSettingsBuilder; try { appSettingsBuilder = KeyValueConfigurationManager .Add(new ReflectionKeyValueConfiguration(typeof(AppBuilder).Assembly)) .Add(new ReflectionKeyValueConfiguration(typeof(ConfigurationKeys).Assembly)); } catch (Exception ex) when(!ex.IsFatal()) { logger.Error(ex, "Could note create settings"); throw; } if (!string.IsNullOrWhiteSpace(machineSettings)) { logger.Information("Using machine specific configuration file '{Settings}'", machineSettings); appSettingsBuilder = appSettingsBuilder.Add(new JsonKeyValueConfiguration(machineSettings, false)); } string?configurationFile = Environment.GetEnvironmentVariable(ConfigurationKeys.KeyValueConfigurationFile); if (!string.IsNullOrWhiteSpace(configurationFile) && File.Exists(configurationFile)) { logger.Information("Using configuration values from file '{ConfigurationFile}'", configurationFile); appSettingsBuilder = appSettingsBuilder.Add(new JsonKeyValueConfiguration(configurationFile, false)); } var argsAsParameters = args .Where(arg => arg.StartsWith("-", StringComparison.OrdinalIgnoreCase)) .Select(arg => arg.TrimStart('-')) .ToImmutableArray(); MultiSourceKeyValueConfiguration configuration = appSettingsBuilder .Add(new EnvironmentVariableKeyValueConfigurationSource()) .AddCommandLineArgsSettings(argsAsParameters) .Add(new UserJsonConfiguration()) .Build(); logger.Debug("Using configuration: {Configuration}", configuration.SourceChain); string logPath = configuration[ConsoleConfigurationKeys.LoggingFilePath]; string environmentLogLevel = configuration[ConfigurationKeys.LogLevelEnvironmentVariable]; string configurationLogLevel = configuration[ConfigurationKeys.LogLevel]; var logLevel = Arbor.App.Extensions.Logging.LogEventLevelExtensions.ParseOrDefault( environmentLogLevel.WithDefault(configurationLogLevel)); levelSwitch.MinimumLevel = logLevel; LoggerConfiguration loggerConfiguration = new LoggerConfiguration() .WriteTo.Console(outputTemplate: outputTemplate); if (!string.IsNullOrWhiteSpace(logPath)) { loggerConfiguration = loggerConfiguration.WriteTo.File(logPath); } if (!hasDefinedLogger) { if (logger is IDisposable disposable) { disposable.Dispose(); } logger = loggerConfiguration .MinimumLevel.ControlledBy(levelSwitch) .CreateLogger(); } if (!string.IsNullOrWhiteSpace(machineSettings)) { logger.Information("Using machine specific configuration file '{Settings}'", machineSettings); } string?nugetSource = args.GetArgumentValueOrDefault("nuget-source"); string?nugetConfig = args.GetArgumentValueOrDefault("nuget-config"); var webDeployConfig = new WebDeployConfig(new WebDeployRulesConfig( true, true, false, true, true)); bool allowPreReleaseEnabled = configuration[ConfigurationKeys.AllowPreReleaseEnvironmentVariable] .ParseAsBooleanOrDefault() || (Debugger.IsAttached && configuration[ConfigurationKeys.ForceAllowPreRelease] .ParseAsBooleanOrDefault()); string?nuGetExePath = configuration[ConfigurationKeys.NuGetExePath]; if (string.IsNullOrWhiteSpace(nuGetExePath)) { logger.Debug("nuget.exe is not specified, downloading with {Tool}", nameof(NuGetDownloadClient)); using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30))) { var nuGetDownloadClient = new NuGetDownloadClient(); NuGetDownloadResult nuGetDownloadResult; using (var httpClient = new HttpClient()) { nuGetDownloadResult = await nuGetDownloadClient .DownloadNuGetAsync(NuGetDownloadSettings.Default, logger, httpClient, cts.Token) .ConfigureAwait(false); } if (!nuGetDownloadResult.Succeeded) { throw new InvalidOperationException( Resources.NuGetExeCouldNotBeDownloaded); } nuGetExePath = nuGetDownloadResult.NuGetExePath; } logger.Debug("Successfully downloaded nuget.exe to '{DownloadedPath}'", nuGetExePath); } var deployerConfiguration = new DeployerConfiguration(webDeployConfig) { NuGetExePath = nuGetExePath, NuGetConfig = nugetConfig.WithDefault(configuration[ConfigurationKeys.NuGetConfig]), NuGetSource = nugetSource.WithDefault(configuration[ConfigurationKeys.NuGetSource]), AllowPreReleaseEnabled = allowPreReleaseEnabled, StopStartIisWebSiteEnabled = configuration[ConfigurationKeys.StopStartIisWebSiteEnabled] .ParseAsBooleanOrDefault(true) }; var nuGetCliSettings = new NuGetCliSettings( deployerConfiguration.NuGetSource, nuGetExePath: deployerConfiguration.NuGetExePath, nugetConfigFile: deployerConfiguration.NuGetConfig); var nuGetPackageInstaller = new NuGetPackageInstaller(logger: logger, nugetCliSettings: nuGetCliSettings); var deploymentService = new DeploymentService( deployerConfiguration, logger, configuration, new WebDeployHelper(logger), deploymentExecutionDefinition => IisManager.Create(deployerConfiguration, logger, deploymentExecutionDefinition), nuGetPackageInstaller, new FtpHandlerFactory()); string temp = configuration[ConfigurationKeys.TempDirectory]; const string tempEnvironmentVariableName = "temp"; if (!string.IsNullOrWhiteSpace(temp) && Directory.Exists(temp)) { Environment.SetEnvironmentVariable(tempEnvironmentVariableName, temp); Environment.SetEnvironmentVariable("tmp", temp); } var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); return(new DeployerApp(logger, deploymentService, configuration, levelSwitch, cancellationTokenSource)); } catch (Exception ex) when(!ex.IsFatal()) { logger.Error("Could not build application"); throw; } }