Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using Microsoft.Build.Logging;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.Debugging;
using Microsoft.Build.Shared.FileSystem;
using Microsoft.Build.TelemetryInfra;
using Microsoft.NET.StringTools;
using ExceptionHandling = Microsoft.Build.Shared.ExceptionHandling;
Expand Down Expand Up @@ -3287,9 +3288,9 @@ private bool ReuseOldCaches(string[] inputCacheFiles)
return false;
}

if (inputCacheFiles.Any(f => !File.Exists(f)))
if (inputCacheFiles.Any(f => !FileSystems.Default.FileExists(f)))
{
LogErrorAndShutdown(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("InputCacheFilesDoNotExist", string.Join(";", inputCacheFiles.Where(f => !File.Exists(f)))));
LogErrorAndShutdown(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("InputCacheFilesDoNotExist", string.Join(";", inputCacheFiles.Where(f => !FileSystems.Default.FileExists(f)))));
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Build/BackEnd/Components/Communications/CurrentHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using Microsoft.Build.Internal;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
#endif

namespace Microsoft.Build.BackEnd;
Expand All @@ -28,7 +29,7 @@ internal static class CurrentHost
string dotnetExe = Path.Combine(
FileUtilities.GetFolderAbove(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory, 2),
Constants.DotnetProcessName);
if (File.Exists(dotnetExe))
if (FileSystems.Default.FileExists(dotnetExe))
{
s_currentHost = dotnetExe;
}
Expand All @@ -48,7 +49,7 @@ internal static class CurrentHost
dotnetExe = Path.Combine(
FileUtilities.GetFolderAbove(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), 4),
Constants.DotnetProcessName);
if (File.Exists(dotnetExe))
if (FileSystems.Default.FileExists(dotnetExe))
{
s_currentHost = dotnetExe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#if FEATURE_REPORTFILEACCESSES
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Runtime.Versioning;
using System.Threading;
using Microsoft.Build.BackEnd;
using Microsoft.Build.Execution;
using Microsoft.Build.Experimental.FileAccess;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;

namespace Microsoft.Build.FileAccesses
{
Expand Down Expand Up @@ -144,7 +144,7 @@ public static void NotifyFileAccessCompletion(int globalRequestId)
{
// Make a dummy file access to use as a notification that the file accesses should be completed for a project.
string filePath = FileAccessCompletionPrefix + globalRequestId.ToString();
_ = File.Exists(filePath);
_ = FileSystems.Default.FileExists(filePath);
}

public void WaitForFileAccessReportCompletion(int globalRequestId, CancellationToken cancellationToken)
Expand Down
3 changes: 2 additions & 1 deletion src/Build/BackEnd/Components/Scheduler/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.Build.ProjectCache;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.Debugging;
using Microsoft.Build.Shared.FileSystem;
using BuildAbortedException = Microsoft.Build.Exceptions.BuildAbortedException;
using ILoggingService = Microsoft.Build.BackEnd.Logging.ILoggingService;
using NodeLoggingContext = Microsoft.Build.BackEnd.Logging.NodeLoggingContext;
Expand Down Expand Up @@ -2703,7 +2704,7 @@ private void DumpSchedulerState()
bool shouldWriteHeader = _debugDumpIsFirstWrite;
if (shouldWriteHeader)
{
shouldWriteHeader = !File.Exists(string.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), EnvironmentUtilities.CurrentProcessId));
shouldWriteHeader = !FileSystems.Default.FileExists(string.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), EnvironmentUtilities.CurrentProcessId));
_debugDumpIsFirstWrite = false;
}
using StreamWriter file = FileUtilities.OpenWrite(string.Format(CultureInfo.CurrentCulture, Path.Combine(_debugDumpPath, "SchedulerState_{0}.txt"), EnvironmentUtilities.CurrentProcessId), append: true);
Expand Down
3 changes: 2 additions & 1 deletion src/Build/BuildCheck/Checks/UntrustedLocationCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.InteropServices;
using Microsoft.Build.Construction;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;

