Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Roslyn 3.11, 4.4, 4.6, and 4.8 #73

Merged
merged 15 commits into from
Feb 27, 2024

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented Feb 27, 2024

Changes

close #66

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

@Aaronontheweb Aaronontheweb changed the title Support Roslyn 3.11, 4.2, 4.4, 4.6, and 4.8 Support Roslyn 3.11, 4.4, 4.6, and 4.8 Feb 27, 2024
@Aaronontheweb Aaronontheweb marked this pull request as ready for review February 27, 2024 16:31
@Aaronontheweb Aaronontheweb added github_actions Pull requests that update GitHub Actions code build-system Build system issues labels Feb 27, 2024
Copy link
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Borrowed this technique from xunit.analyzers - should work to resolve our multi-targeting issues for end users. The real problem isn't the version of .NET being targeted, it's the version of the Visual Studio / .NET SDK tooling being used: https://learn.microsoft.com/en-us/visualstudio/extensibility/roslyn-version-support?view=vs-2022

run: dotnet test -c Release
shell: bash
run: |
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
Copy link
Member Author

Choose a reason for hiding this comment

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

Can't run .NET Framework tests reliably on Linux; worked around that here.

<When Condition="$(MSBuildProjectName.Contains('.Tests'))">
<ItemGroup>
<!-- Download packages referenced by ReferenceAssembliesHelper -->
<PackageDownload Include="Akka.Cluster.Sharding" Version="[1.5.15]"/>
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this to here so all of the individual .Tests projects could all download the same dependencies needed for running integration tests

@@ -21,6 +26,7 @@
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RoslynVersion>4.8.0</RoslynVersion>
Copy link
Member Author

Choose a reason for hiding this comment

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

The key driver of this Roslyn-versioning system is this custom property - this is used to specify the version of the Roslyn tooling that gets included inside each distributable.

@@ -18,4 +18,8 @@
<PackageVersion Include="FluentAssertions" Version="6.12.0"/>
<PackageVersion Include="coverlet.collector" Version="6.0.1"/>
</ItemGroup>

<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
Copy link
Member Author

Choose a reason for hiding this comment

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

Added SourceLink as a global package reference for all projects in the solution.

</PropertyGroup>
<PropertyGroup Condition="$(MSBuildProjectName.Contains('Roslyn311'))">
<DefineConstants>$(DefineConstants);ROSLYN_3_11;ROSLYN_3_11_OR_GREATER</DefineConstants>
<RoslynVersion>3.11.0</RoslynVersion>
Copy link
Member Author

Choose a reason for hiding this comment

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

Defines the versions of Roslyn we use based on the naming convention of the projects

@@ -22,6 +22,14 @@

<file target="analyzers\dotnet\cs\" src="..\Akka.Analyzers\bin\$Configuration$\netstandard2.0\Akka.Analyzers.dll" />
<file target="analyzers\dotnet\cs\" src="..\Akka.Analyzers.Fixes\bin\$Configuration$\netstandard2.0\Akka.Analyzers.Fixes.dll" />
<!-- <file target="tools\" src="..\xunit.analyzers.fixes\tools\*.ps1" />-->

<file target="analyzers\dotnet\roslyn3.11\cs\" src="..\Akka.Analyzers.Fixes.Roslyn311\bin\$Configuration$\netstandard2.0\Akka.Analyzers.dll" />
Copy link
Member Author

Choose a reason for hiding this comment

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

This is what makes the solution workable for end-users - this moves compiler-platform specific versions of the Roslyn analyzers + fixes into the directories expected by the .NET Compiler platform. So if the user is running version 4.3 of Roslyn, the system should fall back to using the 4.2 version specified in this directory.

</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis"/>
<PackageReference Include="Microsoft.CodeAnalysis" VersionOverride="[$(RoslynVersion)]"/>
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where we specify the version of Roslyn tooling that will get used in the solution. All of the .Roslyn{X} solutions update their RoslynVersion variables accordingly and reference the tooling accordingly.

@@ -9,7 +9,7 @@ namespace Akka.Analyzers;
/// <summary>
/// INTERNAL API
/// </summary>
internal static class Guard
public static class Guard
Copy link
Member Author

Choose a reason for hiding this comment

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

So I don't have to declare every compiler version as a Friend assembly.

Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

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

LGTM

@Arkatufus Arkatufus merged commit c83f016 into akkadotnet:dev Feb 27, 2024
2 checks passed
@Aaronontheweb Aaronontheweb deleted the fix-66-roslyn-versions branch July 26, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-system Build system issues github_actions Pull requests that update GitHub Actions code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Akka.Analyzers may not be compatible with .NET Framework v4.7
2 participants