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
8 changes: 5 additions & 3 deletions documentation/specs/multithreading/thread-safe-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ To prevent common thread-safety issues related to path handling, we introduce pa
namespace Microsoft.Build.Framework;
public readonly struct AbsolutePath : IEquatable<AbsolutePath>
{
// Default value returns string.Empty for Path property
// default(AbsolutePath) has a null Value
public string Value { get; }
internal AbsolutePath(string path, bool ignoreRootedCheck) { }
public AbsolutePath(string path); // Checks Path.IsPathRooted
public AbsolutePath(string path); // Checks Path.IsPathFullyQualified when supported
public AbsolutePath(string path, AbsolutePath basePath) { }
public AbsolutePath GetCanonicalForm();
public static implicit operator string(AbsolutePath path) { }
public override string ToString() => Value;

Expand All @@ -157,6 +158,7 @@ public readonly struct AbsolutePath : IEquatable<AbsolutePath>
```

`AbsolutePath` converts implicitly to string for seamless integration with existing File/Directory APIs.
`GetCanonicalForm()` applies `Path.GetFullPath()` canonicalization to an already fully qualified path, resolving `.` and `..` segments and normalizing directory separators. Use it when migrating code that previously relied on `Path.GetFullPath()`; `TaskEnvironment.GetAbsolutePath()` produces fully qualified paths but intentionally does not canonicalize them.

### API Usage Example

Expand All @@ -170,7 +172,7 @@ public bool Execute(...)
AbsolutePath path = TaskEnvironment.GetAbsolutePath("SomePath");
string content = File.ReadAllText(path);
string content2 = File.ReadAllText(path.ToString());
string content3 = File.ReadAllText(path.Path);
string content3 = File.ReadAllText(path.Value);
...
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/PathHelpers/AbsolutePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static string MakeFullyQualifiedRelativeToBasePath(string combined, stri
/// Preserves the OriginalValue of the current instance.
/// </para>
/// </remarks>
internal AbsolutePath GetCanonicalForm()
public AbsolutePath GetCanonicalForm()
{
return new AbsolutePath(System.IO.Path.GetFullPath(Value), OriginalValue, ignoreRootedCheck: true);
}
Expand Down