共用方式為


InMemoryDirectoryInfo 會在檔案前面加上 rootDir

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

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

先前的行為

先前,建構函式 files 引數中的相對路徑前面會加上目前的工作目錄 (CWD)。 這會導致 CWD 上針對應該在記憶體中運作的類型產生不必要的相依性。

新的行為

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

導入的版本

.NET 9 Preview 1

中斷性變更的類型

此變更為行為變更

變更原因

記憶體內部路徑使用目前工作目錄所使用以外的磁碟機代號時,有已遭到封鎖的案例。 例如,請參閱 dotnet/執行階段問題 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