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
15 changes: 5 additions & 10 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<Choose>
<When Condition="$(RoslynVersion) == 'roslyn3.8'">
<ItemGroup >
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
<PackageReference Update="Microsoft.CodeAnalysis.Workspaces.Common" Version="3.8.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" />
Expand All @@ -22,7 +21,6 @@

<When Condition="$(RoslynVersion) == 'roslyn4.2'">
<ItemGroup>
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
<PackageReference Update="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.2.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0" />
Expand All @@ -36,7 +34,6 @@

<When Condition="$(RoslynVersion) == 'roslyn4.4'">
<ItemGroup>
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageReference Update="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.4.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
Expand Down Expand Up @@ -64,7 +61,6 @@

<When Condition="$(RoslynVersion) == 'roslyn4.8'">
<ItemGroup>
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Update="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.8.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
Expand All @@ -78,14 +74,13 @@

<Otherwise>
<ItemGroup>
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
<PackageReference Update="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.14.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="5.0.0-2.final" />
<PackageReference Update="Microsoft.CodeAnalysis.Workspaces.Common" Version="5.0.0-2.final" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0-2.final" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);ROSLYN4_8;ROSLYN_4_2_OR_GREATER;ROSLYN_4_4_OR_GREATER;ROSLYN_4_5_OR_GREATER;ROSLYN_4_6_OR_GREATER;ROSLYN_4_8_OR_GREATER;ROSLYN_4_10_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);CSHARP9_OR_GREATER;CSHARP10_OR_GREATER;CSHARP11_OR_GREATER;CSHARP12_OR_GREATER;CSHARP13_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);ROSLYN5_0;ROSLYN_4_2_OR_GREATER;ROSLYN_4_4_OR_GREATER;ROSLYN_4_5_OR_GREATER;ROSLYN_4_6_OR_GREATER;ROSLYN_4_8_OR_GREATER;ROSLYN_4_10_OR_GREATER;ROSLYN_5_0_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);CSHARP9_OR_GREATER;CSHARP10_OR_GREATER;CSHARP11_OR_GREATER;CSHARP12_OR_GREATER;CSHARP13_OR_GREATER;CSHARP14_OR_GREATER</DefineConstants>
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>
</Otherwise>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" PrivateAssets="all" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/Meziantou.Analyzer/Meziantou.Analyzer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
</ItemGroup>

Expand Down
28 changes: 22 additions & 6 deletions tests/Meziantou.Analyzer.Test/Helpers/ProjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public sealed partial class ProjectBuilder
public string? DefaultAnalyzerId { get; set; }
public string? DefaultAnalyzerMessage { get; set; }

private static async Task<string[]> GetNuGetReferences(string packageName, string version, params string[] paths)
private static async Task<string[]> GetNuGetReferences(string packageName, string version, string[] includedPaths)
{
var bytes = Encoding.UTF8.GetBytes(packageName + '@' + version + ':' + string.Join(',', paths));
var bytes = Encoding.UTF8.GetBytes(packageName + '@' + version + ':' + string.Join(',', includedPaths));
var hash = SHA256.HashData(bytes);
var key = Convert.ToBase64String(hash).Replace('/', '_');
var task = NuGetPackagesCache.GetOrAdd(key, _ => new Lazy<Task<string[]>>(Download));
Expand All @@ -61,15 +61,15 @@ async Task<string[]> Download()
await using var zip = new ZipArchive(stream, ZipArchiveMode.Read);

var hasEntry = false;
foreach (var entry in zip.Entries.Where(file => paths.Any(path => file.FullName.StartsWith(path, StringComparison.Ordinal))))
foreach (var entry in zip.Entries.Where(file => includedPaths.Any(path => file.FullName.StartsWith(path, StringComparison.Ordinal))))
{
await entry.ExtractToFileAsync(Path.Combine(tempFolder, entry.Name), overwrite: true);
hasEntry = true;
}

if (!hasEntry)
{
throw new InvalidOperationException("The NuGet package " + packageName + "@" + version + " does not contain any file matching the paths " + string.Join(", ", paths));
throw new InvalidOperationException("The NuGet package " + packageName + "@" + version + " does not contain any file matching the paths " + string.Join(", ", includedPaths));
}

try
Expand Down Expand Up @@ -114,7 +114,7 @@ async Task<string[]> Download()

public ProjectBuilder AddNuGetReference(string packageName, string version, string pathPrefix)
{
foreach (var reference in GetNuGetReferences(packageName, version, pathPrefix).Result)
foreach (var reference in GetNuGetReferences(packageName, version, [pathPrefix]).Result)
{
References.Add(MetadataReference.CreateFromFile(reference));
}
Expand Down Expand Up @@ -149,22 +149,38 @@ public ProjectBuilder WithAnalyzerFromNuGet(string packageName, string version,
return this;
}

#if ROSLYN5_0
public ProjectBuilder WithMicrosoftCodeAnalysisNetAnalyzers(params string[] ruleIds) =>
WithAnalyzerFromNuGet(
"Microsoft.CodeAnalysis.NetAnalyzers",
"10.0.100-rc.2.25502.107",
paths: ["analyzers/dotnet/cs/", "analyzers/dotnet/Microsoft."],
ruleIds);
#else
public ProjectBuilder WithMicrosoftCodeAnalysisNetAnalyzers(params string[] ruleIds) =>
WithAnalyzerFromNuGet(
"Microsoft.CodeAnalysis.NetAnalyzers",
"9.0.0",
paths: ["analyzers/dotnet/cs/Microsoft.CodeAnalysis"],
ruleIds);
#endif

public ProjectBuilder WithMicrosoftCodeAnalysisCSharpCodeStyleAnalyzers(params string[] ruleIds)
{
AddNuGetReference("Microsoft.Bcl.AsyncInterfaces", "9.0.7", "lib/netstandard2.1/");

#if ROSLYN5_0
return WithAnalyzerFromNuGet(
"Microsoft.CodeAnalysis.CSharp.CodeStyle",
"5.0.0-2.final",
paths: ["analyzers/dotnet/cs/", "analyzers/dotnet/Microsoft.CodeAnalysis"],
ruleIds);
#else
return WithAnalyzerFromNuGet(
"Microsoft.CodeAnalysis.CSharp.CodeStyle",
"4.14.0",
paths: ["analyzers/dotnet/cs/"],
ruleIds);
#endif
}

public ProjectBuilder AddMSTestApi() => AddNuGetReference("MSTest.TestFramework", "2.1.1", "lib/netstandard1.0/");
Expand Down