From fb9e7c157e90599f918614d1af3e3814de708092 Mon Sep 17 00:00:00 2001 From: James May Date: Thu, 6 May 2021 19:57:23 +1000 Subject: [PATCH] Honor DO_NOT_TRACK as well as DOTNET_CLI_TELEMETRY_OPTOUT --- .../LocalizableStrings.resx | 2 +- .../xlf/LocalizableStrings.cs.xlf | 2 +- .../xlf/LocalizableStrings.de.xlf | 4 +-- .../xlf/LocalizableStrings.es.xlf | 4 +-- .../xlf/LocalizableStrings.fr.xlf | 2 +- .../xlf/LocalizableStrings.it.xlf | 2 +- .../xlf/LocalizableStrings.ja.xlf | 2 +- .../xlf/LocalizableStrings.ko.xlf | 2 +- .../xlf/LocalizableStrings.pl.xlf | 2 +- .../xlf/LocalizableStrings.pt-BR.xlf | 2 +- .../xlf/LocalizableStrings.ru.xlf | 2 +- .../xlf/LocalizableStrings.tr.xlf | 2 +- .../xlf/LocalizableStrings.zh-Hans.xlf | 2 +- .../xlf/LocalizableStrings.zh-Hant.xlf | 2 +- src/Cli/dotnet/Program.cs | 3 +- src/Cli/dotnet/README.md | 2 +- src/Cli/dotnet/Telemetry/Telemetry.cs | 5 ++- ...netFirstTimeUseConfigurerWIthStateSetup.cs | 4 ++- .../EnvironmentHelperTests.cs | 32 ++++++++++++------- ...atTheUserIsRunningDotNetForTheFirstTime.cs | 6 ++-- .../Publish/Tasks/WebConfigTelemetry.cs | 4 ++- 21 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/Cli/Microsoft.DotNet.Configurer/LocalizableStrings.resx b/src/Cli/Microsoft.DotNet.Configurer/LocalizableStrings.resx index e5d77533d328..65117c865758 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/LocalizableStrings.resx +++ b/src/Cli/Microsoft.DotNet.Configurer/LocalizableStrings.resx @@ -128,7 +128,7 @@ SDK Version: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf index 134152e56b00..693ee307054a 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf @@ -44,7 +44,7 @@ Verze sady SDK: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Telemetrie diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf index 963ee4db613a..2f8e9180e78d 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf @@ -44,7 +44,7 @@ SDK-Version: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Telemetrie @@ -56,4 +56,4 @@ Weitere Informationen zu Telemetriedaten in .NET-CLI-Tools finden Sie hier: http - \ No newline at end of file + diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf index 481a73bb1e0c..40bbd78696b5 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf @@ -44,7 +44,7 @@ Versión del SDK: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Telemetría @@ -56,4 +56,4 @@ Lea más sobre la telemetría de las herramientas de la CLI de .NET: https://aka - \ No newline at end of file + diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.fr.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.fr.xlf index 27da1cb03099..f79be6ea491e 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.fr.xlf @@ -44,7 +44,7 @@ Version du kit SDK : {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Télémétrie diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.it.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.it.xlf index 4e28cdc82b33..c3728b46c3cf 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.it.xlf @@ -44,7 +44,7 @@ Versione SDK: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Telemetria diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ja.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ja.xlf index dab78dd97df3..a56ea43ea824 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ja.xlf @@ -44,7 +44,7 @@ SDK バージョン: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry テレメトリ diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ko.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ko.xlf index bfba085a0595..17195a5037bd 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ko.xlf @@ -44,7 +44,7 @@ SDK 버전: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry 원격 분석 diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pl.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pl.xlf index 135539034541..d693b2d01db4 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pl.xlf @@ -44,7 +44,7 @@ Wersja zestawu SDK: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Telemetria diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pt-BR.xlf index 278792b0bb07..2ccabf5d0cd8 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pt-BR.xlf @@ -44,7 +44,7 @@ Versão do SDK: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Telemetria diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ru.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ru.xlf index cfc29cfb640c..118a3fb36642 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ru.xlf @@ -44,7 +44,7 @@ SDK Version: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Телеметрия diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.tr.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.tr.xlf index bdd35178e1b4..2852c92aef56 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.tr.xlf @@ -44,7 +44,7 @@ SDK Sürümü: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry Telemetri diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hans.xlf index 447f6c66a95d..0c3ab287dff4 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hans.xlf @@ -44,7 +44,7 @@ SDK 版本: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry 遥测 diff --git a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hant.xlf index d12250e35e24..5589b260a899 100644 --- a/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/Cli/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hant.xlf @@ -44,7 +44,7 @@ SDK 版本: {1} Telemetry --------- -The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. +The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting either the DOTNET_CLI_TELEMETRY_OPTOUT or DO_NOT_TRACK environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry 遙測 diff --git a/src/Cli/dotnet/Program.cs b/src/Cli/dotnet/Program.cs index eb8613a36728..9e1b4f7739ab 100644 --- a/src/Cli/dotnet/Program.cs +++ b/src/Cli/dotnet/Program.cs @@ -158,7 +158,8 @@ 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("DOTNET_CLI_TELEMETRY_OPTOUT", defaultValue: false) + || environmentProvider.GetEnvironmentVariableAsBool("DO_NOT_TRACK", defaultValue: false); bool addGlobalToolsToPath = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true); bool nologo = diff --git a/src/Cli/dotnet/README.md b/src/Cli/dotnet/README.md index 5d8d6bb80127..de7c77514f6f 100644 --- a/src/Cli/dotnet/README.md +++ b/src/Cli/dotnet/README.md @@ -82,6 +82,6 @@ The primary package cache. If not set, it defaults to $HOME/.nuget/packages on U Specifies the location of the servicing index to use by the shared host when loading the runtime. -`DOTNET_CLI_TELEMETRY_OPTOUT` +`DO_NOT_TRACK` or `DOTNET_CLI_TELEMETRY_OPTOUT` Specifies whether data about the .NET Core tools usage is collected and sent to Microsoft. **true** to opt-out of the telemetry feature (values true, 1 or yes accepted); otherwise, **false** (values false, 0 or no accepted). If not set, it defaults to **false**, that is, the telemetry feature is on. diff --git a/src/Cli/dotnet/Telemetry/Telemetry.cs b/src/Cli/dotnet/Telemetry/Telemetry.cs index b4171caaf03b..a85f474bce53 100644 --- a/src/Cli/dotnet/Telemetry/Telemetry.cs +++ b/src/Cli/dotnet/Telemetry/Telemetry.cs @@ -23,6 +23,7 @@ public class Telemetry : ITelemetry private const string InstrumentationKey = "74cc1c9e-3e6e-4d05-b3fc-dde9101d0254"; private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT"; + private const string TelemetryOptoutCommon = "DO_NOT_TRACK"; public bool Enabled { get; } @@ -42,7 +43,9 @@ public Telemetry( environmentProvider = new EnvironmentProvider(); } - Enabled = !environmentProvider.GetEnvironmentVariableAsBool(TelemetryOptout, false) && PermissionExists(sentinel); + Enabled = !environmentProvider.GetEnvironmentVariableAsBool(TelemetryOptout, false) + && !environmentProvider.GetEnvironmentVariableAsBool(TelemetryOptoutCommon, false) + && PermissionExists(sentinel); if (!Enabled) { diff --git a/src/Tests/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurerWIthStateSetup.cs b/src/Tests/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurerWIthStateSetup.cs index 927d1525ab99..3c441b7d6cf5 100644 --- a/src/Tests/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurerWIthStateSetup.cs +++ b/src/Tests/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurerWIthStateSetup.cs @@ -86,6 +86,7 @@ bool telemetrySecondRunShouldBeEnabled _environmentProvider .Setup(p => p.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", It.IsAny())) .Returns(DOTNET_GENERATE_ASPNET_CERTIFICATE); + // XXX: Handle DO_NOT_TRACK? _environmentProvider .Setup(p => p.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", It.IsAny())) .Returns(DOTNET_CLI_TELEMETRY_OPTOUT); @@ -215,7 +216,8 @@ private Telemetry RunConfigUsingMocks(bool isInstallerRun) bool generateAspNetCertificate = _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true); bool telemetryOptout = - _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", false); + _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", false) + || _environmentProviderObject.GetEnvironmentVariableAsBool("DO_NOT_TRACK", false); bool addGlobalToolsToPath = _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true); bool nologo = diff --git a/src/Tests/Microsoft.NET.Sdk.Publish.Tasks.Tests/EnvironmentHelperTests.cs b/src/Tests/Microsoft.NET.Sdk.Publish.Tasks.Tests/EnvironmentHelperTests.cs index 99d7bee951cd..eba6f4519cf1 100644 --- a/src/Tests/Microsoft.NET.Sdk.Publish.Tasks.Tests/EnvironmentHelperTests.cs +++ b/src/Tests/Microsoft.NET.Sdk.Publish.Tasks.Tests/EnvironmentHelperTests.cs @@ -10,30 +10,38 @@ namespace Microsoft.NET.Sdk.Publish.Tasks.Tests public class EnvironmentHelperTests { private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT"; + private const string TelemetryOptoutCommon = "DO_NOT_TRACK"; [Theory] - [InlineData("true", true)] - [InlineData("1", true)] - [InlineData("yes", true)] - [InlineData("false", false)] - [InlineData("0", false)] - [InlineData("no", false)] - [InlineData("anyothervalue", false)] - public void WebConfigTelemetry_RemovesProjectGuid_IfCLIOptedOutEnvVariableIsSet(string value, bool expectedOutput) + [InlineData(TelemetryOptout, "true", true)] + [InlineData(TelemetryOptout, "1", true)] + [InlineData(TelemetryOptout, "yes", true)] + [InlineData(TelemetryOptout, "false", false)] + [InlineData(TelemetryOptout, "0", false)] + [InlineData(TelemetryOptout, "no", false)] + [InlineData(TelemetryOptout, "anyothervalue", false)] + [InlineData(TelemetryOptoutCommon, "true", true)] + [InlineData(TelemetryOptoutCommon, "1", true)] + [InlineData(TelemetryOptoutCommon, "yes", true)] + [InlineData(TelemetryOptoutCommon, "false", false)] + [InlineData(TelemetryOptoutCommon, "0", false)] + [InlineData(TelemetryOptoutCommon, "no", false)] + [InlineData(TelemetryOptoutCommon, "anyothervalue", false)] + public void WebConfigTelemetry_RemovesProjectGuid_IfCLIOptedOutEnvVariableIsSet(string variable, string value, bool expectedOutput) { // Arrange - string originalValue = Environment.GetEnvironmentVariable(TelemetryOptout); - Environment.SetEnvironmentVariable(TelemetryOptout, value); + string originalValue = Environment.GetEnvironmentVariable(variable); + Environment.SetEnvironmentVariable(variable, value); // Act - bool actualOutput = EnvironmentHelper.GetEnvironmentVariableAsBool(TelemetryOptout); + bool actualOutput = EnvironmentHelper.GetEnvironmentVariableAsBool(variable); // Assert Assert.Equal(expectedOutput, actualOutput); // reset the value back to the original value - Environment.SetEnvironmentVariable(TelemetryOptout, originalValue); + Environment.SetEnvironmentVariable(variable, originalValue); } } } diff --git a/src/Tests/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs b/src/Tests/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs index ce6ef6e3141c..947a18f21c08 100644 --- a/src/Tests/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs +++ b/src/Tests/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs @@ -144,7 +144,9 @@ public void ItCreatesAnAspNetCertificateSentinelFileUnderTheDotDotNetFolder() } [Fact] - public void ItDoesNotCreateAFirstUseSentinelFileNorAnAspNetCertificateSentinelFileUnderTheDotDotNetFolderWhenInternalReportInstallSuccessIsInvoked() + [InlineData("DOTNET_CLI_TELEMETRY_OPTOUT")] + [InlineData("DO_NOT_TRACK")] + public void ItDoesNotCreateAFirstUseSentinelFileNorAnAspNetCertificateSentinelFileUnderTheDotDotNetFolderWhenInternalReportInstallSuccessIsInvoked(string telemetryOptoutVariableName) { var dotnetFirstTime = new DotNetFirstTime(); @@ -152,7 +154,7 @@ public void ItDoesNotCreateAFirstUseSentinelFileNorAnAspNetCertificateSentinelFi // Disable telemetry to prevent the creation of the .dotnet folder // for machineid and docker cache files - command = command.WithEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "true"); + command = command.WithEnvironmentVariable(telemetryOptoutVariableName, "true"); command.Execute("internal-reportinstallsuccess", "test").Should().Pass(); diff --git a/src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs b/src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs index e485e0547c8b..0e343f105eee 100644 --- a/src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs +++ b/src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs @@ -9,6 +9,7 @@ namespace Microsoft.NET.Sdk.Publish.Tasks public class WebConfigTelemetry { private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT"; + private const string TelemetryOptoutCommon = "DO_NOT_TRACK"; // 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 +32,8 @@ public static XDocument AddTelemetry(XDocument webConfig, string projectGuid, bo { try { - bool isCLIOptOutEnabled = EnvironmentHelper.GetEnvironmentVariableAsBool(TelemetryOptout); + bool isCLIOptOutEnabled = EnvironmentHelper.GetEnvironmentVariableAsBool(TelemetryOptout) + || EnvironmentHelper.GetEnvironmentVariableAsBool(TelemetryOptoutCommon); if (string.IsNullOrEmpty(projectGuid) && !ignoreProjectGuid && !isCLIOptOutEnabled) { projectGuid = GetProjectGuidFromSolutionFile(solutionFileFullPath, projectFileFullPath);