internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry telemetryClient = null) { Dictionary <string, double> performanceData = new Dictionary <string, double>(); PerformanceLogEventSource.Log.BuiltInCommandParserStart(); Stopwatch parseStartTime = Stopwatch.StartNew(); var parseResult = Parser.Instance.Parse(args); // Avoid create temp directory with root permission and later prevent access in non sudo // This method need to be run very early before temp folder get created // https://github.com/dotnet/sdk/issues/20195 SudoEnvironmentDirectoryOverride.OverrideEnvironmentVariableToTmp(parseResult); performanceData.Add("Parse Time", parseStartTime.Elapsed.TotalMilliseconds); PerformanceLogEventSource.Log.BuiltInCommandParserStop(); using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel = new FirstTimeUseNoticeSentinel()) { IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel; IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel(); IFileSentinel toolPathSentinel = new FileSentinel( new FilePath( Path.Combine( CliFolderPathCalculator.DotnetUserProfileFolderPath, ToolPathSentinelFileName))); if (parseResult.GetValueForOption(Parser.DiagOption) && parseResult.IsDotnetBuiltInCommand()) { Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, bool.TrueString); CommandContext.SetVerbose(true); Reporter.Reset(); } if (parseResult.HasOption(Parser.VersionOption) && parseResult.IsTopLevelDotnetCommand()) { CommandLineInfo.PrintVersion(); return(0); } else if (parseResult.HasOption(Parser.InfoOption) && parseResult.IsTopLevelDotnetCommand()) { CommandLineInfo.PrintInfo(); return(0); } else { PerformanceLogEventSource.Log.FirstTimeConfigurationStart(); var environmentProvider = new EnvironmentProvider(); bool generateAspNetCertificate = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", defaultValue: true); bool telemetryOptout = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", defaultValue: false); bool addGlobalToolsToPath = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true); bool nologo = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_NOLOGO", defaultValue: false); ReportDotnetHomeUsage(environmentProvider); var isDotnetBeingInvokedFromNativeInstaller = false; if (parseResult.CommandResult.Command.Name.Equals(Parser.InstallSuccessCommand.Name)) { aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel(); firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); toolPathSentinel = new NoOpFileSentinel(exists: false); isDotnetBeingInvokedFromNativeInstaller = true; } var dotnetFirstRunConfiguration = new DotnetFirstRunConfiguration( generateAspNetCertificate: generateAspNetCertificate, telemetryOptout: telemetryOptout, addGlobalToolsToPath: addGlobalToolsToPath, nologo: nologo); ConfigureDotNetForFirstTimeUse( firstTimeUseNoticeSentinel, aspNetCertificateSentinel, toolPathSentinel, isDotnetBeingInvokedFromNativeInstaller, dotnetFirstRunConfiguration, environmentProvider, performanceData); PerformanceLogEventSource.Log.FirstTimeConfigurationStop(); } PerformanceLogEventSource.Log.TelemetryRegistrationStart(); if (telemetryClient == null) { telemetryClient = new Telemetry.Telemetry(firstTimeUseNoticeSentinel); } TelemetryEventEntry.Subscribe(telemetryClient.TrackEvent); TelemetryEventEntry.TelemetryFilter = new TelemetryFilter(Sha256Hasher.HashWithNormalizedCasing); PerformanceLogEventSource.Log.TelemetryRegistrationStop(); } if (CommandContext.IsVerbose()) { Console.WriteLine($"Telemetry is: {(telemetryClient.Enabled ? "Enabled" : "Disabled")}"); } PerformanceLogEventSource.Log.TelemetrySaveIfEnabledStart(); performanceData.Add("Startup Time", startupTime.TotalMilliseconds); TelemetryEventEntry.SendFiltered(Tuple.Create(parseResult, performanceData)); PerformanceLogEventSource.Log.TelemetrySaveIfEnabledStop(); int exitCode; if (parseResult.CanBeInvoked()) { PerformanceLogEventSource.Log.BuiltInCommandStart(); exitCode = parseResult.Invoke(); PerformanceLogEventSource.Log.BuiltInCommandStop(); } else { PerformanceLogEventSource.Log.ExtensibleCommandResolverStart(); var resolvedCommand = CommandFactoryUsingResolver.Create( "dotnet-" + parseResult.GetValueForArgument(Parser.DotnetSubCommand), args.GetSubArguments(), FrameworkConstants.CommonFrameworks.NetStandardApp15); PerformanceLogEventSource.Log.ExtensibleCommandResolverStop(); PerformanceLogEventSource.Log.ExtensibleCommandStart(); var result = resolvedCommand.Execute(); PerformanceLogEventSource.Log.ExtensibleCommandStop(); exitCode = result.ExitCode; } PerformanceLogEventSource.Log.TelemetryClientFlushStart(); telemetryClient.Flush(); PerformanceLogEventSource.Log.TelemetryClientFlushStop(); return(exitCode); }
internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry telemetryClient = null) { Dictionary <string, double> performanceData = new Dictionary <string, double>(); PerformanceLogEventSource.Log.BuiltInCommandParserStart(); Stopwatch parseStartTime = Stopwatch.StartNew(); var parseResult = Parser.Instance.Parse(args); performanceData.Add("Parse Time", parseStartTime.Elapsed.TotalMilliseconds); PerformanceLogEventSource.Log.BuiltInCommandParserStop(); using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel = new FirstTimeUseNoticeSentinel()) { IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel; IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel(); IFileSentinel toolPathSentinel = new FileSentinel( new FilePath( Path.Combine( CliFolderPathCalculator.DotnetUserProfileFolderPath, ToolPathSentinelFileName))); if (parseResult.ValueForOption <bool>(Parser.DiagOption) && parseResult.IsDotnetBuiltInCommand()) { Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, bool.TrueString); CommandContext.SetVerbose(true); Reporter.Reset(); } if (parseResult.HasOption(Parser.VersionOption) && parseResult.IsTopLevelDotnetCommand()) { CommandLineInfo.PrintVersion(); return(0); } else if (parseResult.HasOption(Parser.InfoOption) && parseResult.IsTopLevelDotnetCommand()) { CommandLineInfo.PrintInfo(); return(0); } else if (parseResult.HasOption("-h") && parseResult.IsTopLevelDotnetCommand()) { HelpCommand.PrintHelp(); return(0); } else if (parseResult.Directives.Count() > 0) { return(parseResult.Invoke()); } else { PerformanceLogEventSource.Log.FirstTimeConfigurationStart(); var environmentProvider = new EnvironmentProvider(); bool generateAspNetCertificate = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", defaultValue: true); bool telemetryOptout = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", defaultValue: false); bool addGlobalToolsToPath = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true); bool nologo = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_NOLOGO", defaultValue: false); ReportDotnetHomeUsage(environmentProvider); var isDotnetBeingInvokedFromNativeInstaller = false; if (parseResult.CommandResult.Command.Name.Equals(Parser.InstallSuccessCommand.Name)) { aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel(); firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); toolPathSentinel = new NoOpFileSentinel(exists: false); isDotnetBeingInvokedFromNativeInstaller = true; } var dotnetFirstRunConfiguration = new DotnetFirstRunConfiguration( generateAspNetCertificate: generateAspNetCertificate, telemetryOptout: telemetryOptout, addGlobalToolsToPath: addGlobalToolsToPath, nologo: nologo); ConfigureDotNetForFirstTimeUse( firstTimeUseNoticeSentinel, aspNetCertificateSentinel, toolPathSentinel, isDotnetBeingInvokedFromNativeInstaller, dotnetFirstRunConfiguration, environmentProvider, performanceData); PerformanceLogEventSource.Log.FirstTimeConfigurationStop(); } PerformanceLogEventSource.Log.TelemetryRegistrationStart(); if (telemetryClient == null) { telemetryClient = new Telemetry.Telemetry(firstTimeUseNoticeSentinel); } TelemetryEventEntry.Subscribe(telemetryClient.TrackEvent); TelemetryEventEntry.TelemetryFilter = new TelemetryFilter(Sha256Hasher.HashWithNormalizedCasing); PerformanceLogEventSource.Log.TelemetryRegistrationStop(); } if (CommandContext.IsVerbose()) { Console.WriteLine($"Telemetry is: {(telemetryClient.Enabled ? "Enabled" : "Disabled")}"); } PerformanceLogEventSource.Log.TelemetrySaveIfEnabledStart(); performanceData.Add("Startup Time", startupTime.TotalMilliseconds); TelemetryEventEntry.SendFiltered(Tuple.Create(parseResult, performanceData)); PerformanceLogEventSource.Log.TelemetrySaveIfEnabledStop(); var topLevelCommands = new string[] { "dotnet", parseResult.RootSubCommandResult() }.Concat(Parser.DiagOption.Aliases); int exitCode; if (parseResult.CommandResult.Command.Name.Equals("dotnet") && string.IsNullOrEmpty(parseResult.ValueForArgument <string>(Parser.DotnetSubCommand))) { exitCode = 0; } else if (BuiltInCommandsCatalog.Commands.TryGetValue(parseResult.RootSubCommandResult(), out var builtIn)) { PerformanceLogEventSource.Log.BuiltInCommandStart(); exitCode = builtIn.Command(args.Where(t => !topLevelCommands.Contains(t)).ToArray()); PerformanceLogEventSource.Log.BuiltInCommandStop(); } else { PerformanceLogEventSource.Log.ExtensibleCommandResolverStart(); var resolvedCommand = CommandFactoryUsingResolver.Create( "dotnet-" + parseResult.ValueForArgument <string>(Parser.DotnetSubCommand), args.Where(t => !topLevelCommands.Contains(t)).ToArray(), FrameworkConstants.CommonFrameworks.NetStandardApp15); PerformanceLogEventSource.Log.ExtensibleCommandResolverStop(); PerformanceLogEventSource.Log.ExtensibleCommandStart(); var result = resolvedCommand.Execute(); PerformanceLogEventSource.Log.ExtensibleCommandStop(); exitCode = result.ExitCode; } PerformanceLogEventSource.Log.TelemetryClientFlushStart(); telemetryClient.Flush(); PerformanceLogEventSource.Log.TelemetryClientFlushStop(); return(exitCode); }