namespace Microsoft.Build.Experimental.BuildCheck.Checks;
internal sealed class UntrustedLocationCheck : Check
Expand Down Expand Up @@ -79,7 +80,7 @@ private static string GetDownloadsPath()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
string? locationFromEnv = Environment.GetEnvironmentVariable("XDG_DOWNLOAD_DIR");
if (locationFromEnv != null && Directory.Exists(locationFromEnv))
if (locationFromEnv != null && FileSystems.Default.DirectoryExists(locationFromEnv))
{
return locationFromEnv.TrimEnd(['\\','/']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
using static Microsoft.Build.Experimental.BuildCheck.Infrastructure.EditorConfig.EditorConfigGlobsMatcher;

namespace Microsoft.Build.Experimental.BuildCheck.Infrastructure.EditorConfig;
Expand Down Expand Up @@ -51,7 +52,7 @@ internal List<EditorConfigFile> DiscoverEditorConfigFiles(string filePath)
{
var editorConfig = _editorConfigFileCache.GetOrAdd(editorConfigFilePath, (key) =>
{
return EditorConfigFile.Parse(File.ReadAllText(editorConfigFilePath));
return EditorConfigFile.Parse(FileSystems.Default.ReadFileAllText(editorConfigFilePath));
});
editorConfigFilePaths.Add(editorConfigFilePath);
editorConfigDataFromFilesList.Add(editorConfig);
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Construction/ProjectRootElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ internal static bool IsEmptyXmlFile(string path)
return false;
}

string contents = File.ReadAllText(path);
string contents = FileSystems.Default.ReadFileAllText(path);

// If the file is only whitespace or the XML declaration then it is empty
//
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Construction/Solution/SolutionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ internal static string ParseSolutionFromSolutionFilter(string solutionFilterFile
{
// This is to align MSBuild with what VS permits in loading solution filter files. These are not in them by default but can be added manually.
JsonDocumentOptions options = new JsonDocumentOptions() { AllowTrailingCommas = true, CommentHandling = JsonCommentHandling.Skip };
JsonDocument text = JsonDocument.Parse(File.ReadAllText(solutionFilterFile), options);
JsonDocument text = JsonDocument.Parse(FileSystems.Default.ReadFileAllText(solutionFilterFile), options);
solution = text.RootElement.GetProperty("solution");
// We do NOT want to escape in order to preserve symbols like @, %, $ etc.
return FileUtilities.GetFullPath(solution.GetProperty("path").GetString(), Path.GetDirectoryName(solutionFilterFile), escape: false);
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ static string EvaluateProperty(string value, IElementLocation location,
// "S:\sdk\.dotnet\sdk\10.0.100-preview.6.25315.102\Sdks\Microsoft.NET.Sdk\Sdk"
// ^5 ^4 ^3 ^2 ^1
string dotnetExe = Path.Combine(FileUtilities.GetFolderAbove(sdkResult.Path, 5), Constants.DotnetProcessName);
if (File.Exists(dotnetExe))
if (FileSystems.Default.FileExists(dotnetExe))
{
_data.AddSdkResolvedEnvironmentVariable(Constants.DotnetHostPathEnvVarName, dotnetExe);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Evaluation/Expander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,7 @@ internal static void Exists(IElementLocation elementLocation, string functionNam
ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidItemFunctionExpression", functionName, item.Key, e.Message);
}

if (File.Exists(rootedPath) || Directory.Exists(rootedPath))
if (FileSystems.Default.FileOrDirectoryExists(rootedPath))
{
transformedItems.Add(item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Evaluation/IntrinsicFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ public static string GetMSBuildExtensionsPath()
public static bool RegisterBuildCheck(string projectPath, string pathToAssembly, LoggingContext loggingContext)
{
pathToAssembly = FileUtilities.GetFullPathNoThrow(pathToAssembly);
if (File.Exists(pathToAssembly))
if (FileSystems.Default.FileExists(pathToAssembly))
{
loggingContext.LogBuildEvent(new BuildCheckAcquisitionEventArgs(pathToAssembly, projectPath));

Expand Down
4 changes: 2 additions & 2 deletions src/Build/Logging/BinaryLogger/ProjectImportsCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ProjectImportsCollector(
else
{
string cacheDirectory = FileUtilities.GetCacheDirectory();
if (!Directory.Exists(cacheDirectory))
if (!FileSystems.Default.DirectoryExists(cacheDirectory))
{
Directory.CreateDirectory(cacheDirectory);
}
Expand Down Expand Up @@ -222,7 +222,7 @@ private bool ShouldAddFile(ref string filePath, bool checkFileExistence, bool ma
return false;
}

if (checkFileExistence && !File.Exists(filePath))
if (checkFileExistence && !FileSystems.Default.FileExists(filePath))
{
_processedFiles.Add(filePath);
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Build/Utilities/EngineFileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Build.BackEnd.Components.Logging;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;

namespace Microsoft.Build.Internal
{
Expand Down Expand Up @@ -600,7 +600,7 @@ internal sealed class IOCache

public bool DirectoryExists(string directory)
{
return existenceCache.Value.GetOrAdd(directory, directory => Directory.Exists(directory));
return existenceCache.Value.GetOrAdd(directory, directory => FileSystems.Default.DirectoryExists(directory));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/BuildEnvironmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ NativeMethodsShared.ProcessorArchitectures.X64 or NativeMethodsShared.ProcessorA

// Check for existence of an MSBuild file. Note this is not necessary in a VS installation where we always want to
// assume the correct layout.
var existsCheck = mode == BuildEnvironmentMode.VisualStudio ? new Func<string, bool>(_ => true) : File.Exists;
var existsCheck = mode == BuildEnvironmentMode.VisualStudio ? new Func<string, bool>(_ => true) : FileSystems.Default.FileExists;

MSBuildToolsDirectory32 = MSBuildToolsDirectoryRoot;
MSBuildToolsDirectory64 = existsCheck(potentialAmd64FromX86) ? Path.Combine(MSBuildToolsDirectoryRoot, "amd64") : CurrentMSBuildToolsDirectory;
Expand Down
3 changes: 2 additions & 1 deletion src/Shared/Debugging/DebugUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared.FileSystem;

#nullable disable

Expand Down Expand Up @@ -112,7 +113,7 @@ public static string FindNextAvailableDebugFilePath(string fileName)
var fullPath = Path.Combine(DebugPath, fileName);

var counter = 0;
while (File.Exists(fullPath))
while (FileSystems.Default.FileExists(fullPath))
{
fileName = $"{fileNameWithoutExtension}_{counter++}{extension}";
fullPath = Path.Combine(DebugPath, fileName);
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/ExceptionHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ internal static string ReadAnyExceptionFromFile(DateTime fromTimeUtc)

foreach (string file in files)
{
if (File.GetLastWriteTimeUtc(file) >= fromTimeUtc)
if (FileSystems.Default.GetLastWriteTimeUtc(file) >= fromTimeUtc)
{
builder.Append(Environment.NewLine);
builder.Append(file);
builder.Append(':');
builder.Append(Environment.NewLine);
builder.Append(File.ReadAllText(file));
builder.Append(FileSystems.Default.ReadFileAllText(file));
builder.Append(Environment.NewLine);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/FileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static bool GetIsFileSystemCaseSensitive()
using (new FileStream(pathWithUpperCase, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 0x1000, FileOptions.DeleteOnClose))
{
string lowerCased = pathWithUpperCase.ToLowerInvariant();
return !File.Exists(lowerCased);
return !FileSystems.Default.FileExists(lowerCased);
}
}
catch (Exception exc)
Expand Down Expand Up @@ -748,7 +748,7 @@ internal static void DeleteSubdirectoriesNoThrow(string directory)
{
try
{
foreach (string dir in Directory.EnumerateDirectories(directory))
foreach (string dir in FileSystems.Default.EnumerateDirectories(directory))
{
DeleteDirectoryNoThrow(dir, recursive: true, retryCount: 1);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Shared/FrameworkLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ public virtual string GetPathToDotNetFramework(DotNetFrameworkArchitecture archi
FindDotNetFrameworkPath(
Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName),
this.DotNetFrameworkFolderPrefix,
Directory.Exists,
FileSystems.Default.DirectoryExists,
Directory.GetDirectories,
architecture);

Expand All @@ -1432,8 +1432,8 @@ public virtual string GetPathToDotNetFramework(DotNetFrameworkArchitecture archi
// Rollback see https://developercommunity.visualstudio.com/t/Unable-to-locate-MSBuild-path-with-Lates/10824132
if (this._hasMsBuild &&
generatedPathToDotNetFramework != null &&
(!File.Exists(Path.Combine(generatedPathToDotNetFramework, NativeMethodsShared.IsWindows ? "MSBuild.exe" : "mcs.exe")) &&
!File.Exists(Path.Combine(generatedPathToDotNetFramework, "Microsoft.Build.dll"))))
(!FileSystems.Default.FileExists(Path.Combine(generatedPathToDotNetFramework, NativeMethodsShared.IsWindows ? "MSBuild.exe" : "mcs.exe")) &&
!FileSystems.Default.FileExists(Path.Combine(generatedPathToDotNetFramework, "Microsoft.Build.dll"))))
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/MSBuildLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public MSBuildLoadContext(string assemblyPath)
// We should maintain previous behavior in the absence of new data (a .deps.json file) indicating that we
// should do something different.
// Setting the _resolver to null essentially just opts out of the new behavior.
_resolver = File.Exists(assemblyPath) && File.Exists(Path.ChangeExtension(assemblyPath, ".deps.json"))
_resolver = FileSystems.Default.FileExists(assemblyPath) && FileSystems.Default.FileExists(Path.ChangeExtension(assemblyPath, ".deps.json"))
? new AssemblyDependencyResolver(assemblyPath) :
null;
}
Expand Down
17 changes: 9 additions & 8 deletions src/Shared/TaskFactoryUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.Build.Shared.FileSystem;

namespace Microsoft.Build.Shared
{
Expand Down Expand Up @@ -152,7 +153,7 @@ public static List<string> ExtractUniqueDirectoriesFromAssemblyPaths(List<string

foreach (string assemblyPath in assemblyPaths)
{
if (!string.IsNullOrEmpty(assemblyPath) && File.Exists(assemblyPath))
if (!string.IsNullOrEmpty(assemblyPath) && FileSystems.Default.FileExists(assemblyPath))
{
string? directory = Path.GetDirectoryName(assemblyPath);
if (!string.IsNullOrEmpty(directory) && seenDirectories.Add(directory))
Expand All @@ -178,7 +179,7 @@ public static Assembly LoadTaskAssembly(string assemblyPath)
}

// Load the assembly from bytes so we don't lock the file and record its original path for out-of-proc hosts
Assembly assembly = Assembly.Load(File.ReadAllBytes(assemblyPath));
Assembly assembly = Assembly.Load(FileSystems.Default.ReadFileAllBytes(assemblyPath));
return assembly;
}

Expand All @@ -202,7 +203,7 @@ public static void RegisterAssemblyResolveHandlersFromManifest(string taskLocati
}

string manifestPath = taskLocation + InlineTaskLoadManifestSuffix;
if (!File.Exists(manifestPath))
if (!FileSystems.Default.FileExists(manifestPath))
{
return;
}
Expand Down Expand Up @@ -247,7 +248,7 @@ public static void CleanCurrentProcessInlineTaskDirectory()
InlineTaskTempDllSubPath,
$"pid_{EnvironmentUtilities.CurrentProcessId}");

if (Directory.Exists(processSpecificInlineTaskDir))
if (FileSystems.Default.DirectoryExists(processSpecificInlineTaskDir))
{
FileUtilities.DeleteDirectoryNoThrow(processSpecificInlineTaskDir, recursive: true);
}
Expand All @@ -269,17 +270,17 @@ public static void CleanCurrentProcessInlineTaskDirectory()
if (!string.IsNullOrEmpty(assemblyName.CultureName))
{
path = Path.Combine(directory, assemblyName.CultureName, assemblyName.Name + ".dll");
if (File.Exists(path))
if (FileSystems.Default.FileExists(path))
{
return Assembly.Load(File.ReadAllBytes(path));
return Assembly.Load(FileSystems.Default.ReadFileAllBytes(path));
}
}

// Try the standard path
path = Path.Combine(directory, assemblyName.Name + ".dll");
if (File.Exists(path))
if (FileSystems.Default.FileExists(path))
{
return Assembly.Load(File.ReadAllBytes(path));
return Assembly.Load(FileSystems.Default.ReadFileAllBytes(path));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Tasks/AddToWin32Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
using Microsoft.Build.Tasks.Deployment.ManifestUtilities;
using Microsoft.Build.Utilities;

Expand Down Expand Up @@ -89,7 +90,7 @@ public string ManifestPath
{
if (ApplicationManifest != null)
{
if (string.IsNullOrEmpty(ApplicationManifest.ItemSpec) || !File.Exists(ApplicationManifest?.ItemSpec))
if (string.IsNullOrEmpty(ApplicationManifest.ItemSpec) || !FileSystems.Default.FileExists(ApplicationManifest?.ItemSpec))
{
Log.LogErrorWithCodeFromResources(null, ApplicationManifest?.ItemSpec, 0, 0, 0, 0, "AddToWin32Manifest.SpecifiedApplicationManifestCanNotBeFound");
return null;
Expand Down
Loading