private static void ConfigureDotNetForFirstTimeUse( INuGetCacheSentinel nugetCacheSentinel, IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator) { using (PerfTrace.Current.CaptureTiming()) { var nugetPackagesArchiver = new NuGetPackagesArchiver(); var environmentProvider = new EnvironmentProvider(); var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true); var nugetCachePrimer = new NuGetCachePrimer( nugetPackagesArchiver, nugetCacheSentinel, cliFallbackFolderPathCalculator); var dotnetConfigurer = new DotnetFirstTimeUseConfigurer( nugetCachePrimer, nugetCacheSentinel, firstTimeUseNoticeSentinel, environmentProvider, Reporter.Output, cliFallbackFolderPathCalculator.CliFallbackFolderPath); dotnetConfigurer.Configure(); } }
public GivenANuGetCachePrimer() { var fileSystemMockBuilder = FileSystemMockBuilder.Create(); fileSystemMockBuilder.TemporaryFolder = TEMPORARY_FOLDER_PATH; fileSystemMockBuilder.AddFile(COMPRESSED_ARCHIVE_PATH); _fileSystemMock = fileSystemMockBuilder.Build(); _nugetPackagesArchiverMock = new Mock <INuGetPackagesArchiver>(); _nugetPackagesArchiverMock.Setup(n => n.NuGetPackagesArchive).Returns(COMPRESSED_ARCHIVE_PATH); _nugetCacheSentinel = new Mock <INuGetCacheSentinel>(); _nugetConfigMock = new Mock <INuGetConfig>(); _cliFallbackFolderPathCalculator = new CliFallbackFolderPathCalculator(); var nugetCachePrimer = new NuGetCachePrimer( _nugetPackagesArchiverMock.Object, _nugetCacheSentinel.Object, _nugetConfigMock.Object, _cliFallbackFolderPathCalculator, _fileSystemMock.File); nugetCachePrimer.PrimeCache(); }
internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null) { // CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA. var success = true; var command = string.Empty; var lastArg = 0; var cliFallbackFolderPathCalculator = new CliFallbackFolderPathCalculator(); using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel(cliFallbackFolderPathCalculator)) using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel = new FirstTimeUseNoticeSentinel(cliFallbackFolderPathCalculator)) { IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel; for (; lastArg < args.Length; lastArg++) { if (IsArg(args[lastArg], "d", "diagnostics")) { Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, bool.TrueString); CommandContext.SetVerbose(true); } else if (IsArg(args[lastArg], "version")) { PrintVersion(); return(0); } else if (IsArg(args[lastArg], "info")) { PrintInfo(); return(0); } else if (IsArg(args[lastArg], "h", "help") || args[lastArg] == "-?" || args[lastArg] == "/?") { HelpCommand.PrintHelp(); return(0); } else if (args[lastArg].StartsWith("-")) { Reporter.Error.WriteLine($"Unknown option: {args[lastArg]}"); success = false; } else { // It's the command, and we're done! command = args[lastArg]; if (IsDotnetBeingInvokedFromNativeInstaller(command)) { firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); } ConfigureDotNetForFirstTimeUse( nugetCacheSentinel, firstTimeUseNoticeSentinel, cliFallbackFolderPathCalculator); break; } } if (!success) { HelpCommand.PrintHelp(); return(1); } if (telemetryClient == null) { telemetryClient = new Telemetry.Telemetry(firstTimeUseNoticeSentinel); } TelemetryEventEntry.Subscribe(telemetryClient.TrackEvent); TelemetryEventEntry.TelemetryFilter = new TelemetryFilter(); } IEnumerable <string> appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty <string>() : args.Skip(lastArg + 1).ToArray(); if (CommandContext.IsVerbose()) { Console.WriteLine($"Telemetry is: {(telemetryClient.Enabled ? "Enabled" : "Disabled")}"); } if (string.IsNullOrEmpty(command)) { command = "help"; } TelemetryEventEntry.TrackEvent(command, null, null); int exitCode; if (BuiltInCommandsCatalog.Commands.TryGetValue(command, out var builtIn)) { TelemetryEventEntry.SendFiltered(Parser.Instance.ParseFrom($"dotnet {command}", appArgs.ToArray())); exitCode = builtIn.Command(appArgs.ToArray()); } else { CommandResult result = Command.Create( "dotnet-" + command, appArgs, FrameworkConstants.CommonFrameworks.NetStandardApp15) .Execute(); exitCode = result.ExitCode; } return(exitCode); }