diff --git a/src/Build/BackEnd/Shared/BuildRequestConfiguration.cs b/src/Build/BackEnd/Shared/BuildRequestConfiguration.cs index 2d40523d648..edbf03967b2 100644 --- a/src/Build/BackEnd/Shared/BuildRequestConfiguration.cs +++ b/src/Build/BackEnd/Shared/BuildRequestConfiguration.cs @@ -301,7 +301,7 @@ public bool IsTraversal { if (!_isTraversalProject.HasValue) { -#if NET471_OR_GREATER +#if FEATURE_MSIOREDIST if (MemoryExtensions.Equals(Microsoft.IO.Path.GetFileName(ProjectFullPath.AsSpan()), "dirs.proj".AsSpan(), StringComparison.OrdinalIgnoreCase)) #else if (MemoryExtensions.Equals(Path.GetFileName(ProjectFullPath.AsSpan()), "dirs.proj", StringComparison.OrdinalIgnoreCase)) diff --git a/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs b/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs index d2320616e71..59eedb88ac4 100644 --- a/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs +++ b/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs @@ -3,15 +3,14 @@ using System; using System.Collections.Generic; -#if !FEATURE_MSIOREDIST -using System.IO; -#endif using System.Linq; using Microsoft.Build.Shared; using static Microsoft.Build.Experimental.BuildCheck.TaskInvocationCheckData; #if FEATURE_MSIOREDIST using Path = Microsoft.IO.Path; +#else +using System.IO; #endif namespace Microsoft.Build.Experimental.BuildCheck.Checks; diff --git a/src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs b/src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs index 252159162b2..d81ed36aaac 100644 --- a/src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs +++ b/src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs @@ -3,13 +3,12 @@ using System; using System.Collections.Generic; -#if !FEATURE_MSIOREDIST -using System.IO; -#endif using Microsoft.Build.Shared; #if FEATURE_MSIOREDIST using Path = Microsoft.IO.Path; +#else +using System.IO; #endif namespace Microsoft.Build.Experimental.BuildCheck.Checks; diff --git a/src/Build/Evaluation/Expander.cs b/src/Build/Evaluation/Expander.cs index 3cb76b64630..9912532a3bb 100644 --- a/src/Build/Evaluation/Expander.cs +++ b/src/Build/Evaluation/Expander.cs @@ -7,11 +7,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; -#if NET using System.IO; -#else -using Microsoft.IO; -#endif using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; @@ -34,6 +30,11 @@ using TaskItem = Microsoft.Build.Execution.ProjectItemInstance.TaskItem; using TaskItemFactory = Microsoft.Build.Execution.ProjectItemInstance.TaskItem.TaskItemFactory; +#if FEATURE_MSIOREDIST +using Directory = Microsoft.IO.Directory; +using Path = Microsoft.IO.Path; +#endif + #nullable disable namespace Microsoft.Build.Evaluation diff --git a/src/Build/Evaluation/Expander/ArgumentParser.cs b/src/Build/Evaluation/Expander/ArgumentParser.cs index 2d9fa7954a0..a6b8d1f8bd5 100644 --- a/src/Build/Evaluation/Expander/ArgumentParser.cs +++ b/src/Build/Evaluation/Expander/ArgumentParser.cs @@ -4,7 +4,7 @@ using System; using System.Globalization; -#if NETFRAMEWORK +#if FEATURE_MSIOREDIST using Microsoft.IO; #endif diff --git a/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs b/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs index bef70623b73..5c4478317d0 100644 --- a/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs +++ b/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs @@ -11,8 +11,9 @@ using Microsoft.Build.BackEnd.Components.RequestBuilder; using Microsoft.Build.Framework; using Microsoft.Build.Shared; -#if NETFRAMEWORK -using Microsoft.IO; + +#if FEATURE_MSIOREDIST +using Path = Microsoft.IO.Path; #else using System.IO; #endif diff --git a/src/Build/Logging/TerminalLogger/TerminalLogger.cs b/src/Build/Logging/TerminalLogger/TerminalLogger.cs index 8965696dfa8..be8330da86c 100644 --- a/src/Build/Logging/TerminalLogger/TerminalLogger.cs +++ b/src/Build/Logging/TerminalLogger/TerminalLogger.cs @@ -16,8 +16,8 @@ using System.Buffers; #endif -#if NETFRAMEWORK -using Microsoft.IO; +#if FEATURE_MSIOREDIST +using Path = Microsoft.IO.Path; #else using System.IO; #endif diff --git a/src/Build/Utilities/Utilities.cs b/src/Build/Utilities/Utilities.cs index b3936b737e2..d3221ab6d3d 100644 --- a/src/Build/Utilities/Utilities.cs +++ b/src/Build/Utilities/Utilities.cs @@ -5,11 +5,6 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; -#if NET -using System.IO; -#else -using Microsoft.IO; -#endif using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -22,6 +17,12 @@ using Toolset = Microsoft.Build.Evaluation.Toolset; using XmlElementWithLocation = Microsoft.Build.Construction.XmlElementWithLocation; +#if FEATURE_MSIOREDIST +using Path = Microsoft.IO.Path; +#else +using System.IO; +#endif + #nullable disable namespace Microsoft.Build.Internal diff --git a/src/Framework/PathHelpers/AbsolutePath.cs b/src/Framework/PathHelpers/AbsolutePath.cs index 7fb31c57232..49c25e44d69 100644 --- a/src/Framework/PathHelpers/AbsolutePath.cs +++ b/src/Framework/PathHelpers/AbsolutePath.cs @@ -2,8 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -#if NETFRAMEWORK -using Microsoft.IO; + +#if FEATURE_MSIOREDIST +using Path = Microsoft.IO.Path; #else using System.IO; #endif diff --git a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs index a820d138bf8..68f1ae0a765 100644 --- a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs +++ b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.IO; using System.Reflection; using System.Text.RegularExpressions; using System.Threading; @@ -13,15 +14,9 @@ using Microsoft.Build.Shared; using Microsoft.Build.UnitTests; using Microsoft.Build.UnitTests.Shared; -#if NETFRAMEWORK -using Microsoft.IO; -#else -using System.IO; -#endif using Shouldly; using Xunit; using Xunit.Abstractions; -using Path = System.IO.Path; namespace Microsoft.Build.Engine.UnitTests { diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 113f7f0602c..64ed54db5de 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -45,11 +45,10 @@ using SimpleErrorLogger = Microsoft.Build.Logging.SimpleErrorLogger.SimpleErrorLogger; using TerminalLogger = Microsoft.Build.Logging.TerminalLogger; -#if NETFRAMEWORK +#if FEATURE_MSIOREDIST // Use I/O operations from Microsoft.IO.Redist which is generally higher perf // and also works around https://github.com/dotnet/msbuild/issues/10540. // Unnecessary on .NET 6+ because the perf improvements are in-box there. -using Microsoft.IO; using Directory = Microsoft.IO.Directory; using File = Microsoft.IO.File; using FileInfo = Microsoft.IO.FileInfo; diff --git a/src/Shared/FileMatcher.cs b/src/Shared/FileMatcher.cs index d08e6549791..168df31476a 100644 --- a/src/Shared/FileMatcher.cs +++ b/src/Shared/FileMatcher.cs @@ -6,12 +6,13 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; -#if !NETFRAMEWORK -using System.IO; +using System.Linq; + +#if FEATURE_MSIOREDIST +using Path = Microsoft.IO.Path; #else -using Microsoft.IO; +using System.IO; #endif -using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; diff --git a/src/Shared/FileSystem/WindowsFileSystem.cs b/src/Shared/FileSystem/WindowsFileSystem.cs index a83d932c00d..c704360c777 100644 --- a/src/Shared/FileSystem/WindowsFileSystem.cs +++ b/src/Shared/FileSystem/WindowsFileSystem.cs @@ -66,7 +66,7 @@ public override bool DirectoryExists(string path) public override bool FileExists(string path) { -#if NETFRAMEWORK +#if FEATURE_MSIOREDIST return Microsoft.IO.File.Exists(path); #else return File.Exists(path); diff --git a/src/Shared/TaskFactoryUtilities.cs b/src/Shared/TaskFactoryUtilities.cs index 4d918f92bb3..67568c05c32 100644 --- a/src/Shared/TaskFactoryUtilities.cs +++ b/src/Shared/TaskFactoryUtilities.cs @@ -6,8 +6,10 @@ using System.Reflection; using Microsoft.Build.Shared.FileSystem; using Microsoft.Build.Framework; -#if NETFRAMEWORK -using Microsoft.IO; + +#if FEATURE_MSIOREDIST +using File = Microsoft.IO.File; +using Path = Microsoft.IO.Path; #else using System.IO; #endif diff --git a/src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs b/src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs index 0253b720504..d18a9effcf2 100644 --- a/src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs +++ b/src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; using Microsoft.Build.Framework; @@ -10,10 +11,6 @@ using Microsoft.Build.UnitTests; using Microsoft.Build.UnitTests.Shared; using Microsoft.Build.Utilities; -using System.IO; -#if NETFRAMEWORK -using MicrosoftIO = Microsoft.IO; -#endif using Shouldly; using VerifyTests; using VerifyXunit; diff --git a/src/Tasks/XamlTaskFactory/CommandLineGenerator.cs b/src/Tasks/XamlTaskFactory/CommandLineGenerator.cs index f9eb9441801..cedbd859db0 100644 --- a/src/Tasks/XamlTaskFactory/CommandLineGenerator.cs +++ b/src/Tasks/XamlTaskFactory/CommandLineGenerator.cs @@ -7,10 +7,6 @@ using System.Text; using System.Text.RegularExpressions; -#if NETFRAMEWORK -using Microsoft.IO; -#endif - using Microsoft.Build.Framework; using Microsoft.Build.Framework.XamlTypes; using Microsoft.Build.Shared;