From b831a98e0a3c704549a1f949872fff1afd87f6ce Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Thu, 9 Jun 2022 14:03:53 +0200 Subject: [PATCH 1/8] For build-from-source builds of .NET, opt-out of Microsoft telemetry by default. We opt-out by setting DOTNET_CLI_TELEMETRY_OPTOUT at 'dotnet' Main to ensure that anything that checks the variable later, including MSBuild Tasks, will see the value. --- src/Cli/dotnet/Program.cs | 10 ++++++++++ src/Cli/dotnet/dotnet.csproj | 1 + 2 files changed, 11 insertions(+) diff --git a/src/Cli/dotnet/Program.cs b/src/Cli/dotnet/Program.cs index eee34231f9ce..12cbc782821a 100644 --- a/src/Cli/dotnet/Program.cs +++ b/src/Cli/dotnet/Program.cs @@ -23,10 +23,20 @@ namespace Microsoft.DotNet.Cli { public class Program { + private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT"; + private static readonly string ToolPathSentinelFileName = $"{Product.Version}.toolpath.sentinel"; public static int Main(string[] args) { +#if NO_TELEMETRY_BY_DEFAULT + // opt out of telemetry by default if the env var is unset + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(TelemetryOptout))) + { + Environment.SetEnvironmentVariable(TelemetryOptout, "1"); + } +#endif + //setting output encoding is not available on those platforms if (!OperatingSystem.IsIOS() && !OperatingSystem.IsAndroid() && !OperatingSystem.IsTvOS()) { diff --git a/src/Cli/dotnet/dotnet.csproj b/src/Cli/dotnet/dotnet.csproj index ad31316cefd3..1bd7fbdf7e7f 100644 --- a/src/Cli/dotnet/dotnet.csproj +++ b/src/Cli/dotnet/dotnet.csproj @@ -9,6 +9,7 @@ dotnet5.4 Microsoft.DotNet.Cli $(DefineConstants);EXCLUDE_ASPNETCORE + $(DefineConstants);NO_TELEMETRY_BY_DEFAULT Microsoft.DotNet.Cli false true From ec48946b0c21ad8d0811f54cc959fd2d4fe40311 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Thu, 9 Jun 2022 14:49:11 +0200 Subject: [PATCH 2/8] Use const string also for existing check. --- src/Cli/dotnet/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/dotnet/Program.cs b/src/Cli/dotnet/Program.cs index 12cbc782821a..d450d25afe44 100644 --- a/src/Cli/dotnet/Program.cs +++ b/src/Cli/dotnet/Program.cs @@ -178,7 +178,7 @@ internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry bool generateAspNetCertificate = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", defaultValue: true); bool telemetryOptout = - environmentProvider.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", defaultValue: false); + environmentProvider.GetEnvironmentVariableAsBool(TelemetryOptout, defaultValue: false); bool addGlobalToolsToPath = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true); bool nologo = From d9a60748f78eb314dda88bb9693864b77cb5056d Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 20 Jun 2022 10:39:52 +0200 Subject: [PATCH 3/8] Refactor to using the default value to control the opt-out. --- Directory.Build.props | 1 + src/Cli/dotnet/Program.cs | 12 +----------- src/Cli/dotnet/Telemetry/Telemetry.cs | 4 ++-- src/Cli/dotnet/dotnet.csproj | 2 +- src/Common/CompileOptions.cs | 15 +++++++++++++++ src/Common/EnvironmentVariableNames.cs | 1 + .../Tasks/Microsoft.NET.Sdk.Publish.Tasks.csproj | 5 ++++- src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs | 4 ++-- 8 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 src/Common/CompileOptions.cs diff --git a/Directory.Build.props b/Directory.Build.props index 8ee962ab1da8..30f232bfa861 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -21,6 +21,7 @@ $(DefineConstants);CI_BUILD + $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY $(DefineConstants);DOT_NET_BUILD_FROM_SOURCE diff --git a/src/Cli/dotnet/Program.cs b/src/Cli/dotnet/Program.cs index d450d25afe44..b7cc49dd4274 100644 --- a/src/Cli/dotnet/Program.cs +++ b/src/Cli/dotnet/Program.cs @@ -23,20 +23,10 @@ namespace Microsoft.DotNet.Cli { public class Program { - private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT"; - private static readonly string ToolPathSentinelFileName = $"{Product.Version}.toolpath.sentinel"; public static int Main(string[] args) { -#if NO_TELEMETRY_BY_DEFAULT - // opt out of telemetry by default if the env var is unset - if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(TelemetryOptout))) - { - Environment.SetEnvironmentVariable(TelemetryOptout, "1"); - } -#endif - //setting output encoding is not available on those platforms if (!OperatingSystem.IsIOS() && !OperatingSystem.IsAndroid() && !OperatingSystem.IsTvOS()) { @@ -178,7 +168,7 @@ internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry bool generateAspNetCertificate = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", defaultValue: true); bool telemetryOptout = - environmentProvider.GetEnvironmentVariableAsBool(TelemetryOptout, defaultValue: false); + environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, defaultValue: CompileOptions.TelemetryOptOutDefault); bool addGlobalToolsToPath = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true); bool nologo = diff --git a/src/Cli/dotnet/Telemetry/Telemetry.cs b/src/Cli/dotnet/Telemetry/Telemetry.cs index 20b2af393c34..954fe655c64a 100644 --- a/src/Cli/dotnet/Telemetry/Telemetry.cs +++ b/src/Cli/dotnet/Telemetry/Telemetry.cs @@ -23,7 +23,6 @@ public class Telemetry : ITelemetry private Task _trackEventTask = null; private const string InstrumentationKey = "74cc1c9e-3e6e-4d05-b3fc-dde9101d0254"; - private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT"; public bool Enabled { get; } @@ -49,7 +48,8 @@ public Telemetry( environmentProvider = new EnvironmentProvider(); } - Enabled = !environmentProvider.GetEnvironmentVariableAsBool(TelemetryOptout, false) && PermissionExists(sentinel); + Enabled = !environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, defaultValue: CompileOptions.TelemetryOptOutDefault) + && PermissionExists(sentinel); if (!Enabled) { diff --git a/src/Cli/dotnet/dotnet.csproj b/src/Cli/dotnet/dotnet.csproj index 1bd7fbdf7e7f..bb202db43721 100644 --- a/src/Cli/dotnet/dotnet.csproj +++ b/src/Cli/dotnet/dotnet.csproj @@ -9,7 +9,6 @@ dotnet5.4 Microsoft.DotNet.Cli $(DefineConstants);EXCLUDE_ASPNETCORE - $(DefineConstants);NO_TELEMETRY_BY_DEFAULT Microsoft.DotNet.Cli false true @@ -18,6 +17,7 @@ + diff --git a/src/Common/CompileOptions.cs b/src/Common/CompileOptions.cs new file mode 100644 index 000000000000..0262f610f5c6 --- /dev/null +++ b/src/Common/CompileOptions.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.DotNet.Cli +{ + static class CompileOptions + { + public const bool TelemetryOptOutDefault = +#if MICROSOFT_ENABLE_TELEMETRY + false; +#else + true; +#endif + } +} \ No newline at end of file diff --git a/src/Common/EnvironmentVariableNames.cs b/src/Common/EnvironmentVariableNames.cs index 236e27329eb1..573bf63dcd98 100644 --- a/src/Common/EnvironmentVariableNames.cs +++ b/src/Common/EnvironmentVariableNames.cs @@ -11,5 +11,6 @@ static class EnvironmentVariableNames public static readonly string WORKLOAD_UPDATE_NOTIFY_DISABLE = "DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE"; public static readonly string WORKLOAD_UPDATE_NOTIFY_INTERVAL_HOURS = "DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_INTERVAL_HOURS"; public static readonly string WORKLOAD_DISABLE_PACK_GROUPS = "DOTNET_CLI_WORKLOAD_DISABLE_PACK_GROUPS"; + public static readonly string TELEMETRY_OPTOUT = "DOTNET_CLI_TELEMETRY_OPTOUT"; } } diff --git a/src/WebSdk/Publish/Tasks/Microsoft.NET.Sdk.Publish.Tasks.csproj b/src/WebSdk/Publish/Tasks/Microsoft.NET.Sdk.Publish.Tasks.csproj index 7946ba4deaf8..bfd3e00a8afd 100644 --- a/src/WebSdk/Publish/Tasks/Microsoft.NET.Sdk.Publish.Tasks.csproj +++ b/src/WebSdk/Publish/Tasks/Microsoft.NET.Sdk.Publish.Tasks.csproj @@ -48,7 +48,10 @@ True Resources.resx - + + + + true targets diff --git a/src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs b/src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs index e485e0547c8b..45cd901e3150 100644 --- a/src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs +++ b/src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs @@ -3,12 +3,12 @@ using System.IO; using System.Text.RegularExpressions; using System.Xml.Linq; +using Microsoft.DotNet.Cli; namespace Microsoft.NET.Sdk.Publish.Tasks { public class WebConfigTelemetry { - private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT"; // An example of a project line looks like this: // Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{05A5AD00-71B5-4612-AF2F-9EA9121C4111}" private static readonly Lazy s_crackProjectLine = new Lazy( @@ -31,7 +31,7 @@ public static XDocument AddTelemetry(XDocument webConfig, string projectGuid, bo { try { - bool isCLIOptOutEnabled = EnvironmentHelper.GetEnvironmentVariableAsBool(TelemetryOptout); + bool isCLIOptOutEnabled = EnvironmentHelper.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, defaultValue: CompileOptions.TelemetryOptOutDefault); if (string.IsNullOrEmpty(projectGuid) && !ignoreProjectGuid && !isCLIOptOutEnabled) { projectGuid = GetProjectGuidFromSolutionFile(solutionFileFullPath, projectFileFullPath); From b5db7d6c77a0f844f2c4f74b19497b6934888b41 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Tue, 21 Jun 2022 13:37:06 +0200 Subject: [PATCH 4/8] Apply suggestions from code review Co-authored-by: Rich Lander --- Directory.Build.props | 2 +- src/Common/CompileOptions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 30f232bfa861..ecd409976062 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -21,7 +21,7 @@ $(DefineConstants);CI_BUILD - $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY + $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY $(DefineConstants);DOT_NET_BUILD_FROM_SOURCE diff --git a/src/Common/CompileOptions.cs b/src/Common/CompileOptions.cs index 0262f610f5c6..2ba77d957d5e 100644 --- a/src/Common/CompileOptions.cs +++ b/src/Common/CompileOptions.cs @@ -12,4 +12,4 @@ static class CompileOptions true; #endif } -} \ No newline at end of file +} From afb63aea6e236eb9fcad1c4d2f4e2b576e4c548f Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Tue, 5 Jul 2022 14:51:04 +0200 Subject: [PATCH 5/8] Rename to OfficialBuilder, and set value to true in workflow. --- .vsts-ci.yml | 3 ++- Directory.Build.props | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 5eee7dcb875e..2581a02e8d6f 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -32,7 +32,8 @@ variables: - group: DotNetBuilds storage account read tokens - name: _InternalRuntimeDownloadArgs value: /p:DotNetRuntimeSourceFeed=https://dotnetbuilds.blob.core.windows.net/internal - /p:DotNetRuntimeSourceFeedKey=$(dotnetbuilds-internal-container-read-token-base64) + /p:DotNetRuntimeSourceFeedKey=$(dotnetbuilds-internal-container-read-token-base64) + /p:OfficialBuild=true - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - group: DotNet-CLI-SDLValidation-Params diff --git a/Directory.Build.props b/Directory.Build.props index ecd409976062..0f26eb934711 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -21,7 +21,7 @@ $(DefineConstants);CI_BUILD - $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY + $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY $(DefineConstants);DOT_NET_BUILD_FROM_SOURCE From 8126bbf82548bfe5a825f3b05d1624bd861e8309 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Tue, 5 Jul 2022 15:26:19 +0200 Subject: [PATCH 6/8] Apply suggestions from code review Use 'Microsoft' as 'OfficialBuilder' value. Co-authored-by: Jan Kotas --- .vsts-ci.yml | 2 +- Directory.Build.props | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 2581a02e8d6f..d4f64117525d 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -33,7 +33,7 @@ variables: - name: _InternalRuntimeDownloadArgs value: /p:DotNetRuntimeSourceFeed=https://dotnetbuilds.blob.core.windows.net/internal /p:DotNetRuntimeSourceFeedKey=$(dotnetbuilds-internal-container-read-token-base64) - /p:OfficialBuild=true + /p:OfficialBuilder=Microsoft - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - group: DotNet-CLI-SDLValidation-Params diff --git a/Directory.Build.props b/Directory.Build.props index 0f26eb934711..5006411eb68c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -21,7 +21,7 @@ $(DefineConstants);CI_BUILD - $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY + $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY $(DefineConstants);DOT_NET_BUILD_FROM_SOURCE From 6d2a16b990b07c5730e02652bb6db0824aacf92a Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Wed, 13 Jul 2022 11:26:10 +0200 Subject: [PATCH 7/8] Update Directory.Build.props --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 5006411eb68c..1353696a295f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -21,7 +21,7 @@ $(DefineConstants);CI_BUILD - $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY + $(DefineConstants);MICROSOFT_ENABLE_TELEMETRY $(DefineConstants);DOT_NET_BUILD_FROM_SOURCE From 2cd0f133b3a06b8b89c252e676137bcb0f8487e7 Mon Sep 17 00:00:00 2001 From: Marc Paine Date: Fri, 29 Jul 2022 16:30:20 -0700 Subject: [PATCH 8/8] Change Move Official builder into a separate build variable --- .vsts-ci.yml | 5 ++++- eng/build.yml | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.vsts-ci.yml b/.vsts-ci.yml index d4f64117525d..495149976450 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -26,14 +26,17 @@ variables: - ${{ if eq(variables['System.TeamProject'], 'public') }}: - name: _InternalRuntimeDownloadArgs value: '' + - name: _OfficialBuildArgs + value: '' - ${{ if ne(variables['System.TeamProject'], 'public') }}: - name: _DotNetPublishToBlobFeed value: true + - name: _OfficialBuildArgs + value: /p:OfficialBuilder=Microsoft - group: DotNetBuilds storage account read tokens - name: _InternalRuntimeDownloadArgs value: /p:DotNetRuntimeSourceFeed=https://dotnetbuilds.blob.core.windows.net/internal /p:DotNetRuntimeSourceFeedKey=$(dotnetbuilds-internal-container-read-token-base64) - /p:OfficialBuilder=Microsoft - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - group: DotNet-CLI-SDLValidation-Params diff --git a/eng/build.yml b/eng/build.yml index fc97c8fe6608..6fb25a126e73 100644 --- a/eng/build.yml +++ b/eng/build.yml @@ -74,6 +74,7 @@ jobs: $(_OfficialBuildIdArgs) /p:Test=false $(_InternalRuntimeDownloadArgs) + $(_OfficialBuildArgs) displayName: Build env: BuildConfig: $(_BuildConfig) @@ -480,4 +481,4 @@ jobs: ArtifactName: '$(_AgentOSName)_$(Agent.JobName)_$(Build.BuildNumber)' publishLocation: Container continueOnError: true - condition: always() \ No newline at end of file + condition: always()