From d3e85167d3197b4b91679521ecbeb87fdaa280f4 Mon Sep 17 00:00:00 2001 From: Will Li Date: Fri, 5 Feb 2021 12:57:11 -0800 Subject: [PATCH 01/19] ToolsetConfigurationReader compilable with net5.0 --- eng/Packages.props | 5 +++-- src/Build/Definition/ProjectCollection.cs | 6 ------ src/Build/Definition/ToolsetReader.cs | 8 -------- src/Build/Microsoft.Build.csproj | 6 +++--- src/Shared/FrameworkLocationHelper.cs | 6 ------ src/Shared/ToolsetElement.cs | 5 ----- src/Tasks.UnitTests/Copy_Tests.cs | 2 ++ src/Utilities/Microsoft.Build.Utilities.csproj | 3 +-- 8 files changed, 9 insertions(+), 32 deletions(-) diff --git a/eng/Packages.props b/eng/Packages.props index 30ae007906c..251da3b23a3 100644 --- a/eng/Packages.props +++ b/eng/Packages.props @@ -19,6 +19,7 @@ + @@ -36,8 +37,8 @@ - - + + diff --git a/src/Build/Definition/ProjectCollection.cs b/src/Build/Definition/ProjectCollection.cs index ec52f815e3d..88c7f74bca7 100644 --- a/src/Build/Definition/ProjectCollection.cs +++ b/src/Build/Definition/ProjectCollection.cs @@ -1729,7 +1729,6 @@ private void CreateLoggingService(int maxCPUCount, bool onlyLogCriticalEvents) _loggingService.OnlyLogCriticalEvents = onlyLogCriticalEvents; } -#if FEATURE_SYSTEM_CONFIGURATION /// /// Reset the toolsets using the provided toolset reader, used by unit tests /// @@ -1737,7 +1736,6 @@ internal void ResetToolsetsForTests(ToolsetConfigurationReader configurationRead { InitializeToolsetCollection(configReader:configurationReaderForTestsOnly); } -#endif #if FEATURE_WIN32_REGISTRY /// @@ -1757,9 +1755,7 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests #if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader = null, #endif -#if FEATURE_SYSTEM_CONFIGURATION ToolsetConfigurationReader configReader = null -#endif ) { _toolsets = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -1769,9 +1765,7 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests #if FEATURE_WIN32_REGISTRY registryReader, #endif -#if FEATURE_SYSTEM_CONFIGURATION configReader, -#endif EnvironmentProperties, _globalProperties, ToolsetLocations); _toolsetsVersion++; diff --git a/src/Build/Definition/ToolsetReader.cs b/src/Build/Definition/ToolsetReader.cs index 3bcf77e90aa..869b3318ea4 100644 --- a/src/Build/Definition/ToolsetReader.cs +++ b/src/Build/Definition/ToolsetReader.cs @@ -76,7 +76,6 @@ internal abstract class ToolsetReader get; } -#if FEATURE_WIN32_REGISTRY || FEATURE_SYSTEM_CONFIGURATION /// /// Gathers toolset data from the registry and configuration file, if any: /// allows you to specify which of the registry and configuration file to @@ -88,12 +87,9 @@ internal static string ReadAllToolsets(Dictionary toolsets, Pro #if FEATURE_WIN32_REGISTRY null, #endif -#if FEATURE_SYSTEM_CONFIGURATION null, -#endif environmentProperties, globalProperties, locations); } -#endif /// /// Gathers toolset data from the registry and configuration file, if any. @@ -105,9 +101,7 @@ internal static string ReadAllToolsets #if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader, #endif -#if FEATURE_SYSTEM_CONFIGURATION ToolsetConfigurationReader configurationReader, -#endif PropertyDictionary environmentProperties, PropertyDictionary globalProperties, ToolsetDefinitionLocations locations @@ -124,7 +118,6 @@ ToolsetDefinitionLocations locations string overrideTasksPathFromConfiguration = null; string defaultOverrideToolsVersionFromConfiguration = null; -#if FEATURE_SYSTEM_CONFIGURATION if ((locations & ToolsetDefinitionLocations.ConfigurationFile) == ToolsetDefinitionLocations.ConfigurationFile) { if (configurationReader == null) @@ -137,7 +130,6 @@ ToolsetDefinitionLocations locations initialProperties, true /* accumulate properties */, out overrideTasksPathFromConfiguration, out defaultOverrideToolsVersionFromConfiguration); } -#endif string defaultToolsVersionFromRegistry = null; string overrideTasksPathFromRegistry = null; diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index a554ecfd951..7e846d74565 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -31,6 +31,7 @@ + @@ -41,7 +42,6 @@ - @@ -419,8 +419,8 @@ - - + + true diff --git a/src/Shared/FrameworkLocationHelper.cs b/src/Shared/FrameworkLocationHelper.cs index bacbc95e936..8544c12acd2 100644 --- a/src/Shared/FrameworkLocationHelper.cs +++ b/src/Shared/FrameworkLocationHelper.cs @@ -4,17 +4,11 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -#if FEATURE_SYSTEM_CONFIGURATION -using System.Configuration; -#endif using System.IO; using System.Linq; using System.Runtime.Versioning; using Microsoft.Win32; -#if FEATURE_SYSTEM_CONFIGURATION -using PropertyElement = Microsoft.Build.Evaluation.ToolsetElement.PropertyElement; -#endif using Microsoft.Build.Shared.FileSystem; namespace Microsoft.Build.Shared diff --git a/src/Shared/ToolsetElement.cs b/src/Shared/ToolsetElement.cs index 7453ed33cb3..feb3acb6a5c 100644 --- a/src/Shared/ToolsetElement.cs +++ b/src/Shared/ToolsetElement.cs @@ -3,17 +3,13 @@ using System; using System.Collections.Generic; -#if FEATURE_SYSTEM_CONFIGURATION using System.Configuration; -#endif using System.IO; using Microsoft.Build.Collections; using Microsoft.Build.Shared; namespace Microsoft.Build.Evaluation { -#if FEATURE_SYSTEM_CONFIGURATION - /// /// Helper class for reading toolsets out of the configuration file. /// @@ -708,5 +704,4 @@ public string DefaultOverrideToolsVersion } } } -#endif } diff --git a/src/Tasks.UnitTests/Copy_Tests.cs b/src/Tasks.UnitTests/Copy_Tests.cs index edd0c80b6e4..b3591623fae 100644 --- a/src/Tasks.UnitTests/Copy_Tests.cs +++ b/src/Tasks.UnitTests/Copy_Tests.cs @@ -2397,7 +2397,9 @@ public void CopyToDestinationFolderWithSymbolicLinkCheck() if (NativeMethodsShared.IsWindows) { +#pragma warning disable CA1416 if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null))) +#pragma warning restore CA1416 { isPrivileged = false; Assert.True(true, "It seems that you don't have the permission to create symbolic links. Try to run this test again with higher privileges"); diff --git a/src/Utilities/Microsoft.Build.Utilities.csproj b/src/Utilities/Microsoft.Build.Utilities.csproj index 2fdd06afdd6..a683d5a7112 100644 --- a/src/Utilities/Microsoft.Build.Utilities.csproj +++ b/src/Utilities/Microsoft.Build.Utilities.csproj @@ -22,12 +22,11 @@ + - - From d9a316d735ffcf8814821614a6653f9c550b2775 Mon Sep 17 00:00:00 2001 From: Will Li Date: Fri, 5 Feb 2021 13:53:12 -0800 Subject: [PATCH 02/19] Allow some unit tests to run in net5.0 --- .../Definition/ToolsetConfigurationReader_Tests.cs | 3 --- .../Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs | 6 ------ .../Microsoft.Build.Engine.UnitTests.csproj | 8 ++------ 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs index db0593111e7..41bc1a70494 100644 --- a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs +++ b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs @@ -1,10 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_SYSTEM_CONFIGURATION using System.Configuration; -using Microsoft.Win32; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Execution; @@ -683,4 +681,3 @@ private ToolsetConfigurationReader GetStandardConfigurationReader() } } -#endif diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index da2f1fc518e..a8d17dde5c2 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -1,10 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_SYSTEM_CONFIGURATION - -using System.Configuration; -using Microsoft.Win32; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Exceptions; @@ -15,7 +11,6 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.Build.UnitTests; namespace Microsoft.Build.UnitTests.Evaluation { @@ -977,4 +972,3 @@ private ToolsetConfigurationReader GetStandardConfigurationReader() } } } -#endif diff --git a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj index dbb5365a805..c685e1d4af7 100644 --- a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj +++ b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj @@ -1,4 +1,4 @@ - + $(RuntimeOutputTargetFrameworks) @@ -17,6 +17,7 @@ + @@ -45,17 +46,12 @@ TargetFramework=$(FullFrameworkTFM) TargetFramework=net5.0 - - true - - - From 046e0a6dc00cb45f61ceab2011058d83d256ae51 Mon Sep 17 00:00:00 2001 From: Will Li Date: Mon, 8 Feb 2021 15:56:45 -0800 Subject: [PATCH 03/19] Remove System.Configuration Reference completed --- .../Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs | 6 ++++++ src/MSBuild/MSBuild.csproj | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index a8d17dde5c2..da2f1fc518e 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -1,6 +1,10 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if FEATURE_SYSTEM_CONFIGURATION + +using System.Configuration; +using Microsoft.Win32; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Exceptions; @@ -11,6 +15,7 @@ using System; using System.Collections.Generic; using System.IO; +using Microsoft.Build.UnitTests; namespace Microsoft.Build.UnitTests.Evaluation { @@ -972,3 +977,4 @@ private ToolsetConfigurationReader GetStandardConfigurationReader() } } } +#endif diff --git a/src/MSBuild/MSBuild.csproj b/src/MSBuild/MSBuild.csproj index 98f08298b0b..e936c21e19b 100644 --- a/src/MSBuild/MSBuild.csproj +++ b/src/MSBuild/MSBuild.csproj @@ -222,12 +222,14 @@ PreserveNewest + + + - From 9a541e4f353529db0425ebd40d149fd4e6870b7a Mon Sep 17 00:00:00 2001 From: Will Li Date: Tue, 9 Feb 2021 13:02:04 -0800 Subject: [PATCH 04/19] Allow IntrinsicFunctions to run in all conditions --- src/Build/Evaluation/IntrinsicFunctions.cs | 32 ---------------------- 1 file changed, 32 deletions(-) diff --git a/src/Build/Evaluation/IntrinsicFunctions.cs b/src/Build/Evaluation/IntrinsicFunctions.cs index aa1cdeaa90b..2295b0d24ad 100644 --- a/src/Build/Evaluation/IntrinsicFunctions.cs +++ b/src/Build/Evaluation/IntrinsicFunctions.cs @@ -24,11 +24,9 @@ namespace Microsoft.Build.Evaluation /// internal static class IntrinsicFunctions { -#if FEATURE_WIN32_REGISTRY private static readonly object[] DefaultRegistryViews = new object[] { RegistryView.Default }; private static readonly Lazy RegistrySdkRegex = new Lazy(() => new Regex(@"^HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft SDKs\\Windows\\v(\d+\.\d+)$", RegexOptions.IgnoreCase)); -#endif // FEATURE_WIN32_REGISTRY private static readonly Lazy NuGetFramework = new Lazy(() => new NuGetFrameworkWrapper()); @@ -160,7 +158,6 @@ internal static int BitwiseNot(int first) return ~first; } -#if FEATURE_WIN32_REGISTRY /// /// Get the value of the registry key and value, default value is null /// @@ -259,33 +256,6 @@ internal static object GetRegistryValueFromView(string keyName, string valueName return result; } -#else // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - - /// - /// Get the value of the registry key and value, default value is null - /// - internal static object GetRegistryValue(string keyName, string valueName) - { - return null; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - } - - /// - /// Get the value of the registry key and value - /// - internal static object GetRegistryValue(string keyName, string valueName, object defaultValue) - { - return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - } - - /// - /// Get the value of the registry key from one of the RegistryView's specified - /// - internal static object GetRegistryValueFromView(string keyName, string valueName, object defaultValue, params object[] views) - { - return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - } -#endif - /// /// Given the absolute location of a file, and a disc location, returns relative file path to that disk location. /// Throws UriFormatException. @@ -571,7 +541,6 @@ internal static List __GetListTest() #endregion -#if FEATURE_WIN32_REGISTRY /// /// Following function will parse a keyName and returns the basekey for it. /// It will also store the subkey name in the out parameter. @@ -640,6 +609,5 @@ private static RegistryKey GetBaseKeyFromKeyName(string keyName, RegistryView vi return basekey; } -#endif } } From d0d0e7e08220ca3c41c8742e4ea53ab5db6c7539 Mon Sep 17 00:00:00 2001 From: Will Li Date: Wed, 17 Feb 2021 13:11:19 -0800 Subject: [PATCH 05/19] Open up Registry as well --- src/Build/Definition/ProjectCollection.cs | 6 ------ src/Build/Definition/ToolsetReader.cs | 6 ------ src/Build/Definition/ToolsetRegistryReader.cs | 6 ------ src/Build/Utilities/RegistryKeyWrapper.cs | 6 ------ 4 files changed, 24 deletions(-) diff --git a/src/Build/Definition/ProjectCollection.cs b/src/Build/Definition/ProjectCollection.cs index 88c7f74bca7..9471945f4e3 100644 --- a/src/Build/Definition/ProjectCollection.cs +++ b/src/Build/Definition/ProjectCollection.cs @@ -1737,7 +1737,6 @@ internal void ResetToolsetsForTests(ToolsetConfigurationReader configurationRead InitializeToolsetCollection(configReader:configurationReaderForTestsOnly); } -#if FEATURE_WIN32_REGISTRY /// /// Reset the toolsets using the provided toolset reader, used by unit tests /// @@ -1745,16 +1744,13 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests { InitializeToolsetCollection(registryReader:registryReaderForTestsOnly); } -#endif /// /// Populate Toolsets with a dictionary of (toolset version, Toolset) /// using information from the registry and config file, if any. /// private void InitializeToolsetCollection( -#if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader = null, -#endif ToolsetConfigurationReader configReader = null ) { @@ -1762,9 +1758,7 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests // We only want our local toolset (as defined in MSBuild.exe.config) when we're operating locally... _defaultToolsVersion = ToolsetReader.ReadAllToolsets(_toolsets, -#if FEATURE_WIN32_REGISTRY registryReader, -#endif configReader, EnvironmentProperties, _globalProperties, ToolsetLocations); diff --git a/src/Build/Definition/ToolsetReader.cs b/src/Build/Definition/ToolsetReader.cs index 869b3318ea4..56591a93104 100644 --- a/src/Build/Definition/ToolsetReader.cs +++ b/src/Build/Definition/ToolsetReader.cs @@ -84,9 +84,7 @@ internal abstract class ToolsetReader internal static string ReadAllToolsets(Dictionary toolsets, PropertyDictionary environmentProperties, PropertyDictionary globalProperties, ToolsetDefinitionLocations locations) { return ReadAllToolsets(toolsets, -#if FEATURE_WIN32_REGISTRY null, -#endif null, environmentProperties, globalProperties, locations); } @@ -98,9 +96,7 @@ internal static string ReadAllToolsets(Dictionary toolsets, Pro internal static string ReadAllToolsets ( Dictionary toolsets, -#if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader, -#endif ToolsetConfigurationReader configurationReader, PropertyDictionary environmentProperties, PropertyDictionary globalProperties, @@ -137,7 +133,6 @@ ToolsetDefinitionLocations locations if ((locations & ToolsetDefinitionLocations.Registry) == ToolsetDefinitionLocations.Registry) { -#if FEATURE_WIN32_REGISTRY if (NativeMethodsShared.IsWindows || registryReader != null) { // If we haven't been provided a registry reader (i.e. unit tests), create one @@ -151,7 +146,6 @@ ToolsetDefinitionLocations locations out defaultOverrideToolsVersionFromRegistry); } else -#endif { var currentDir = BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory.TrimEnd(Path.DirectorySeparatorChar); var props = new PropertyDictionary(); diff --git a/src/Build/Definition/ToolsetRegistryReader.cs b/src/Build/Definition/ToolsetRegistryReader.cs index 7a083fbebbd..7b1bfc4dd76 100644 --- a/src/Build/Definition/ToolsetRegistryReader.cs +++ b/src/Build/Definition/ToolsetRegistryReader.cs @@ -1,13 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_WIN32_REGISTRY - -using Microsoft.Win32; using System; using System.Collections.Generic; -using System.IO; -using System.Security; using Microsoft.Build.Shared; using error = Microsoft.Build.Shared.ErrorUtilities; @@ -346,4 +341,3 @@ private static string GetValue(RegistryKeyWrapper wrapper, string valueName) } } } -#endif \ No newline at end of file diff --git a/src/Build/Utilities/RegistryKeyWrapper.cs b/src/Build/Utilities/RegistryKeyWrapper.cs index 5db9a22e37c..8ab3c88e6a9 100644 --- a/src/Build/Utilities/RegistryKeyWrapper.cs +++ b/src/Build/Utilities/RegistryKeyWrapper.cs @@ -1,12 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_WIN32_REGISTRY using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Security; using Microsoft.Build.Shared; using Microsoft.Win32; @@ -271,4 +266,3 @@ private void Dispose(bool disposing) } } } -#endif From f3d2d228341fd3ff64c0e1fab507863083f35a0e Mon Sep 17 00:00:00 2001 From: Will Li Date: Tue, 2 Mar 2021 14:17:26 -0800 Subject: [PATCH 06/19] Removing all FEATURE_SYSTEM_CONFIGURATION that aren't needed --- .../ToolsetConfigurationReader_Tests.cs | 1 - .../Definition/ToolsetReader_Tests.cs | 2 -- .../ImportFromMSBuildExtensionsPath_Tests.cs | 8 +++-- src/Build/Definition/ProjectCollection.cs | 10 ++++-- src/Build/Definition/ToolsetReader.cs | 6 ++++ src/Build/Definition/ToolsetRegistryReader.cs | 3 ++ src/Build/Evaluation/IntrinsicFunctions.cs | 34 ++++++++++++++++++- src/Build/Utilities/RegistryKeyWrapper.cs | 2 ++ src/MSBuild/XMake.cs | 2 -- src/Tasks.UnitTests/Copy_Tests.cs | 4 +-- 10 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs index 41bc1a70494..6babb127ce7 100644 --- a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs +++ b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. - using System.Configuration; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; diff --git a/src/Build.UnitTests/Definition/ToolsetReader_Tests.cs b/src/Build.UnitTests/Definition/ToolsetReader_Tests.cs index 2e44a4239a9..c90b546da38 100644 --- a/src/Build.UnitTests/Definition/ToolsetReader_Tests.cs +++ b/src/Build.UnitTests/Definition/ToolsetReader_Tests.cs @@ -3,9 +3,7 @@ using System; using System.Collections.Generic; -#if FEATURE_SYSTEM_CONFIGURATION using System.Configuration; -#endif using System.IO; using Microsoft.Build.Collections; diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index da2f1fc518e..1781342fefb 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -2,9 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #if FEATURE_SYSTEM_CONFIGURATION +// NOTE: This test WOULD work in net5.0 after the System.Configuration.ConfigurationManager change. However, it would +// only work if ToolsetDefinitionLocations is set to ConfigurationFile and that ReadApplicationConfiguration in +// ToolsetConfigurationReader.cs removes the RunningTests condition since ConfigurationManager.OpenExeConfiguration +// would try to get testhost.exe.config instead of the actual configuration file. But those changes seems more +// fitting as a different test rather than making all these changes instead. -using System.Configuration; -using Microsoft.Win32; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Exceptions; @@ -15,7 +18,6 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.Build.UnitTests; namespace Microsoft.Build.UnitTests.Evaluation { diff --git a/src/Build/Definition/ProjectCollection.cs b/src/Build/Definition/ProjectCollection.cs index 9471945f4e3..a75a28c248a 100644 --- a/src/Build/Definition/ProjectCollection.cs +++ b/src/Build/Definition/ProjectCollection.cs @@ -1737,6 +1737,7 @@ internal void ResetToolsetsForTests(ToolsetConfigurationReader configurationRead InitializeToolsetCollection(configReader:configurationReaderForTestsOnly); } +#if FEATURE_WIN32_REGISTRY /// /// Reset the toolsets using the provided toolset reader, used by unit tests /// @@ -1744,13 +1745,16 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests { InitializeToolsetCollection(registryReader:registryReaderForTestsOnly); } +#endif /// /// Populate Toolsets with a dictionary of (toolset version, Toolset) /// using information from the registry and config file, if any. /// private void InitializeToolsetCollection( +#if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader = null, +#endif ToolsetConfigurationReader configReader = null ) { @@ -1758,7 +1762,9 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests // We only want our local toolset (as defined in MSBuild.exe.config) when we're operating locally... _defaultToolsVersion = ToolsetReader.ReadAllToolsets(_toolsets, +#if FEATURE_WIN32_REGISTRY registryReader, +#endif configReader, EnvironmentProperties, _globalProperties, ToolsetLocations); @@ -2026,9 +2032,9 @@ public void IncludeTaskInputs() _includeTaskInputs = true; } - #endregion +#endregion - #region ILogger Members +#region ILogger Members /// /// The logger verbosity diff --git a/src/Build/Definition/ToolsetReader.cs b/src/Build/Definition/ToolsetReader.cs index 56591a93104..869b3318ea4 100644 --- a/src/Build/Definition/ToolsetReader.cs +++ b/src/Build/Definition/ToolsetReader.cs @@ -84,7 +84,9 @@ internal abstract class ToolsetReader internal static string ReadAllToolsets(Dictionary toolsets, PropertyDictionary environmentProperties, PropertyDictionary globalProperties, ToolsetDefinitionLocations locations) { return ReadAllToolsets(toolsets, +#if FEATURE_WIN32_REGISTRY null, +#endif null, environmentProperties, globalProperties, locations); } @@ -96,7 +98,9 @@ internal static string ReadAllToolsets(Dictionary toolsets, Pro internal static string ReadAllToolsets ( Dictionary toolsets, +#if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader, +#endif ToolsetConfigurationReader configurationReader, PropertyDictionary environmentProperties, PropertyDictionary globalProperties, @@ -133,6 +137,7 @@ ToolsetDefinitionLocations locations if ((locations & ToolsetDefinitionLocations.Registry) == ToolsetDefinitionLocations.Registry) { +#if FEATURE_WIN32_REGISTRY if (NativeMethodsShared.IsWindows || registryReader != null) { // If we haven't been provided a registry reader (i.e. unit tests), create one @@ -146,6 +151,7 @@ ToolsetDefinitionLocations locations out defaultOverrideToolsVersionFromRegistry); } else +#endif { var currentDir = BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory.TrimEnd(Path.DirectorySeparatorChar); var props = new PropertyDictionary(); diff --git a/src/Build/Definition/ToolsetRegistryReader.cs b/src/Build/Definition/ToolsetRegistryReader.cs index 7b1bfc4dd76..e2081dc5ad7 100644 --- a/src/Build/Definition/ToolsetRegistryReader.cs +++ b/src/Build/Definition/ToolsetRegistryReader.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if FEATURE_WIN32_REGISTRY + using System; using System.Collections.Generic; @@ -341,3 +343,4 @@ private static string GetValue(RegistryKeyWrapper wrapper, string valueName) } } } +#endif diff --git a/src/Build/Evaluation/IntrinsicFunctions.cs b/src/Build/Evaluation/IntrinsicFunctions.cs index 2295b0d24ad..46b0bb0a1ea 100644 --- a/src/Build/Evaluation/IntrinsicFunctions.cs +++ b/src/Build/Evaluation/IntrinsicFunctions.cs @@ -24,9 +24,11 @@ namespace Microsoft.Build.Evaluation /// internal static class IntrinsicFunctions { +#if FEATURE_WIN32_REGISTRY private static readonly object[] DefaultRegistryViews = new object[] { RegistryView.Default }; private static readonly Lazy RegistrySdkRegex = new Lazy(() => new Regex(@"^HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft SDKs\\Windows\\v(\d+\.\d+)$", RegexOptions.IgnoreCase)); +#endif // FEATURE_WIN32_REGISTRY private static readonly Lazy NuGetFramework = new Lazy(() => new NuGetFrameworkWrapper()); @@ -158,6 +160,7 @@ internal static int BitwiseNot(int first) return ~first; } +#if FEATURE_WIN32_REGISTRY /// /// Get the value of the registry key and value, default value is null /// @@ -256,6 +259,33 @@ internal static object GetRegistryValueFromView(string keyName, string valueName return result; } +#else // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + + /// + /// Get the value of the registry key and value, default value is null + /// + internal static object GetRegistryValue(string keyName, string valueName) + { + return null; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + } + + /// + /// Get the value of the registry key and value + /// + internal static object GetRegistryValue(string keyName, string valueName, object defaultValue) + { + return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + } + + /// + /// Get the value of the registry key from one of the RegistryView's specified + /// + internal static object GetRegistryValueFromView(string keyName, string valueName, object defaultValue, params object[] views) + { + return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + } +#endif + /// /// Given the absolute location of a file, and a disc location, returns relative file path to that disk location. /// Throws UriFormatException. @@ -539,8 +569,9 @@ internal static List __GetListTest() return new List { "A", "B", "C", "D" }; } -#endregion + #endregion +#if FEATURE_WIN32_REGISTRY /// /// Following function will parse a keyName and returns the basekey for it. /// It will also store the subkey name in the out parameter. @@ -609,5 +640,6 @@ private static RegistryKey GetBaseKeyFromKeyName(string keyName, RegistryView vi return basekey; } +#endif } } diff --git a/src/Build/Utilities/RegistryKeyWrapper.cs b/src/Build/Utilities/RegistryKeyWrapper.cs index 8ab3c88e6a9..c1503c698ef 100644 --- a/src/Build/Utilities/RegistryKeyWrapper.cs +++ b/src/Build/Utilities/RegistryKeyWrapper.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if FEATURE_WIN32_REGISTRY using System; @@ -266,3 +267,4 @@ private void Dispose(bool disposing) } } } +#endif diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 89b5641c4c4..128b9c9f13d 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -4,9 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; -#if FEATURE_SYSTEM_CONFIGURATION using System.Configuration; -#endif using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; diff --git a/src/Tasks.UnitTests/Copy_Tests.cs b/src/Tasks.UnitTests/Copy_Tests.cs index b3591623fae..6d48ace8c4b 100644 --- a/src/Tasks.UnitTests/Copy_Tests.cs +++ b/src/Tasks.UnitTests/Copy_Tests.cs @@ -2397,9 +2397,9 @@ public void CopyToDestinationFolderWithSymbolicLinkCheck() if (NativeMethodsShared.IsWindows) { -#pragma warning disable CA1416 +#pragma warning disable CA1416 // Suppress Warning saying that WindowsPrincipal might not be compatible on Windows (Which shouldn't be an issue...) if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null))) -#pragma warning restore CA1416 +#pragma warning restore CA1416 // Suppress Warning saying that WindowsPrincipal might not be compatible on Windows (Which shouldn't be an issue...) { isPrivileged = false; Assert.True(true, "It seems that you don't have the permission to create symbolic links. Try to run this test again with higher privileges"); From 82a23fcd2beca928e4b80b3acde8ad0cbeb24492 Mon Sep 17 00:00:00 2001 From: Will Li Date: Wed, 3 Mar 2021 12:46:39 -0800 Subject: [PATCH 07/19] Adding unit tests --- .../ImportFromMSBuildExtensionsPath_Tests.cs | 51 +++++++++--- .../ToolsetConfigurationNet5_Tests.cs | 77 +++++++++++++++++++ .../Definition/ToolsetConfigurationReader.cs | 2 + 3 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index 1781342fefb..0185fbd7911 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -1,13 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_SYSTEM_CONFIGURATION -// NOTE: This test WOULD work in net5.0 after the System.Configuration.ConfigurationManager change. However, it would -// only work if ToolsetDefinitionLocations is set to ConfigurationFile and that ReadApplicationConfiguration in -// ToolsetConfigurationReader.cs removes the RunningTests condition since ConfigurationManager.OpenExeConfiguration -// would try to get testhost.exe.config instead of the actual configuration file. But those changes seems more -// fitting as a different test rather than making all these changes instead. - using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Exceptions; @@ -54,7 +47,11 @@ public void ImportFromExtensionsPathNotFound() extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), GetExtensionTargetsFileContent1()); mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistent"))); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -299,7 +296,11 @@ public void ImportFromExtensionsPathInvalidFile() extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), extnTargetsFileContent); mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistent"))); var logger = new MockLogger(); @@ -398,7 +399,11 @@ public void ImportFromExtensionsPathSearchOrder2() // MSBuildExtensionsPath* property value has highest priority for the lookups try { +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", Path.Combine("tmp", "non-existent"), extnDir1)); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -487,7 +492,12 @@ public void ImportFromExtensionsPathAnd32And64() ToolsetConfigurationReaderTestHelper.WriteConfigFile(String.Format(configFileContents, extnDir1, extnDir2, extnDir3)); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif + projColln.ResetToolsetsForTests(reader); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -561,7 +571,11 @@ public void ExpandExtensionsPathFallback() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); - var projectCollection = new ProjectCollection(new Dictionary {["FallbackExpandDir1"] = extnDir1}); +#if FEATURE_SYSTEM_CONFIGURATION + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -622,7 +636,11 @@ public void ExpandExtensionsPathFallbackInErrorMessage() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -692,7 +710,11 @@ public void FallbackImportWithIndirectReference() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -757,7 +779,11 @@ public void FallbackImportWithUndefinedProperty() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -816,7 +842,11 @@ public void FallbackImportWithFileNotFoundWhenPropertyNotDefined() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -867,7 +897,11 @@ void CreateAndBuildProjectForImportFromExtensionsPath(string extnPathPropertyNam Action action) { try { +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader(extnPathPropertyName, extnDirs)); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -979,4 +1013,3 @@ private ToolsetConfigurationReader GetStandardConfigurationReader() } } } -#endif diff --git a/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs new file mode 100644 index 00000000000..10927cbb41a --- /dev/null +++ b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#if !FEATURE_SYSTEM_CONFIGURATION +/* This test is designed especially to test Configuration parsing in net5.0 + * which means it WON'T work in net472 and thus we don't run it in net472 */ + +using Microsoft.Build.Evaluation; +using Microsoft.Build.Execution; + +using Xunit; +using System.Collections.Generic; + +namespace Microsoft.Build.UnitTests.Evaluation +{ + /// + /// Unit tests for MSBuild Net5.0 Configuration Parsing + /// + public class ToolsetConfigurationNet5Test + { + [Fact] + // The default ToolsetDefintionLocations is None, which results in only the local which results in only the several included + // paths such as SDK path and RoslynTargetPath and nothing else. This behavior is expected and the exact same as before. + public void ToolsetDefinitionLocationsIsDefault() + { + var projectCollection = new ProjectCollection(); + IDictionary toolsetProperties + = new Dictionary(); + + foreach (Toolset toolset in projectCollection.Toolsets) + { + foreach (KeyValuePair properties in toolset.Properties) + { + toolsetProperties[properties.Value.Name] = properties.Value.EvaluatedValue; + } + } + + Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath")); + Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath")); + Assert.Contains("net5.0", toolsetProperties["MSBuildSDKsPath"]); + Assert.Contains("net5.0", toolsetProperties["RoslynTargetsPath"]); + Assert.False(toolsetProperties.ContainsKey("VCTargetsPath")); + Assert.False(toolsetProperties.ContainsKey("MSBuildToolsRoot")); + Assert.False(toolsetProperties.ContainsKey("MSBuildExtensionsPath")); + } + + [Fact] + // With ToolsetDefintionLocations set to ConfigurationFile (Which would only happen in net5.0 if the user decides to set it). + // Most toolsets are available and the MsBuildTools and SDK paths are all in the net5.0 runtime. + public void ToolsetDefinitionLocationsIsConfiguration() + { + var projectCollection = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); + IDictionary toolsetProperties + = new Dictionary(); + + foreach (Toolset toolset in projectCollection.Toolsets) + { + foreach (KeyValuePair properties in toolset.Properties) + { + toolsetProperties[properties.Value.Name] = properties.Value.EvaluatedValue; + } + } + + Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath")); + Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath")); + Assert.Contains("net5.0", toolsetProperties["MSBuildSDKsPath"]); + Assert.Contains("net5.0", toolsetProperties["RoslynTargetsPath"]); + + Assert.True(toolsetProperties.ContainsKey("VCTargetsPath")); + Assert.True(toolsetProperties.ContainsKey("MSBuildToolsRoot")); + Assert.True(toolsetProperties.ContainsKey("MSBuildExtensionsPath")); + Assert.Contains("net5.0", toolsetProperties["VCTargetsPath"]); + Assert.Contains("net5.0", toolsetProperties["MSBuildExtensionsPath"]); + } + } +} +#endif diff --git a/src/Build/Definition/ToolsetConfigurationReader.cs b/src/Build/Definition/ToolsetConfigurationReader.cs index 52128c04fa6..2b586dd9fdf 100644 --- a/src/Build/Definition/ToolsetConfigurationReader.cs +++ b/src/Build/Definition/ToolsetConfigurationReader.cs @@ -253,7 +253,9 @@ private static Configuration ReadApplicationConfiguration() { // When running from the command-line or from VS, use the msbuild.exe.config file. if (BuildEnvironmentHelper.Instance.Mode != BuildEnvironmentMode.None && +#if FEATURE_SYSTEM_CONFIGURATION !BuildEnvironmentHelper.Instance.RunningTests && +#endif FileSystems.Default.FileExists(BuildEnvironmentHelper.Instance.CurrentMSBuildConfigurationFile)) { var configFile = new ExeConfigurationFileMap { ExeConfigFilename = BuildEnvironmentHelper.Instance.CurrentMSBuildConfigurationFile }; From 7570c02963ccdda85c537c19638b60360f92fa6d Mon Sep 17 00:00:00 2001 From: Will Li Date: Fri, 5 Feb 2021 12:57:11 -0800 Subject: [PATCH 08/19] ToolsetConfigurationReader compilable with net5.0 --- eng/Packages.props | 5 +++-- src/Build/Definition/ProjectCollection.cs | 6 ------ src/Build/Definition/ToolsetReader.cs | 8 -------- src/Build/Microsoft.Build.csproj | 6 +++--- src/Shared/FrameworkLocationHelper.cs | 6 ------ src/Shared/ToolsetElement.cs | 5 ----- src/Tasks.UnitTests/Copy_Tests.cs | 2 ++ src/Utilities/Microsoft.Build.Utilities.csproj | 3 +-- 8 files changed, 9 insertions(+), 32 deletions(-) diff --git a/eng/Packages.props b/eng/Packages.props index c4ae1af44ed..cd7d7ab9ce0 100644 --- a/eng/Packages.props +++ b/eng/Packages.props @@ -18,14 +18,15 @@ + - - + + diff --git a/src/Build/Definition/ProjectCollection.cs b/src/Build/Definition/ProjectCollection.cs index ec52f815e3d..88c7f74bca7 100644 --- a/src/Build/Definition/ProjectCollection.cs +++ b/src/Build/Definition/ProjectCollection.cs @@ -1729,7 +1729,6 @@ private void CreateLoggingService(int maxCPUCount, bool onlyLogCriticalEvents) _loggingService.OnlyLogCriticalEvents = onlyLogCriticalEvents; } -#if FEATURE_SYSTEM_CONFIGURATION /// /// Reset the toolsets using the provided toolset reader, used by unit tests /// @@ -1737,7 +1736,6 @@ internal void ResetToolsetsForTests(ToolsetConfigurationReader configurationRead { InitializeToolsetCollection(configReader:configurationReaderForTestsOnly); } -#endif #if FEATURE_WIN32_REGISTRY /// @@ -1757,9 +1755,7 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests #if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader = null, #endif -#if FEATURE_SYSTEM_CONFIGURATION ToolsetConfigurationReader configReader = null -#endif ) { _toolsets = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -1769,9 +1765,7 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests #if FEATURE_WIN32_REGISTRY registryReader, #endif -#if FEATURE_SYSTEM_CONFIGURATION configReader, -#endif EnvironmentProperties, _globalProperties, ToolsetLocations); _toolsetsVersion++; diff --git a/src/Build/Definition/ToolsetReader.cs b/src/Build/Definition/ToolsetReader.cs index 3bcf77e90aa..869b3318ea4 100644 --- a/src/Build/Definition/ToolsetReader.cs +++ b/src/Build/Definition/ToolsetReader.cs @@ -76,7 +76,6 @@ internal abstract class ToolsetReader get; } -#if FEATURE_WIN32_REGISTRY || FEATURE_SYSTEM_CONFIGURATION /// /// Gathers toolset data from the registry and configuration file, if any: /// allows you to specify which of the registry and configuration file to @@ -88,12 +87,9 @@ internal static string ReadAllToolsets(Dictionary toolsets, Pro #if FEATURE_WIN32_REGISTRY null, #endif -#if FEATURE_SYSTEM_CONFIGURATION null, -#endif environmentProperties, globalProperties, locations); } -#endif /// /// Gathers toolset data from the registry and configuration file, if any. @@ -105,9 +101,7 @@ internal static string ReadAllToolsets #if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader, #endif -#if FEATURE_SYSTEM_CONFIGURATION ToolsetConfigurationReader configurationReader, -#endif PropertyDictionary environmentProperties, PropertyDictionary globalProperties, ToolsetDefinitionLocations locations @@ -124,7 +118,6 @@ ToolsetDefinitionLocations locations string overrideTasksPathFromConfiguration = null; string defaultOverrideToolsVersionFromConfiguration = null; -#if FEATURE_SYSTEM_CONFIGURATION if ((locations & ToolsetDefinitionLocations.ConfigurationFile) == ToolsetDefinitionLocations.ConfigurationFile) { if (configurationReader == null) @@ -137,7 +130,6 @@ ToolsetDefinitionLocations locations initialProperties, true /* accumulate properties */, out overrideTasksPathFromConfiguration, out defaultOverrideToolsVersionFromConfiguration); } -#endif string defaultToolsVersionFromRegistry = null; string overrideTasksPathFromRegistry = null; diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index 01a5fd018d2..5ecbce9ebeb 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -31,6 +31,7 @@ + @@ -39,7 +40,6 @@ - @@ -419,8 +419,8 @@ - - + + true diff --git a/src/Shared/FrameworkLocationHelper.cs b/src/Shared/FrameworkLocationHelper.cs index bacbc95e936..8544c12acd2 100644 --- a/src/Shared/FrameworkLocationHelper.cs +++ b/src/Shared/FrameworkLocationHelper.cs @@ -4,17 +4,11 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -#if FEATURE_SYSTEM_CONFIGURATION -using System.Configuration; -#endif using System.IO; using System.Linq; using System.Runtime.Versioning; using Microsoft.Win32; -#if FEATURE_SYSTEM_CONFIGURATION -using PropertyElement = Microsoft.Build.Evaluation.ToolsetElement.PropertyElement; -#endif using Microsoft.Build.Shared.FileSystem; namespace Microsoft.Build.Shared diff --git a/src/Shared/ToolsetElement.cs b/src/Shared/ToolsetElement.cs index 7453ed33cb3..feb3acb6a5c 100644 --- a/src/Shared/ToolsetElement.cs +++ b/src/Shared/ToolsetElement.cs @@ -3,17 +3,13 @@ using System; using System.Collections.Generic; -#if FEATURE_SYSTEM_CONFIGURATION using System.Configuration; -#endif using System.IO; using Microsoft.Build.Collections; using Microsoft.Build.Shared; namespace Microsoft.Build.Evaluation { -#if FEATURE_SYSTEM_CONFIGURATION - /// /// Helper class for reading toolsets out of the configuration file. /// @@ -708,5 +704,4 @@ public string DefaultOverrideToolsVersion } } } -#endif } diff --git a/src/Tasks.UnitTests/Copy_Tests.cs b/src/Tasks.UnitTests/Copy_Tests.cs index edd0c80b6e4..b3591623fae 100644 --- a/src/Tasks.UnitTests/Copy_Tests.cs +++ b/src/Tasks.UnitTests/Copy_Tests.cs @@ -2397,7 +2397,9 @@ public void CopyToDestinationFolderWithSymbolicLinkCheck() if (NativeMethodsShared.IsWindows) { +#pragma warning disable CA1416 if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null))) +#pragma warning restore CA1416 { isPrivileged = false; Assert.True(true, "It seems that you don't have the permission to create symbolic links. Try to run this test again with higher privileges"); diff --git a/src/Utilities/Microsoft.Build.Utilities.csproj b/src/Utilities/Microsoft.Build.Utilities.csproj index 8c4526c39b6..87d1b12e2dc 100644 --- a/src/Utilities/Microsoft.Build.Utilities.csproj +++ b/src/Utilities/Microsoft.Build.Utilities.csproj @@ -22,12 +22,11 @@ + - - From ab9d9ed43e705f8f049319765298937f544c4170 Mon Sep 17 00:00:00 2001 From: Will Li Date: Fri, 5 Feb 2021 13:53:12 -0800 Subject: [PATCH 09/19] Allow some unit tests to run in net5.0 --- .../Definition/ToolsetConfigurationReader_Tests.cs | 3 --- .../Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs | 6 ------ .../Microsoft.Build.Engine.UnitTests.csproj | 8 ++------ 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs index db0593111e7..41bc1a70494 100644 --- a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs +++ b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs @@ -1,10 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_SYSTEM_CONFIGURATION using System.Configuration; -using Microsoft.Win32; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Execution; @@ -683,4 +681,3 @@ private ToolsetConfigurationReader GetStandardConfigurationReader() } } -#endif diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index da2f1fc518e..a8d17dde5c2 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -1,10 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_SYSTEM_CONFIGURATION - -using System.Configuration; -using Microsoft.Win32; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Exceptions; @@ -15,7 +11,6 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.Build.UnitTests; namespace Microsoft.Build.UnitTests.Evaluation { @@ -977,4 +972,3 @@ private ToolsetConfigurationReader GetStandardConfigurationReader() } } } -#endif diff --git a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj index 756dffdbd0e..a54a2b11812 100644 --- a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj +++ b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj @@ -1,4 +1,4 @@ - + $(RuntimeOutputTargetFrameworks) @@ -16,6 +16,7 @@ + @@ -44,17 +45,12 @@ TargetFramework=$(FullFrameworkTFM) TargetFramework=net5.0 - - true - - - From 8ec091ffcecf5af1e5856f71e02e2c167940dfc9 Mon Sep 17 00:00:00 2001 From: Will Li Date: Mon, 8 Feb 2021 15:56:45 -0800 Subject: [PATCH 10/19] Remove System.Configuration Reference completed --- .../Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs | 6 ++++++ src/MSBuild/MSBuild.csproj | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index a8d17dde5c2..da2f1fc518e 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -1,6 +1,10 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if FEATURE_SYSTEM_CONFIGURATION + +using System.Configuration; +using Microsoft.Win32; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Exceptions; @@ -11,6 +15,7 @@ using System; using System.Collections.Generic; using System.IO; +using Microsoft.Build.UnitTests; namespace Microsoft.Build.UnitTests.Evaluation { @@ -972,3 +977,4 @@ private ToolsetConfigurationReader GetStandardConfigurationReader() } } } +#endif diff --git a/src/MSBuild/MSBuild.csproj b/src/MSBuild/MSBuild.csproj index 7d990720a96..af98f64d8bc 100644 --- a/src/MSBuild/MSBuild.csproj +++ b/src/MSBuild/MSBuild.csproj @@ -221,12 +221,14 @@ PreserveNewest + + + - From b9d7dbafa85ee4cb378ae74978417e836bcd7f72 Mon Sep 17 00:00:00 2001 From: Will Li Date: Tue, 9 Feb 2021 13:02:04 -0800 Subject: [PATCH 11/19] Allow IntrinsicFunctions to run in all conditions --- src/Build/Evaluation/IntrinsicFunctions.cs | 32 ---------------------- 1 file changed, 32 deletions(-) diff --git a/src/Build/Evaluation/IntrinsicFunctions.cs b/src/Build/Evaluation/IntrinsicFunctions.cs index aa1cdeaa90b..2295b0d24ad 100644 --- a/src/Build/Evaluation/IntrinsicFunctions.cs +++ b/src/Build/Evaluation/IntrinsicFunctions.cs @@ -24,11 +24,9 @@ namespace Microsoft.Build.Evaluation /// internal static class IntrinsicFunctions { -#if FEATURE_WIN32_REGISTRY private static readonly object[] DefaultRegistryViews = new object[] { RegistryView.Default }; private static readonly Lazy RegistrySdkRegex = new Lazy(() => new Regex(@"^HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft SDKs\\Windows\\v(\d+\.\d+)$", RegexOptions.IgnoreCase)); -#endif // FEATURE_WIN32_REGISTRY private static readonly Lazy NuGetFramework = new Lazy(() => new NuGetFrameworkWrapper()); @@ -160,7 +158,6 @@ internal static int BitwiseNot(int first) return ~first; } -#if FEATURE_WIN32_REGISTRY /// /// Get the value of the registry key and value, default value is null /// @@ -259,33 +256,6 @@ internal static object GetRegistryValueFromView(string keyName, string valueName return result; } -#else // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - - /// - /// Get the value of the registry key and value, default value is null - /// - internal static object GetRegistryValue(string keyName, string valueName) - { - return null; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - } - - /// - /// Get the value of the registry key and value - /// - internal static object GetRegistryValue(string keyName, string valueName, object defaultValue) - { - return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - } - - /// - /// Get the value of the registry key from one of the RegistryView's specified - /// - internal static object GetRegistryValueFromView(string keyName, string valueName, object defaultValue, params object[] views) - { - return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - } -#endif - /// /// Given the absolute location of a file, and a disc location, returns relative file path to that disk location. /// Throws UriFormatException. @@ -571,7 +541,6 @@ internal static List __GetListTest() #endregion -#if FEATURE_WIN32_REGISTRY /// /// Following function will parse a keyName and returns the basekey for it. /// It will also store the subkey name in the out parameter. @@ -640,6 +609,5 @@ private static RegistryKey GetBaseKeyFromKeyName(string keyName, RegistryView vi return basekey; } -#endif } } From f2e10bd759ecdb3887914d70ad95a75b213a494d Mon Sep 17 00:00:00 2001 From: Will Li Date: Wed, 17 Feb 2021 13:11:19 -0800 Subject: [PATCH 12/19] Open up Registry as well --- src/Build/Definition/ProjectCollection.cs | 6 ------ src/Build/Definition/ToolsetReader.cs | 6 ------ src/Build/Definition/ToolsetRegistryReader.cs | 6 ------ src/Build/Utilities/RegistryKeyWrapper.cs | 6 ------ 4 files changed, 24 deletions(-) diff --git a/src/Build/Definition/ProjectCollection.cs b/src/Build/Definition/ProjectCollection.cs index 88c7f74bca7..9471945f4e3 100644 --- a/src/Build/Definition/ProjectCollection.cs +++ b/src/Build/Definition/ProjectCollection.cs @@ -1737,7 +1737,6 @@ internal void ResetToolsetsForTests(ToolsetConfigurationReader configurationRead InitializeToolsetCollection(configReader:configurationReaderForTestsOnly); } -#if FEATURE_WIN32_REGISTRY /// /// Reset the toolsets using the provided toolset reader, used by unit tests /// @@ -1745,16 +1744,13 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests { InitializeToolsetCollection(registryReader:registryReaderForTestsOnly); } -#endif /// /// Populate Toolsets with a dictionary of (toolset version, Toolset) /// using information from the registry and config file, if any. /// private void InitializeToolsetCollection( -#if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader = null, -#endif ToolsetConfigurationReader configReader = null ) { @@ -1762,9 +1758,7 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests // We only want our local toolset (as defined in MSBuild.exe.config) when we're operating locally... _defaultToolsVersion = ToolsetReader.ReadAllToolsets(_toolsets, -#if FEATURE_WIN32_REGISTRY registryReader, -#endif configReader, EnvironmentProperties, _globalProperties, ToolsetLocations); diff --git a/src/Build/Definition/ToolsetReader.cs b/src/Build/Definition/ToolsetReader.cs index 869b3318ea4..56591a93104 100644 --- a/src/Build/Definition/ToolsetReader.cs +++ b/src/Build/Definition/ToolsetReader.cs @@ -84,9 +84,7 @@ internal abstract class ToolsetReader internal static string ReadAllToolsets(Dictionary toolsets, PropertyDictionary environmentProperties, PropertyDictionary globalProperties, ToolsetDefinitionLocations locations) { return ReadAllToolsets(toolsets, -#if FEATURE_WIN32_REGISTRY null, -#endif null, environmentProperties, globalProperties, locations); } @@ -98,9 +96,7 @@ internal static string ReadAllToolsets(Dictionary toolsets, Pro internal static string ReadAllToolsets ( Dictionary toolsets, -#if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader, -#endif ToolsetConfigurationReader configurationReader, PropertyDictionary environmentProperties, PropertyDictionary globalProperties, @@ -137,7 +133,6 @@ ToolsetDefinitionLocations locations if ((locations & ToolsetDefinitionLocations.Registry) == ToolsetDefinitionLocations.Registry) { -#if FEATURE_WIN32_REGISTRY if (NativeMethodsShared.IsWindows || registryReader != null) { // If we haven't been provided a registry reader (i.e. unit tests), create one @@ -151,7 +146,6 @@ ToolsetDefinitionLocations locations out defaultOverrideToolsVersionFromRegistry); } else -#endif { var currentDir = BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory.TrimEnd(Path.DirectorySeparatorChar); var props = new PropertyDictionary(); diff --git a/src/Build/Definition/ToolsetRegistryReader.cs b/src/Build/Definition/ToolsetRegistryReader.cs index 7a083fbebbd..7b1bfc4dd76 100644 --- a/src/Build/Definition/ToolsetRegistryReader.cs +++ b/src/Build/Definition/ToolsetRegistryReader.cs @@ -1,13 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_WIN32_REGISTRY - -using Microsoft.Win32; using System; using System.Collections.Generic; -using System.IO; -using System.Security; using Microsoft.Build.Shared; using error = Microsoft.Build.Shared.ErrorUtilities; @@ -346,4 +341,3 @@ private static string GetValue(RegistryKeyWrapper wrapper, string valueName) } } } -#endif \ No newline at end of file diff --git a/src/Build/Utilities/RegistryKeyWrapper.cs b/src/Build/Utilities/RegistryKeyWrapper.cs index 5db9a22e37c..8ab3c88e6a9 100644 --- a/src/Build/Utilities/RegistryKeyWrapper.cs +++ b/src/Build/Utilities/RegistryKeyWrapper.cs @@ -1,12 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_WIN32_REGISTRY using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Security; using Microsoft.Build.Shared; using Microsoft.Win32; @@ -271,4 +266,3 @@ private void Dispose(bool disposing) } } } -#endif From 4b1343b8b3c992652a3d36ad3d31d02ec7769962 Mon Sep 17 00:00:00 2001 From: Will Li Date: Tue, 2 Mar 2021 14:17:26 -0800 Subject: [PATCH 13/19] Removing all FEATURE_SYSTEM_CONFIGURATION that aren't needed --- .../ToolsetConfigurationReader_Tests.cs | 1 - .../Definition/ToolsetReader_Tests.cs | 2 -- .../ImportFromMSBuildExtensionsPath_Tests.cs | 8 +++-- src/Build/Definition/ProjectCollection.cs | 10 ++++-- src/Build/Definition/ToolsetReader.cs | 6 ++++ src/Build/Definition/ToolsetRegistryReader.cs | 3 ++ src/Build/Evaluation/IntrinsicFunctions.cs | 34 ++++++++++++++++++- src/Build/Utilities/RegistryKeyWrapper.cs | 2 ++ src/MSBuild/XMake.cs | 2 -- src/Tasks.UnitTests/Copy_Tests.cs | 4 +-- 10 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs index 41bc1a70494..6babb127ce7 100644 --- a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs +++ b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. - using System.Configuration; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; diff --git a/src/Build.UnitTests/Definition/ToolsetReader_Tests.cs b/src/Build.UnitTests/Definition/ToolsetReader_Tests.cs index 2e44a4239a9..c90b546da38 100644 --- a/src/Build.UnitTests/Definition/ToolsetReader_Tests.cs +++ b/src/Build.UnitTests/Definition/ToolsetReader_Tests.cs @@ -3,9 +3,7 @@ using System; using System.Collections.Generic; -#if FEATURE_SYSTEM_CONFIGURATION using System.Configuration; -#endif using System.IO; using Microsoft.Build.Collections; diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index da2f1fc518e..1781342fefb 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -2,9 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #if FEATURE_SYSTEM_CONFIGURATION +// NOTE: This test WOULD work in net5.0 after the System.Configuration.ConfigurationManager change. However, it would +// only work if ToolsetDefinitionLocations is set to ConfigurationFile and that ReadApplicationConfiguration in +// ToolsetConfigurationReader.cs removes the RunningTests condition since ConfigurationManager.OpenExeConfiguration +// would try to get testhost.exe.config instead of the actual configuration file. But those changes seems more +// fitting as a different test rather than making all these changes instead. -using System.Configuration; -using Microsoft.Win32; using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Exceptions; @@ -15,7 +18,6 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.Build.UnitTests; namespace Microsoft.Build.UnitTests.Evaluation { diff --git a/src/Build/Definition/ProjectCollection.cs b/src/Build/Definition/ProjectCollection.cs index 9471945f4e3..a75a28c248a 100644 --- a/src/Build/Definition/ProjectCollection.cs +++ b/src/Build/Definition/ProjectCollection.cs @@ -1737,6 +1737,7 @@ internal void ResetToolsetsForTests(ToolsetConfigurationReader configurationRead InitializeToolsetCollection(configReader:configurationReaderForTestsOnly); } +#if FEATURE_WIN32_REGISTRY /// /// Reset the toolsets using the provided toolset reader, used by unit tests /// @@ -1744,13 +1745,16 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests { InitializeToolsetCollection(registryReader:registryReaderForTestsOnly); } +#endif /// /// Populate Toolsets with a dictionary of (toolset version, Toolset) /// using information from the registry and config file, if any. /// private void InitializeToolsetCollection( +#if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader = null, +#endif ToolsetConfigurationReader configReader = null ) { @@ -1758,7 +1762,9 @@ internal void ResetToolsetsForTests(ToolsetRegistryReader registryReaderForTests // We only want our local toolset (as defined in MSBuild.exe.config) when we're operating locally... _defaultToolsVersion = ToolsetReader.ReadAllToolsets(_toolsets, +#if FEATURE_WIN32_REGISTRY registryReader, +#endif configReader, EnvironmentProperties, _globalProperties, ToolsetLocations); @@ -2026,9 +2032,9 @@ public void IncludeTaskInputs() _includeTaskInputs = true; } - #endregion +#endregion - #region ILogger Members +#region ILogger Members /// /// The logger verbosity diff --git a/src/Build/Definition/ToolsetReader.cs b/src/Build/Definition/ToolsetReader.cs index 56591a93104..869b3318ea4 100644 --- a/src/Build/Definition/ToolsetReader.cs +++ b/src/Build/Definition/ToolsetReader.cs @@ -84,7 +84,9 @@ internal abstract class ToolsetReader internal static string ReadAllToolsets(Dictionary toolsets, PropertyDictionary environmentProperties, PropertyDictionary globalProperties, ToolsetDefinitionLocations locations) { return ReadAllToolsets(toolsets, +#if FEATURE_WIN32_REGISTRY null, +#endif null, environmentProperties, globalProperties, locations); } @@ -96,7 +98,9 @@ internal static string ReadAllToolsets(Dictionary toolsets, Pro internal static string ReadAllToolsets ( Dictionary toolsets, +#if FEATURE_WIN32_REGISTRY ToolsetRegistryReader registryReader, +#endif ToolsetConfigurationReader configurationReader, PropertyDictionary environmentProperties, PropertyDictionary globalProperties, @@ -133,6 +137,7 @@ ToolsetDefinitionLocations locations if ((locations & ToolsetDefinitionLocations.Registry) == ToolsetDefinitionLocations.Registry) { +#if FEATURE_WIN32_REGISTRY if (NativeMethodsShared.IsWindows || registryReader != null) { // If we haven't been provided a registry reader (i.e. unit tests), create one @@ -146,6 +151,7 @@ ToolsetDefinitionLocations locations out defaultOverrideToolsVersionFromRegistry); } else +#endif { var currentDir = BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory.TrimEnd(Path.DirectorySeparatorChar); var props = new PropertyDictionary(); diff --git a/src/Build/Definition/ToolsetRegistryReader.cs b/src/Build/Definition/ToolsetRegistryReader.cs index 7b1bfc4dd76..e2081dc5ad7 100644 --- a/src/Build/Definition/ToolsetRegistryReader.cs +++ b/src/Build/Definition/ToolsetRegistryReader.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if FEATURE_WIN32_REGISTRY + using System; using System.Collections.Generic; @@ -341,3 +343,4 @@ private static string GetValue(RegistryKeyWrapper wrapper, string valueName) } } } +#endif diff --git a/src/Build/Evaluation/IntrinsicFunctions.cs b/src/Build/Evaluation/IntrinsicFunctions.cs index 2295b0d24ad..46b0bb0a1ea 100644 --- a/src/Build/Evaluation/IntrinsicFunctions.cs +++ b/src/Build/Evaluation/IntrinsicFunctions.cs @@ -24,9 +24,11 @@ namespace Microsoft.Build.Evaluation /// internal static class IntrinsicFunctions { +#if FEATURE_WIN32_REGISTRY private static readonly object[] DefaultRegistryViews = new object[] { RegistryView.Default }; private static readonly Lazy RegistrySdkRegex = new Lazy(() => new Regex(@"^HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft SDKs\\Windows\\v(\d+\.\d+)$", RegexOptions.IgnoreCase)); +#endif // FEATURE_WIN32_REGISTRY private static readonly Lazy NuGetFramework = new Lazy(() => new NuGetFrameworkWrapper()); @@ -158,6 +160,7 @@ internal static int BitwiseNot(int first) return ~first; } +#if FEATURE_WIN32_REGISTRY /// /// Get the value of the registry key and value, default value is null /// @@ -256,6 +259,33 @@ internal static object GetRegistryValueFromView(string keyName, string valueName return result; } +#else // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + + /// + /// Get the value of the registry key and value, default value is null + /// + internal static object GetRegistryValue(string keyName, string valueName) + { + return null; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + } + + /// + /// Get the value of the registry key and value + /// + internal static object GetRegistryValue(string keyName, string valueName, object defaultValue) + { + return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + } + + /// + /// Get the value of the registry key from one of the RegistryView's specified + /// + internal static object GetRegistryValueFromView(string keyName, string valueName, object defaultValue, params object[] views) + { + return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + } +#endif + /// /// Given the absolute location of a file, and a disc location, returns relative file path to that disk location. /// Throws UriFormatException. @@ -539,8 +569,9 @@ internal static List __GetListTest() return new List { "A", "B", "C", "D" }; } -#endregion + #endregion +#if FEATURE_WIN32_REGISTRY /// /// Following function will parse a keyName and returns the basekey for it. /// It will also store the subkey name in the out parameter. @@ -609,5 +640,6 @@ private static RegistryKey GetBaseKeyFromKeyName(string keyName, RegistryView vi return basekey; } +#endif } } diff --git a/src/Build/Utilities/RegistryKeyWrapper.cs b/src/Build/Utilities/RegistryKeyWrapper.cs index 8ab3c88e6a9..c1503c698ef 100644 --- a/src/Build/Utilities/RegistryKeyWrapper.cs +++ b/src/Build/Utilities/RegistryKeyWrapper.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#if FEATURE_WIN32_REGISTRY using System; @@ -266,3 +267,4 @@ private void Dispose(bool disposing) } } } +#endif diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 7891c7923dd..f6e3bc27f4b 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -4,9 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; -#if FEATURE_SYSTEM_CONFIGURATION using System.Configuration; -#endif using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; diff --git a/src/Tasks.UnitTests/Copy_Tests.cs b/src/Tasks.UnitTests/Copy_Tests.cs index b3591623fae..6d48ace8c4b 100644 --- a/src/Tasks.UnitTests/Copy_Tests.cs +++ b/src/Tasks.UnitTests/Copy_Tests.cs @@ -2397,9 +2397,9 @@ public void CopyToDestinationFolderWithSymbolicLinkCheck() if (NativeMethodsShared.IsWindows) { -#pragma warning disable CA1416 +#pragma warning disable CA1416 // Suppress Warning saying that WindowsPrincipal might not be compatible on Windows (Which shouldn't be an issue...) if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null))) -#pragma warning restore CA1416 +#pragma warning restore CA1416 // Suppress Warning saying that WindowsPrincipal might not be compatible on Windows (Which shouldn't be an issue...) { isPrivileged = false; Assert.True(true, "It seems that you don't have the permission to create symbolic links. Try to run this test again with higher privileges"); From 1616a368b4b6bbac6c4795405860be70205828f6 Mon Sep 17 00:00:00 2001 From: Will Li Date: Wed, 3 Mar 2021 12:46:39 -0800 Subject: [PATCH 14/19] Adding unit tests --- .../ImportFromMSBuildExtensionsPath_Tests.cs | 51 +++++++++--- .../ToolsetConfigurationNet5_Tests.cs | 77 +++++++++++++++++++ .../Definition/ToolsetConfigurationReader.cs | 2 + 3 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index 1781342fefb..0185fbd7911 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -1,13 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if FEATURE_SYSTEM_CONFIGURATION -// NOTE: This test WOULD work in net5.0 after the System.Configuration.ConfigurationManager change. However, it would -// only work if ToolsetDefinitionLocations is set to ConfigurationFile and that ReadApplicationConfiguration in -// ToolsetConfigurationReader.cs removes the RunningTests condition since ConfigurationManager.OpenExeConfiguration -// would try to get testhost.exe.config instead of the actual configuration file. But those changes seems more -// fitting as a different test rather than making all these changes instead. - using Microsoft.Build.Collections; using Microsoft.Build.Evaluation; using Microsoft.Build.Exceptions; @@ -54,7 +47,11 @@ public void ImportFromExtensionsPathNotFound() extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), GetExtensionTargetsFileContent1()); mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistent"))); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -299,7 +296,11 @@ public void ImportFromExtensionsPathInvalidFile() extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), extnTargetsFileContent); mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistent"))); var logger = new MockLogger(); @@ -398,7 +399,11 @@ public void ImportFromExtensionsPathSearchOrder2() // MSBuildExtensionsPath* property value has highest priority for the lookups try { +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", Path.Combine("tmp", "non-existent"), extnDir1)); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -487,7 +492,12 @@ public void ImportFromExtensionsPathAnd32And64() ToolsetConfigurationReaderTestHelper.WriteConfigFile(String.Format(configFileContents, extnDir1, extnDir2, extnDir3)); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif + projColln.ResetToolsetsForTests(reader); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -561,7 +571,11 @@ public void ExpandExtensionsPathFallback() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); - var projectCollection = new ProjectCollection(new Dictionary {["FallbackExpandDir1"] = extnDir1}); +#if FEATURE_SYSTEM_CONFIGURATION + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -622,7 +636,11 @@ public void ExpandExtensionsPathFallbackInErrorMessage() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -692,7 +710,11 @@ public void FallbackImportWithIndirectReference() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -757,7 +779,11 @@ public void FallbackImportWithUndefinedProperty() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -816,7 +842,11 @@ public void FallbackImportWithFileNotFoundWhenPropertyNotDefined() ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); var reader = GetStandardConfigurationReader(); +#if FEATURE_SYSTEM_CONFIGURATION var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); +#else + var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); +#endif projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -867,7 +897,11 @@ void CreateAndBuildProjectForImportFromExtensionsPath(string extnPathPropertyNam Action action) { try { +#if FEATURE_SYSTEM_CONFIGURATION var projColln = new ProjectCollection(); +#else + var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader(extnPathPropertyName, extnDirs)); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -979,4 +1013,3 @@ private ToolsetConfigurationReader GetStandardConfigurationReader() } } } -#endif diff --git a/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs new file mode 100644 index 00000000000..10927cbb41a --- /dev/null +++ b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#if !FEATURE_SYSTEM_CONFIGURATION +/* This test is designed especially to test Configuration parsing in net5.0 + * which means it WON'T work in net472 and thus we don't run it in net472 */ + +using Microsoft.Build.Evaluation; +using Microsoft.Build.Execution; + +using Xunit; +using System.Collections.Generic; + +namespace Microsoft.Build.UnitTests.Evaluation +{ + /// + /// Unit tests for MSBuild Net5.0 Configuration Parsing + /// + public class ToolsetConfigurationNet5Test + { + [Fact] + // The default ToolsetDefintionLocations is None, which results in only the local which results in only the several included + // paths such as SDK path and RoslynTargetPath and nothing else. This behavior is expected and the exact same as before. + public void ToolsetDefinitionLocationsIsDefault() + { + var projectCollection = new ProjectCollection(); + IDictionary toolsetProperties + = new Dictionary(); + + foreach (Toolset toolset in projectCollection.Toolsets) + { + foreach (KeyValuePair properties in toolset.Properties) + { + toolsetProperties[properties.Value.Name] = properties.Value.EvaluatedValue; + } + } + + Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath")); + Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath")); + Assert.Contains("net5.0", toolsetProperties["MSBuildSDKsPath"]); + Assert.Contains("net5.0", toolsetProperties["RoslynTargetsPath"]); + Assert.False(toolsetProperties.ContainsKey("VCTargetsPath")); + Assert.False(toolsetProperties.ContainsKey("MSBuildToolsRoot")); + Assert.False(toolsetProperties.ContainsKey("MSBuildExtensionsPath")); + } + + [Fact] + // With ToolsetDefintionLocations set to ConfigurationFile (Which would only happen in net5.0 if the user decides to set it). + // Most toolsets are available and the MsBuildTools and SDK paths are all in the net5.0 runtime. + public void ToolsetDefinitionLocationsIsConfiguration() + { + var projectCollection = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); + IDictionary toolsetProperties + = new Dictionary(); + + foreach (Toolset toolset in projectCollection.Toolsets) + { + foreach (KeyValuePair properties in toolset.Properties) + { + toolsetProperties[properties.Value.Name] = properties.Value.EvaluatedValue; + } + } + + Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath")); + Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath")); + Assert.Contains("net5.0", toolsetProperties["MSBuildSDKsPath"]); + Assert.Contains("net5.0", toolsetProperties["RoslynTargetsPath"]); + + Assert.True(toolsetProperties.ContainsKey("VCTargetsPath")); + Assert.True(toolsetProperties.ContainsKey("MSBuildToolsRoot")); + Assert.True(toolsetProperties.ContainsKey("MSBuildExtensionsPath")); + Assert.Contains("net5.0", toolsetProperties["VCTargetsPath"]); + Assert.Contains("net5.0", toolsetProperties["MSBuildExtensionsPath"]); + } + } +} +#endif diff --git a/src/Build/Definition/ToolsetConfigurationReader.cs b/src/Build/Definition/ToolsetConfigurationReader.cs index 52128c04fa6..2b586dd9fdf 100644 --- a/src/Build/Definition/ToolsetConfigurationReader.cs +++ b/src/Build/Definition/ToolsetConfigurationReader.cs @@ -253,7 +253,9 @@ private static Configuration ReadApplicationConfiguration() { // When running from the command-line or from VS, use the msbuild.exe.config file. if (BuildEnvironmentHelper.Instance.Mode != BuildEnvironmentMode.None && +#if FEATURE_SYSTEM_CONFIGURATION !BuildEnvironmentHelper.Instance.RunningTests && +#endif FileSystems.Default.FileExists(BuildEnvironmentHelper.Instance.CurrentMSBuildConfigurationFile)) { var configFile = new ExeConfigurationFileMap { ExeConfigFilename = BuildEnvironmentHelper.Instance.CurrentMSBuildConfigurationFile }; From da88865f5b1dc7d949150a4957dfeabafa7df609 Mon Sep 17 00:00:00 2001 From: Will Li Date: Wed, 3 Mar 2021 13:15:37 -0800 Subject: [PATCH 15/19] Fixing whitespaces --- src/Build/Definition/ProjectCollection.cs | 4 +-- .../Definition/ToolsetConfigurationReader.cs | 2 ++ src/Build/Evaluation/IntrinsicFunctions.cs | 26 +++++++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Build/Definition/ProjectCollection.cs b/src/Build/Definition/ProjectCollection.cs index a75a28c248a..88c7f74bca7 100644 --- a/src/Build/Definition/ProjectCollection.cs +++ b/src/Build/Definition/ProjectCollection.cs @@ -2032,9 +2032,9 @@ public void IncludeTaskInputs() _includeTaskInputs = true; } -#endregion + #endregion -#region ILogger Members + #region ILogger Members /// /// The logger verbosity diff --git a/src/Build/Definition/ToolsetConfigurationReader.cs b/src/Build/Definition/ToolsetConfigurationReader.cs index 2b586dd9fdf..5b54d856b43 100644 --- a/src/Build/Definition/ToolsetConfigurationReader.cs +++ b/src/Build/Definition/ToolsetConfigurationReader.cs @@ -253,6 +253,8 @@ private static Configuration ReadApplicationConfiguration() { // When running from the command-line or from VS, use the msbuild.exe.config file. if (BuildEnvironmentHelper.Instance.Mode != BuildEnvironmentMode.None && + // This FEATURE_SYSTEM_CONFIGURATION is needed as OpenExeConfiguration for net5.0 works differently, without this condition unit tests won't pass. + // OpenExeConfiguration in net5.0 will return testhost.exe which does not contain any configuration and therefore fail. #if FEATURE_SYSTEM_CONFIGURATION !BuildEnvironmentHelper.Instance.RunningTests && #endif diff --git a/src/Build/Evaluation/IntrinsicFunctions.cs b/src/Build/Evaluation/IntrinsicFunctions.cs index 46b0bb0a1ea..3bdb5d398c1 100644 --- a/src/Build/Evaluation/IntrinsicFunctions.cs +++ b/src/Build/Evaluation/IntrinsicFunctions.cs @@ -259,30 +259,30 @@ internal static object GetRegistryValueFromView(string keyName, string valueName return result; } -#else // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors +#else // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors - /// - /// Get the value of the registry key and value, default value is null - /// + /// + /// Get the value of the registry key and value, default value is null + /// internal static object GetRegistryValue(string keyName, string valueName) { return null; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors } - /// - /// Get the value of the registry key and value - /// + /// + /// Get the value of the registry key and value + /// internal static object GetRegistryValue(string keyName, string valueName, object defaultValue) { - return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors } - /// - /// Get the value of the registry key from one of the RegistryView's specified - /// + /// + /// Get the value of the registry key from one of the RegistryView's specified + /// internal static object GetRegistryValueFromView(string keyName, string valueName, object defaultValue, params object[] views) { - return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + return defaultValue; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors } #endif @@ -569,7 +569,7 @@ internal static List __GetListTest() return new List { "A", "B", "C", "D" }; } - #endregion +#endregion #if FEATURE_WIN32_REGISTRY /// From dbc1236d01b99a438b511606bcb9a98b51bd5133 Mon Sep 17 00:00:00 2001 From: Will Li Date: Wed, 3 Mar 2021 13:17:39 -0800 Subject: [PATCH 16/19] Fixing comment and more whitespace --- src/Build/Definition/ToolsetConfigurationReader.cs | 2 +- src/Build/Evaluation/IntrinsicFunctions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Build/Definition/ToolsetConfigurationReader.cs b/src/Build/Definition/ToolsetConfigurationReader.cs index 5b54d856b43..5665b1aaf09 100644 --- a/src/Build/Definition/ToolsetConfigurationReader.cs +++ b/src/Build/Definition/ToolsetConfigurationReader.cs @@ -254,7 +254,7 @@ private static Configuration ReadApplicationConfiguration() // When running from the command-line or from VS, use the msbuild.exe.config file. if (BuildEnvironmentHelper.Instance.Mode != BuildEnvironmentMode.None && // This FEATURE_SYSTEM_CONFIGURATION is needed as OpenExeConfiguration for net5.0 works differently, without this condition unit tests won't pass. - // OpenExeConfiguration in net5.0 will return testhost.exe which does not contain any configuration and therefore fail. + // ConfigurationManager.OpenExeConfiguration in net5.0 will find testhost.exe instead which does not contain any configuration and therefore fail. #if FEATURE_SYSTEM_CONFIGURATION !BuildEnvironmentHelper.Instance.RunningTests && #endif diff --git a/src/Build/Evaluation/IntrinsicFunctions.cs b/src/Build/Evaluation/IntrinsicFunctions.cs index 3bdb5d398c1..aa1cdeaa90b 100644 --- a/src/Build/Evaluation/IntrinsicFunctions.cs +++ b/src/Build/Evaluation/IntrinsicFunctions.cs @@ -266,7 +266,7 @@ internal static object GetRegistryValueFromView(string keyName, string valueName /// internal static object GetRegistryValue(string keyName, string valueName) { - return null; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors + return null; // FEATURE_WIN32_REGISTRY is off, need to mock the function names to let scrips call these property functions and get NULLs rather than fail with errors } /// From 7e4ab7240ee26720dd79bfe3525d7483e3f30cc7 Mon Sep 17 00:00:00 2001 From: Will Li Date: Wed, 3 Mar 2021 16:49:45 -0800 Subject: [PATCH 17/19] Unit test + package version update --- eng/Packages.props | 6 +++--- .../Evaluation/ToolsetConfigurationNet5_Tests.cs | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/eng/Packages.props b/eng/Packages.props index cd7d7ab9ce0..97f340790f5 100644 --- a/eng/Packages.props +++ b/eng/Packages.props @@ -18,15 +18,15 @@ - + - - + + diff --git a/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs index 10927cbb41a..2ea0bfc25f1 100644 --- a/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs @@ -37,8 +37,9 @@ public void ToolsetDefinitionLocationsIsDefault() Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath")); Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath")); - Assert.Contains("net5.0", toolsetProperties["MSBuildSDKsPath"]); - Assert.Contains("net5.0", toolsetProperties["RoslynTargetsPath"]); + Assert.NotEqual(string.Empty, toolsetProperties["MSBuildSDKsPath"]); + Assert.NotEqual(string.Empty, toolsetProperties["RoslynTargetsPath"]); + Assert.False(toolsetProperties.ContainsKey("VCTargetsPath")); Assert.False(toolsetProperties.ContainsKey("MSBuildToolsRoot")); Assert.False(toolsetProperties.ContainsKey("MSBuildExtensionsPath")); @@ -63,14 +64,15 @@ public void ToolsetDefinitionLocationsIsConfiguration() Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath")); Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath")); - Assert.Contains("net5.0", toolsetProperties["MSBuildSDKsPath"]); - Assert.Contains("net5.0", toolsetProperties["RoslynTargetsPath"]); + Assert.NotEqual(string.Empty, toolsetProperties["MSBuildSDKsPath"]); + Assert.NotEqual(string.Empty, toolsetProperties["RoslynTargetsPath"]); Assert.True(toolsetProperties.ContainsKey("VCTargetsPath")); Assert.True(toolsetProperties.ContainsKey("MSBuildToolsRoot")); Assert.True(toolsetProperties.ContainsKey("MSBuildExtensionsPath")); - Assert.Contains("net5.0", toolsetProperties["VCTargetsPath"]); - Assert.Contains("net5.0", toolsetProperties["MSBuildExtensionsPath"]); + Assert.NotEqual(string.Empty, toolsetProperties["VCTargetsPath"]); + Assert.NotEqual(string.Empty, toolsetProperties["MSBuildToolsRoot"]); + Assert.NotEqual(string.Empty, toolsetProperties["MSBuildExtensionsPath"]); } } } From a5d1939880c8137d62b74cc2389e6e8a37bea8d3 Mon Sep 17 00:00:00 2001 From: Will Li Date: Mon, 8 Mar 2021 10:18:51 -0800 Subject: [PATCH 18/19] Addressing PR comments --- .../ImportFromMSBuildExtensionsPath_Tests.cs | 158 +++++++++--------- .../ToolsetConfigurationNet5_Tests.cs | 35 ++-- 2 files changed, 99 insertions(+), 94 deletions(-) diff --git a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs index 0185fbd7911..bfcf5685dc2 100644 --- a/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ImportFromMSBuildExtensionsPath_Tests.cs @@ -43,15 +43,13 @@ public void ImportFromExtensionsPathNotFound() string extnDir1 = null; string mainProjectPath = null; - try { + try + { extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), GetExtensionTargetsFileContent1()); mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); -#if FEATURE_SYSTEM_CONFIGURATION - var projColln = new ProjectCollection(); -#else - var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); -#endif + var projColln = GetProjectCollection(); + projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistent"))); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -59,7 +57,9 @@ public void ImportFromExtensionsPathNotFound() Assert.Throws(() => projColln.LoadProject(mainProjectPath)); logger.AssertLogContains("MSB4226"); - } finally { + } + finally + { if (mainProjectPath != null) { FileUtilities.DeleteNoThrow(mainProjectPath); @@ -90,7 +90,7 @@ public void ConditionalImportFromExtensionsPathNotFound() string extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), extnTargetsFileContentWithCondition); string mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); - CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, "MSBuildExtensionsPath", new string[] {extnDir1, Path.Combine("tmp", "nonexistent")}, + CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, "MSBuildExtensionsPath", new string[] { extnDir1, Path.Combine("tmp", "nonexistent") }, null, (p, l) => { Assert.True(p.Build()); @@ -127,7 +127,7 @@ public void ImportFromExtensionsPathCircularImportError() String.Format(extnTargetsFileContent2, mainProjectPath)); CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, "MSBuildExtensionsPath", - new string[] {extnDir2, Path.Combine("tmp", "nonexistent"), extnDir1}, + new string[] { extnDir2, Path.Combine("tmp", "nonexistent"), extnDir1 }, null, (p, l) => l.AssertLogContains("MSB4210")); } @@ -198,7 +198,7 @@ public void ImportFromExtensionsPathWithWildCard() string mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", mainTargetsFileContent); CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, "MSBuildExtensionsPath", - new[] {extnDir1, Path.Combine("tmp", "nonexistent"), extnDir2}, + new[] { extnDir1, Path.Combine("tmp", "nonexistent"), extnDir2 }, null, (project, logger) => { @@ -280,7 +280,7 @@ public void ImportFromExtensionsPathWithWildCardNothingFound() string extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), extnTargetsFileContent); string mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); - CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, "MSBuildExtensionsPath", new string[] {Path.Combine("tmp", "nonexistent"), extnDir1}, + CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, "MSBuildExtensionsPath", new string[] { Path.Combine("tmp", "nonexistent"), extnDir1 }, null, (p, l) => Assert.True(p.Build())); } @@ -292,15 +292,12 @@ public void ImportFromExtensionsPathInvalidFile() string extnDir1 = null; string mainProjectPath = null; - try { + try + { extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), extnTargetsFileContent); mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); -#if FEATURE_SYSTEM_CONFIGURATION - var projColln = new ProjectCollection(); -#else - var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); -#endif + var projColln = GetProjectCollection(); projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistent"))); var logger = new MockLogger(); @@ -308,7 +305,9 @@ public void ImportFromExtensionsPathInvalidFile() Assert.Throws(() => projColln.LoadProject(mainProjectPath)); logger.AssertLogContains("MSB4024"); - } finally { + } + finally + { if (mainProjectPath != null) { FileUtilities.DeleteNoThrow(mainProjectPath); @@ -354,7 +353,7 @@ public void ImportFromExtensionsPathSearchOrder() string extnDir2 = GetNewExtensionsPathAndCreateFile("extensions2", Path.Combine("foo", "extn.proj"), extnTargetsFileContent2); string mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); - CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, "MSBuildExtensionsPath", new string[] {extnDir2, Path.Combine("tmp", "nonexistent"), extnDir1}, + CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, "MSBuildExtensionsPath", new string[] { extnDir2, Path.Combine("tmp", "nonexistent"), extnDir1 }, null, (p, l) => { Assert.True(p.Build()); @@ -398,12 +397,9 @@ public void ImportFromExtensionsPathSearchOrder2() string mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); // MSBuildExtensionsPath* property value has highest priority for the lookups - try { -#if FEATURE_SYSTEM_CONFIGURATION - var projColln = new ProjectCollection(); -#else - var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); -#endif + try + { + var projColln = GetProjectCollection(); projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", Path.Combine("tmp", "non-existent"), extnDir1)); var logger = new MockLogger(); projColln.RegisterLogger(logger); @@ -415,7 +411,9 @@ public void ImportFromExtensionsPathSearchOrder2() logger.AssertLogContains("Running FromExtn"); logger.AssertLogContains("PropertyFromExtn1: FromSecondFile"); - } finally { + } + finally + { if (mainProjectPath != null) { FileUtilities.DeleteNoThrow(mainProjectPath); @@ -479,7 +477,8 @@ public void ImportFromExtensionsPathAnd32And64() string extnDir1 = null, extnDir2 = null, extnDir3 = null; string mainProjectPath = null; - try { + try + { extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), String.Format(extnTargetsFileContentTemplate, String.Empty, "FromExtn2", "")); extnDir2 = GetNewExtensionsPathAndCreateFile("extensions2", Path.Combine("bar", "extn2.proj"), @@ -490,13 +489,9 @@ public void ImportFromExtensionsPathAnd32And64() mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent()); ToolsetConfigurationReaderTestHelper.WriteConfigFile(String.Format(configFileContents, extnDir1, extnDir2, extnDir3)); - var reader = GetStandardConfigurationReader(); -#if FEATURE_SYSTEM_CONFIGURATION - var projColln = new ProjectCollection(); -#else - var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); -#endif + var reader = GetStandardConfigurationReader(); + var projColln = GetProjectCollection(); projColln.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -507,7 +502,9 @@ public void ImportFromExtensionsPathAnd32And64() logger.AssertLogContains("Running FromExtn3"); logger.AssertLogContains("Running FromExtn2"); logger.AssertLogContains("Running FromExtn"); - } finally { + } + finally + { if (mainProjectPath != null) { FileUtilities.DeleteNoThrow(mainProjectPath); @@ -569,13 +566,9 @@ public void ExpandExtensionsPathFallback() GetMainTargetFileContent()); ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); - var reader = GetStandardConfigurationReader(); -#if FEATURE_SYSTEM_CONFIGURATION - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); -#else - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); -#endif + var reader = GetStandardConfigurationReader(); + var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -634,13 +627,9 @@ public void ExpandExtensionsPathFallbackInErrorMessage() GetMainTargetFileContent()); ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); - var reader = GetStandardConfigurationReader(); -#if FEATURE_SYSTEM_CONFIGURATION - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); -#else - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); -#endif + var reader = GetStandardConfigurationReader(); + var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -708,13 +697,9 @@ public void FallbackImportWithIndirectReference() mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", mainTargetsFileContent); ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); - var reader = GetStandardConfigurationReader(); -#if FEATURE_SYSTEM_CONFIGURATION - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); -#else - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); -#endif + var reader = GetStandardConfigurationReader(); + var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -777,13 +762,9 @@ public void FallbackImportWithUndefinedProperty() mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", mainTargetsFileContent); ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); - var reader = GetStandardConfigurationReader(); -#if FEATURE_SYSTEM_CONFIGURATION - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); -#else - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); -#endif + var reader = GetStandardConfigurationReader(); + var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -840,13 +821,9 @@ public void FallbackImportWithFileNotFoundWhenPropertyNotDefined() mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", mainTargetsFileContent); ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents); - var reader = GetStandardConfigurationReader(); -#if FEATURE_SYSTEM_CONFIGURATION - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); -#else - var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }, null, ToolsetDefinitionLocations.ConfigurationFile); -#endif + var reader = GetStandardConfigurationReader(); + var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 }); projectCollection.ResetToolsetsForTests(reader); var logger = new MockLogger(); @@ -866,7 +843,8 @@ public void FallbackImportWithFileNotFoundWhenPropertyNotDefined() void CreateAndBuildProjectForImportFromExtensionsPath(string extnPathPropertyName, Action action) { string extnDir1 = null, extnDir2 = null, mainProjectPath = null; - try { + try + { extnDir1 = GetNewExtensionsPathAndCreateFile("extensions1", Path.Combine("foo", "extn.proj"), GetExtensionTargetsFileContent1(extnPathPropertyName)); extnDir2 = GetNewExtensionsPathAndCreateFile("extensions2", Path.Combine("bar", "extn2.proj"), @@ -874,10 +852,12 @@ void CreateAndBuildProjectForImportFromExtensionsPath(string extnPathPropertyNam mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent(extnPathPropertyName)); - CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, extnPathPropertyName, new string[] {extnDir1, extnDir2}, + CreateAndBuildProjectForImportFromExtensionsPath(mainProjectPath, extnPathPropertyName, new string[] { extnDir1, extnDir2 }, null, action); - } finally { + } + finally + { if (extnDir1 != null) { FileUtilities.DeleteDirectoryNoThrow(extnDir1, recursive: true); @@ -896,19 +876,19 @@ void CreateAndBuildProjectForImportFromExtensionsPath(string extnPathPropertyNam void CreateAndBuildProjectForImportFromExtensionsPath(string mainProjectPath, string extnPathPropertyName, string[] extnDirs, Action setExtensionsPath, Action action) { - try { -#if FEATURE_SYSTEM_CONFIGURATION - var projColln = new ProjectCollection(); -#else - var projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); -#endif + try + { + var projColln = GetProjectCollection(); + projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader(extnPathPropertyName, extnDirs)); var logger = new MockLogger(); projColln.RegisterLogger(logger); var project = projColln.LoadProject(mainProjectPath); action(project, logger); - } finally { + } + finally + { if (mainProjectPath != null) { FileUtilities.DeleteNoThrow(mainProjectPath); @@ -949,6 +929,30 @@ private ToolsetConfigurationReader WriteConfigFileAndGetReader(string extnPathPr return GetStandardConfigurationReader(); } + private ProjectCollection GetProjectCollection(IDictionary globalProperties = null) + { + ProjectCollection projColln; + + if (globalProperties == null) + { +#if FEATURE_SYSTEM_CONFIGURATION + projColln = new ProjectCollection(); +#else + projColln = new ProjectCollection(ToolsetDefinitionLocations.ConfigurationFile); +#endif + } + else + { +#if FEATURE_SYSTEM_CONFIGURATION + projColln = new ProjectCollection(globalProperties); +#else + projColln = new ProjectCollection(globalProperties, loggers: null, ToolsetDefinitionLocations.ConfigurationFile); +#endif + } + + return projColln; + } + string GetNewExtensionsPathAndCreateFile(string extnDirName, string relativeFilePath, string fileContents) { var extnDir = Path.Combine(ObjectModelHelpers.TempProjectDir, extnDirName); @@ -958,7 +962,7 @@ string GetNewExtensionsPathAndCreateFile(string extnDirName, string relativeFile return extnDir; } - string GetMainTargetFileContent(string extensionsPathPropertyName="MSBuildExtensionsPath") + string GetMainTargetFileContent(string extensionsPathPropertyName = "MSBuildExtensionsPath") { string mainTargetsFileContent = @" @@ -972,7 +976,7 @@ string GetMainTargetFileContent(string extensionsPathPropertyName="MSBuildExtens return String.Format(mainTargetsFileContent, extensionsPathPropertyName); } - string GetExtensionTargetsFileContent1(string extensionsPathPropertyName="MSBuildExtensionsPath") + string GetExtensionTargetsFileContent1(string extensionsPathPropertyName = "MSBuildExtensionsPath") { string extnTargetsFileContent1 = @" @@ -990,7 +994,7 @@ string GetExtensionTargetsFileContent1(string extensionsPathPropertyName="MSBuil return String.Format(extnTargetsFileContent1, extensionsPathPropertyName); } - string GetExtensionTargetsFileContent2(string extensionsPathPropertyName="MSBuildExtensionsPath") + string GetExtensionTargetsFileContent2(string extensionsPathPropertyName = "MSBuildExtensionsPath") { string extnTargetsFileContent2 = @" diff --git a/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs index 2ea0bfc25f1..298cf5ff37f 100644 --- a/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs +++ b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs @@ -10,6 +10,7 @@ using Xunit; using System.Collections.Generic; +using Shouldly; namespace Microsoft.Build.UnitTests.Evaluation { @@ -35,14 +36,14 @@ public void ToolsetDefinitionLocationsIsDefault() } } - Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath")); - Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath")); - Assert.NotEqual(string.Empty, toolsetProperties["MSBuildSDKsPath"]); - Assert.NotEqual(string.Empty, toolsetProperties["RoslynTargetsPath"]); + toolsetProperties.ShouldContainKey("MSBuildSDKsPath"); + toolsetProperties.ShouldContainKey("RoslynTargetsPath"); + toolsetProperties["MSBuildSDKsPath"].ShouldNotBeNullOrEmpty(); + toolsetProperties["RoslynTargetsPath"].ShouldNotBeNullOrEmpty(); - Assert.False(toolsetProperties.ContainsKey("VCTargetsPath")); - Assert.False(toolsetProperties.ContainsKey("MSBuildToolsRoot")); - Assert.False(toolsetProperties.ContainsKey("MSBuildExtensionsPath")); + toolsetProperties.ShouldNotContainKey("VCTargetsPath"); + toolsetProperties.ShouldNotContainKey("MSBuildToolsRoot"); + toolsetProperties.ShouldNotContainKey("MSBuildExtensionsPath"); } [Fact] @@ -62,17 +63,17 @@ public void ToolsetDefinitionLocationsIsConfiguration() } } - Assert.True(toolsetProperties.ContainsKey("MSBuildSDKsPath")); - Assert.True(toolsetProperties.ContainsKey("RoslynTargetsPath")); - Assert.NotEqual(string.Empty, toolsetProperties["MSBuildSDKsPath"]); - Assert.NotEqual(string.Empty, toolsetProperties["RoslynTargetsPath"]); + toolsetProperties.ShouldContainKey("MSBuildSDKsPath"); + toolsetProperties.ShouldContainKey("RoslynTargetsPath"); + toolsetProperties["MSBuildSDKsPath"].ShouldNotBeNullOrEmpty(); + toolsetProperties["RoslynTargetsPath"].ShouldNotBeNullOrEmpty(); - Assert.True(toolsetProperties.ContainsKey("VCTargetsPath")); - Assert.True(toolsetProperties.ContainsKey("MSBuildToolsRoot")); - Assert.True(toolsetProperties.ContainsKey("MSBuildExtensionsPath")); - Assert.NotEqual(string.Empty, toolsetProperties["VCTargetsPath"]); - Assert.NotEqual(string.Empty, toolsetProperties["MSBuildToolsRoot"]); - Assert.NotEqual(string.Empty, toolsetProperties["MSBuildExtensionsPath"]); + toolsetProperties.ShouldContainKey("VCTargetsPath"); + toolsetProperties.ShouldContainKey("MSBuildToolsRoot"); + toolsetProperties.ShouldContainKey("MSBuildExtensionsPath"); + toolsetProperties["VCTargetsPath"].ShouldNotBeNullOrEmpty(); + toolsetProperties["MSBuildToolsRoot"].ShouldNotBeNullOrEmpty(); + toolsetProperties["MSBuildExtensionsPath"].ShouldNotBeNullOrEmpty(); } } } From 6989bc1649778912860f13cd58be46323689efbe Mon Sep 17 00:00:00 2001 From: Will Li Date: Mon, 8 Mar 2021 16:06:08 -0800 Subject: [PATCH 19/19] Fix BOM change --- src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj index a54a2b11812..52f699668fb 100644 --- a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj +++ b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj @@ -1,4 +1,4 @@ - + $(RuntimeOutputTargetFrameworks)