共用方式為


InMemoryDirectoryInfo 會在檔案前面加上 rootDir

InMemoryDirectoryInfo 現在會將指定的根目錄加到其檔案集合的前面。

InMemoryDirectoryInfoMatcherExtensions.Match使用 ,可讓 Matcher 執行 glob 比對模式而不存取磁碟。

先前的行為

先前,files參數中的相對路徑會在建構子中加上目前的工作目錄(CWD)。 這會導致一種應該能在記憶體中運作的類型,出現對 CWD(當前工作目錄)的不必要相依性。

新行為

從 .NET 9 開始,建構函式自變數中的 files 相對路徑會加上指定的根目錄。

推出的版本

.NET 9 Preview 1

破壞性變更的類型

此變更為行為變更

變更的原因

使用非目前工作目錄驅動器號的記憶體路徑存在受阻情況。 例如,請參閱 dotnet/runtime 問題 93107

如果您依賴之前的行為,請調整程式碼,以因應現在檔案會加上根目錄。 例如:

// Since rootDir is also relative, it could've been used to filter the matching scope of `files`.
-string rootDir = "dir1";
// Now that's not possible; everything in `files` is under `root`.
+string rootDir = "root";
string[] files = ["dir1/test.0", "dir1/subdir/test.1", "dir2/test.2"];

-PatternMatchingResult result = new Matcher().AddInclude("**/*").Match(rootDir, files);
// Adjust the pattern if you want to scope down to dir1.
+PatternMatchingResult result = new Matcher().AddInclude("dir1/**/*").Match(rootDir, files);
Console.WriteLine(string.Join(", ", result.Files.Select(x => x.Path)));

// Output:
// dir1/test.0
// dir1/subdir/test.1

受影響的 API