diff --git a/eng/Packages.props b/eng/Packages.props
index c4ae1af44ed..97f340790f5 100644
--- a/eng/Packages.props
+++ b/eng/Packages.props
@@ -18,6 +18,7 @@
+
diff --git a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs
index db0593111e7..6babb127ce7 100644
--- a/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs
+++ b/src/Build.UnitTests/Definition/ToolsetConfigurationReader_Tests.cs
@@ -1,10 +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_SYSTEM_CONFIGURATION
-
using System.Configuration;
-using Microsoft.Win32;
using Microsoft.Build.Collections;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
@@ -683,4 +680,3 @@ private ToolsetConfigurationReader GetStandardConfigurationReader()
}
}
-#endif
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..bfcf5685dc2 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
{
@@ -48,11 +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());
- var projColln = new ProjectCollection();
+ var projColln = GetProjectCollection();
+
projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1, Path.Combine("tmp", "nonexistent")));
var logger = new MockLogger();
projColln.RegisterLogger(logger);
@@ -60,7 +57,9 @@ public void ImportFromExtensionsPathNotFound()
Assert.Throws(() => projColln.LoadProject(mainProjectPath));
logger.AssertLogContains("MSB4226");
- } finally {
+ }
+ finally
+ {
if (mainProjectPath != null)
{
FileUtilities.DeleteNoThrow(mainProjectPath);
@@ -91,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());
@@ -128,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"));
}
@@ -199,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) =>
{
@@ -281,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()));
}
@@ -293,11 +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());
- var projColln = new ProjectCollection();
+ var projColln = GetProjectCollection();
projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", extnDir1,
Path.Combine("tmp", "nonexistent")));
var logger = new MockLogger();
@@ -305,7 +305,9 @@ public void ImportFromExtensionsPathInvalidFile()
Assert.Throws(() => projColln.LoadProject(mainProjectPath));
logger.AssertLogContains("MSB4024");
- } finally {
+ }
+ finally
+ {
if (mainProjectPath != null)
{
FileUtilities.DeleteNoThrow(mainProjectPath);
@@ -351,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());
@@ -395,8 +397,9 @@ public void ImportFromExtensionsPathSearchOrder2()
string mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent());
// MSBuildExtensionsPath* property value has highest priority for the lookups
- try {
- var projColln = new ProjectCollection();
+ try
+ {
+ var projColln = GetProjectCollection();
projColln.ResetToolsetsForTests(WriteConfigFileAndGetReader("MSBuildExtensionsPath", Path.Combine("tmp", "non-existent"), extnDir1));
var logger = new MockLogger();
projColln.RegisterLogger(logger);
@@ -408,7 +411,9 @@ public void ImportFromExtensionsPathSearchOrder2()
logger.AssertLogContains("Running FromExtn");
logger.AssertLogContains("PropertyFromExtn1: FromSecondFile");
- } finally {
+ }
+ finally
+ {
if (mainProjectPath != null)
{
FileUtilities.DeleteNoThrow(mainProjectPath);
@@ -472,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"),
@@ -483,9 +489,10 @@ public void ImportFromExtensionsPathAnd32And64()
mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", GetMainTargetFileContent());
ToolsetConfigurationReaderTestHelper.WriteConfigFile(String.Format(configFileContents, extnDir1, extnDir2, extnDir3));
+
var reader = GetStandardConfigurationReader();
+ var projColln = GetProjectCollection();
- var projColln = new ProjectCollection();
projColln.ResetToolsetsForTests(reader);
var logger = new MockLogger();
projColln.RegisterLogger(logger);
@@ -495,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);
@@ -557,9 +566,9 @@ public void ExpandExtensionsPathFallback()
GetMainTargetFileContent());
ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents);
- var reader = GetStandardConfigurationReader();
- var projectCollection = new ProjectCollection(new Dictionary {["FallbackExpandDir1"] = extnDir1});
+ var reader = GetStandardConfigurationReader();
+ var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
projectCollection.ResetToolsetsForTests(reader);
var logger = new MockLogger();
@@ -618,9 +627,9 @@ public void ExpandExtensionsPathFallbackInErrorMessage()
GetMainTargetFileContent());
ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents);
- var reader = GetStandardConfigurationReader();
- var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
+ var reader = GetStandardConfigurationReader();
+ var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
projectCollection.ResetToolsetsForTests(reader);
var logger = new MockLogger();
@@ -688,9 +697,9 @@ public void FallbackImportWithIndirectReference()
mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", mainTargetsFileContent);
ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents);
- var reader = GetStandardConfigurationReader();
- var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
+ var reader = GetStandardConfigurationReader();
+ var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
projectCollection.ResetToolsetsForTests(reader);
var logger = new MockLogger();
@@ -753,9 +762,9 @@ public void FallbackImportWithUndefinedProperty()
mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", mainTargetsFileContent);
ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents);
- var reader = GetStandardConfigurationReader();
- var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
+ var reader = GetStandardConfigurationReader();
+ var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
projectCollection.ResetToolsetsForTests(reader);
var logger = new MockLogger();
@@ -812,9 +821,9 @@ public void FallbackImportWithFileNotFoundWhenPropertyNotDefined()
mainProjectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", mainTargetsFileContent);
ToolsetConfigurationReaderTestHelper.WriteConfigFile(configFileContents);
- var reader = GetStandardConfigurationReader();
- var projectCollection = new ProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
+ var reader = GetStandardConfigurationReader();
+ var projectCollection = GetProjectCollection(new Dictionary { ["FallbackExpandDir1"] = extnDir1 });
projectCollection.ResetToolsetsForTests(reader);
var logger = new MockLogger();
@@ -834,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"),
@@ -842,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);
@@ -864,15 +876,19 @@ void CreateAndBuildProjectForImportFromExtensionsPath(string extnPathPropertyNam
void CreateAndBuildProjectForImportFromExtensionsPath(string mainProjectPath, string extnPathPropertyName, string[] extnDirs, Action setExtensionsPath,
Action action)
{
- try {
- var projColln = new ProjectCollection();
+ 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);
@@ -913,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);
@@ -922,7 +962,7 @@ string GetNewExtensionsPathAndCreateFile(string extnDirName, string relativeFile
return extnDir;
}
- string GetMainTargetFileContent(string extensionsPathPropertyName="MSBuildExtensionsPath")
+ string GetMainTargetFileContent(string extensionsPathPropertyName = "MSBuildExtensionsPath")
{
string mainTargetsFileContent = @"
@@ -936,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 = @"
@@ -954,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 = @"
@@ -977,4 +1017,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..298cf5ff37f
--- /dev/null
+++ b/src/Build.UnitTests/Evaluation/ToolsetConfigurationNet5_Tests.cs
@@ -0,0 +1,80 @@
+// 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;
+using Shouldly;
+
+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;
+ }
+ }
+
+ toolsetProperties.ShouldContainKey("MSBuildSDKsPath");
+ toolsetProperties.ShouldContainKey("RoslynTargetsPath");
+ toolsetProperties["MSBuildSDKsPath"].ShouldNotBeNullOrEmpty();
+ toolsetProperties["RoslynTargetsPath"].ShouldNotBeNullOrEmpty();
+
+ toolsetProperties.ShouldNotContainKey("VCTargetsPath");
+ toolsetProperties.ShouldNotContainKey("MSBuildToolsRoot");
+ toolsetProperties.ShouldNotContainKey("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;
+ }
+ }
+
+ toolsetProperties.ShouldContainKey("MSBuildSDKsPath");
+ toolsetProperties.ShouldContainKey("RoslynTargetsPath");
+ toolsetProperties["MSBuildSDKsPath"].ShouldNotBeNullOrEmpty();
+ toolsetProperties["RoslynTargetsPath"].ShouldNotBeNullOrEmpty();
+
+ toolsetProperties.ShouldContainKey("VCTargetsPath");
+ toolsetProperties.ShouldContainKey("MSBuildToolsRoot");
+ toolsetProperties.ShouldContainKey("MSBuildExtensionsPath");
+ toolsetProperties["VCTargetsPath"].ShouldNotBeNullOrEmpty();
+ toolsetProperties["MSBuildToolsRoot"].ShouldNotBeNullOrEmpty();
+ toolsetProperties["MSBuildExtensionsPath"].ShouldNotBeNullOrEmpty();
+ }
+ }
+}
+#endif
diff --git a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj
index 756dffdbd0e..52f699668fb 100644
--- a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj
+++ b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj
@@ -16,6 +16,7 @@
+
@@ -44,17 +45,12 @@
TargetFramework=$(FullFrameworkTFM)
TargetFramework=net5.0
-
-
true
-
-
-
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/ToolsetConfigurationReader.cs b/src/Build/Definition/ToolsetConfigurationReader.cs
index 52128c04fa6..5665b1aaf09 100644
--- a/src/Build/Definition/ToolsetConfigurationReader.cs
+++ b/src/Build/Definition/ToolsetConfigurationReader.cs
@@ -253,7 +253,11 @@ 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.
+ // 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
FileSystems.Default.FileExists(BuildEnvironmentHelper.Instance.CurrentMSBuildConfigurationFile))
{
var configFile = new ExeConfigurationFileMap { ExeConfigFilename = BuildEnvironmentHelper.Instance.CurrentMSBuildConfigurationFile };
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/Definition/ToolsetRegistryReader.cs b/src/Build/Definition/ToolsetRegistryReader.cs
index 7a083fbebbd..e2081dc5ad7 100644
--- a/src/Build/Definition/ToolsetRegistryReader.cs
+++ b/src/Build/Definition/ToolsetRegistryReader.cs
@@ -3,11 +3,8 @@
#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 +343,4 @@ private static string GetValue(RegistryKeyWrapper wrapper, string valueName)
}
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj
index acf22733730..0a5dafcf5e3 100644
--- a/src/Build/Microsoft.Build.csproj
+++ b/src/Build/Microsoft.Build.csproj
@@ -31,6 +31,7 @@
+
@@ -39,7 +40,6 @@
-
@@ -420,8 +420,8 @@
-
-
+
+
true
diff --git a/src/Build/Utilities/RegistryKeyWrapper.cs b/src/Build/Utilities/RegistryKeyWrapper.cs
index 5db9a22e37c..c1503c698ef 100644
--- a/src/Build/Utilities/RegistryKeyWrapper.cs
+++ b/src/Build/Utilities/RegistryKeyWrapper.cs
@@ -3,10 +3,6 @@
#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;
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
+
+
+
-
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/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..6d48ace8c4b 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 // 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 // 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");
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 @@
+
-
-