Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 26 additions & 6 deletions documentation/general/analyzer-redirecting.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,31 @@ And metadata at `metadata.json`:

```json
{
"AspNetCoreAnalyzers": "9.0.0-preview.5.24306.11",
"NetCoreAnalyzers": "9.0.0-preview.5.24306.7",
"WindowsDesktopAnalyzers": "9.0.0-preview.5.24306.8",
"SDKAnalyzers": "9.0.100-dev",
"WebSDKAnalyzers": "9.0.100-dev",
"AspNetCoreAnalyzers":
{
"Version": "9.0.0-preview.5.24306.11",
"Files": ["analyzers\\dotnet\\cs\\Microsoft.AspNetCore.App.Analyzers.dll"]
},
"NetCoreAnalyzers":
{
"Version": "9.0.0-preview.5.24306.7",
"Files": ["analyzers\\dotnet\\cs\\System.Text.RegularExpressions.Generator.dll"]
},
"WindowsDesktopAnalyzers":
{
"Version": "9.0.0-preview.5.24306.8",
"Files": ["analyzers\\dotnet\\System.Windows.Forms.Analyzers.dll"]
},
"SDKAnalyzers":
{
"Version": "9.0.100-dev",
"Files": ["Sdks\\Microsoft.NET.Sdk\\analyzers\\Microsoft.CodeAnalysis.NetAnalyzers.dll"]
},
"WebSDKAnalyzers":
{
"Version": "9.0.100-dev",
"Files": ["Sdks\\Microsoft.NET.Sdk.Web\\analyzers\\cs\\Microsoft.AspNetCore.Analyzers.dll"]
},
}
```

Expand All @@ -73,7 +93,7 @@ will be redirected to
{InstallDir}\SDKAnalyzers\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll
```

where `metadata.json` has `"SDKAnalyzers": "9.0.100-dev"`, because
where `metadata.json` has `"SDKAnalyzers": { "Version": "9.0.100-dev" }`, because
1. the suffix `Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll` matches, and
2. the version `9.0.100-preview.5.24307.3` has the same major and minor component (`9.0`) as the version `9.0.100-dev`
(both versions are read from the paths, not DLL metadata).
Expand Down
24 changes: 19 additions & 5 deletions src/Tasks/sdk-tasks/ProcessRuntimeAnalyzerVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class ProcessRuntimeAnalyzerVersions : Task

public override bool Execute()
{
var metadata = new Dictionary<string, string>();
var metadata = new Dictionary<string, MetadataEntry>();

// Extract version from a path like:
// ...\packs\Microsoft.NetCore.App.Ref\<version>\analyzers\**\*.*
Expand All @@ -37,16 +37,24 @@ public override bool Execute()

input.SetMetadata("CustomRecursiveDir", rest);

if (!metadata.TryGetValue(deploymentSubpath, out var existingVersion))
if (!metadata.TryGetValue(deploymentSubpath, out var entry))
{
metadata.Add(deploymentSubpath, version);
entry = new MetadataEntry(version);
metadata.Add(deploymentSubpath, entry);
}
else if (existingVersion != version)
else if (entry.Version != version)
{
Log.LogError($"Version mismatch for '{deploymentSubpath}': '{existingVersion}' != '{version}'. " +
Log.LogError($"Version mismatch for '{deploymentSubpath}': '{entry.Version}' != '{version}'. " +
$"Expected only one version of '{input.GetMetadata("Identity")}'.");
return false;
}

if (!rest.EndsWith("/") && !rest.EndsWith("\\"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be normalizing the paths so that they use consistent separators?

{
rest += '\\';
}

entry.Files.Add($"{rest}{input.GetMetadata("Filename")}{input.GetMetadata("Extension")}");
}

Directory.CreateDirectory(Path.GetDirectoryName(MetadataFilePath)!);
Expand All @@ -55,4 +63,10 @@ public override bool Execute()
Outputs = Inputs;
return true;
}

private sealed class MetadataEntry(string version)
{
public string Version { get; } = version;
public List<string> Files { get; } = [];
}
}
Loading