Skip to content
Draft
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
25 changes: 19 additions & 6 deletions src/Tasks/ResolveCodeAnalysisRuleSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ namespace Microsoft.Build.Tasks
/// Determines which file, if any, to be used as the code analysis rule set based
/// on the supplied code analysis properties.
/// </summary>
public sealed class ResolveCodeAnalysisRuleSet : TaskExtension
[MSBuildMultiThreadableTask]
public sealed class ResolveCodeAnalysisRuleSet : TaskExtension, IMultiThreadableTask
{
#region Properties

/// <summary>
/// Gets or sets the task execution environment for thread-safe path resolution.
/// </summary>
public TaskEnvironment TaskEnvironment { get; set; } = TaskEnvironment.Fallback;

/// <summary>
/// The desired code analysis rule set file. May be a simple name, relative
/// path, or full path.
Expand Down Expand Up @@ -84,7 +90,8 @@ private string GetResolvedRuleSetPath()
if (!string.IsNullOrEmpty(MSBuildProjectDirectory))
{
string fullName = Path.Combine(MSBuildProjectDirectory, CodeAnalysisRuleSet);
if (FileSystems.Default.FileExists(fullName))
AbsolutePath absolute = TaskEnvironment.GetAbsolutePath(fullName);
if (FileSystems.Default.FileExists(absolute))
{
return CodeAnalysisRuleSet;
}
Expand All @@ -96,7 +103,8 @@ private string GetResolvedRuleSetPath()
foreach (string directory in CodeAnalysisRuleSetDirectories)
{
string fullName = Path.Combine(directory, CodeAnalysisRuleSet);
if (FileSystems.Default.FileExists(fullName))
AbsolutePath absolute = TaskEnvironment.GetAbsolutePath(fullName);
if (FileSystems.Default.FileExists(absolute))
{
return fullName;
}
Expand All @@ -109,16 +117,21 @@ private string GetResolvedRuleSetPath()
if (!string.IsNullOrEmpty(MSBuildProjectDirectory))
{
string fullName = Path.Combine(MSBuildProjectDirectory, CodeAnalysisRuleSet);
if (FileSystems.Default.FileExists(fullName))
AbsolutePath absolute = TaskEnvironment.GetAbsolutePath(fullName);
if (FileSystems.Default.FileExists(absolute))
{
return CodeAnalysisRuleSet;
}
}
}
else if (FileSystems.Default.FileExists(CodeAnalysisRuleSet))
else
{
// This is a full path.
return CodeAnalysisRuleSet;
AbsolutePath absolute = TaskEnvironment.GetAbsolutePath(CodeAnalysisRuleSet);
if (FileSystems.Default.FileExists(absolute))
{
return CodeAnalysisRuleSet;
}
}

// We can't resolve the rule set to any existing file.
Expand Down