Skip to content

Commit 833a52c

Browse files
committed
use typed config in program.cs
1 parent ddaeeef commit 833a52c

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

src/Cli/dotnet/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ internal static int ProcessArgs(string[] args, TimeSpan startupTime)
182182
var configurationService = DotNetConfigurationFactory.Create();
183183
var environmentProvider = new ConfigurationBasedEnvironmentProvider(configurationService);
184184

185-
bool generateAspNetCertificate = environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.DOTNET_GENERATE_ASPNET_CERTIFICATE, defaultValue: true);
186-
bool telemetryOptout = environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, defaultValue: CompileOptions.TelemetryOptOutDefault);
187-
bool addGlobalToolsToPath = environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.DOTNET_ADD_GLOBAL_TOOLS_TO_PATH, defaultValue: true);
188-
bool nologo = environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.DOTNET_NOLOGO, defaultValue: false);
189-
bool skipWorkloadIntegrityCheck = environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.DOTNET_SKIP_WORKLOAD_INTEGRITY_CHECK,
185+
// Use typed configuration directly instead of environment variable calls
186+
bool generateAspNetCertificate = configurationService.FirstTimeUse.GenerateAspNetCertificate;
187+
bool telemetryOptout = configurationService.CliUserExperience.TelemetryOptOut;
188+
bool addGlobalToolsToPath = configurationService.FirstTimeUse.AddGlobalToolsToPath;
189+
bool nologo = configurationService.CliUserExperience.NoLogo;
190+
bool skipWorkloadIntegrityCheck = configurationService.Workload.SkipIntegrityCheck ||
190191
// Default the workload integrity check skip to true if the command is being ran in CI. Otherwise, false.
191-
defaultValue: new CIEnvironmentDetectorForTelemetry().IsCIEnvironment());
192+
new CIEnvironmentDetectorForTelemetry().IsCIEnvironment();
192193

193194
ReportDotnetHomeUsage(environmentProvider);
194195

src/Microsoft.Extensions.Configuration.DotnetCli/Microsoft.Extensions.Configuration.DotnetCli.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<Compile Include="$(RepoRoot)src\Common\CompileOptions.cs" LinkBase="Common" />
12+
</ItemGroup>
13+
1014
<ItemGroup>
1115
<PackageReference Include="Microsoft.Extensions.Configuration" />
1216
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />

src/Microsoft.Extensions.Configuration.DotnetCli/Models/CliUserExperienceConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Microsoft.DotNet.Cli;
5+
46
namespace Microsoft.Extensions.Configuration.DotnetCli.Models;
57

68
/// <summary>
@@ -12,7 +14,7 @@ public sealed class CliUserExperienceConfiguration
1214
/// Gets or sets whether telemetry collection is disabled.
1315
/// Mapped from DOTNET_CLI_TELEMETRY_OPTOUT environment variable.
1416
/// </summary>
15-
public bool TelemetryOptOut { get; set; } = false;
17+
public bool TelemetryOptOut { get; set; } = CompileOptions.TelemetryOptOutDefault;
1618

1719
/// <summary>
1820
/// Gets or sets whether to suppress the .NET logo on startup.

src/Microsoft.Extensions.Configuration.DotnetCli/Models/WorkloadConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class WorkloadConfiguration
1818
/// Gets or sets the interval in hours between workload update notifications.
1919
/// Mapped from DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_INTERVAL_HOURS environment variable.
2020
/// </summary>
21-
public int UpdateNotifyIntervalHours { get; set; } = 24;
21+
public int UpdateNotifyIntervalHours { get; set; } = 24; // Default to check once per day
2222

2323
/// <summary>
2424
/// Gets or sets whether to disable workload pack groups.

0 commit comments

Comments
 (0)