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

Multi-target Json and Logger Source Generators between Roslyn v3.9 and v4.0 #58446

Merged
merged 10 commits into from
Sep 14, 2021

Conversation

eerhardt
Copy link
Member

Add the ability to target both Roslyn v3.9 and v4.0 in our Logging source generator. This is only enabled in the NuGet packages. For the ref-packs (both NetCoreApp and AspNetCore), we will only ship the 4.0 targeting versions of the generators. In order to target net6.0, customers must use VS 2022 which has Roslyn 4.0.

This is just an early draft to get initial feedback on the approach. The structure created here follows the proposal in dotnet/sdk#20355.

If the SDK proposal isn't accepted for 6.0, my plan is to ship .targets files in both NuGet packages which will select the correct source generator version using custom logic. In both cases, we will need these changes to build the source generator twice - once for each Roslyn version we want to target.

Once we settle on an approach here, I can make the same changes to the System.Text.Json source generator.

@ghost
Copy link

ghost commented Aug 31, 2021

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

Add the ability to target both Roslyn v3.9 and v4.0 in our Logging source generator. This is only enabled in the NuGet packages. For the ref-packs (both NetCoreApp and AspNetCore), we will only ship the 4.0 targeting versions of the generators. In order to target net6.0, customers must use VS 2022 which has Roslyn 4.0.

This is just an early draft to get initial feedback on the approach. The structure created here follows the proposal in dotnet/sdk#20355.

If the SDK proposal isn't accepted for 6.0, my plan is to ship .targets files in both NuGet packages which will select the correct source generator version using custom logic. In both cases, we will need these changes to build the source generator twice - once for each Roslyn version we want to target.

Once we settle on an approach here, I can make the same changes to the System.Text.Json source generator.

Author: eerhardt
Assignees: -
Labels:

area-Extensions-Logging

Milestone: -

Copy link
Member

@ViktorHofer ViktorHofer left a comment

Choose a reason for hiding this comment

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

The msbuild and the project changes as well as the transport package change LGTM.

@eerhardt
Copy link
Member Author

@ViktorHofer - one place I was wondering about was the changes to the .sln file. I know we generate our .sln files. Will the sln generator handle these changes?

@@ -260,6 +260,7 @@
Returns="@(_AnalyzerPackFile)">
<PropertyGroup>
<_analyzerPath>analyzers/dotnet</_analyzerPath>
<_analyzerPath Condition="'$(AnalyzerRoslynVersion)' != ''">$(_analyzerPath)/roslyn$(AnalyzerRoslynVersion)</_analyzerPath>
Copy link
Member

Choose a reason for hiding this comment

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

what does this do?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now: nothing. But check out dotnet/sdk#20355 for more information.

@ViktorHofer
Copy link
Member

@ViktorHofer - one place I was wondering about was the changes to the .sln file. I know we generate our .sln files. Will the sln generator handle these changes?

Feel free to check the solution file format change in as it probably will be a some time until we regenerate them again. Regarding your question, yes slngen discovers these references as AnalyzerReference items are just slightly modified ProjectReferences. Because of that, the analyzers are part of the depedency graph and slngen sees them.

@eerhardt eerhardt marked this pull request as ready for review September 8, 2021 23:47
@eerhardt eerhardt changed the title Multi-target LoggerMessageGenerator between Roslyn v3.9 and v4.0 Multi-target Json and Logger Source Generators between Roslyn v3.9 and v4.0 Sep 8, 2021
@eerhardt
Copy link
Member Author

eerhardt commented Sep 8, 2021

I believe this is ready for review, assuming dotnet/sdk#20793 gets approved and merged for 6.0.

- Name .cs and .csproj files with Roslyn in the name
- Upgrade to Roslyn 3.11 so IsExplicitlyNamedTupleElement API is available
- Fix some references to the test projects
- Fix incremental pack of the analyzer targets
Copy link
Contributor

@layomia layomia left a comment

Choose a reason for hiding this comment

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

LGTM assuming clean CI & there are no issues relating to dotnet/sdk#20793.

@@ -19,6 +17,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{548DF5F7-790
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{7631380A-FB73-4241-9987-0891A21E9769}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Logging.Generators.Roslyn4.0", "gen\Microsoft.Extensions.Logging.Generators.Roslyn4.0.csproj", "{A5439E79-96D6-4F02-8DD0-23DFF979851D}"
Copy link
Member

Choose a reason for hiding this comment

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

so with future upgrades we have to rename these files?

Copy link
Member

Choose a reason for hiding this comment

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

if yes, do we prefer to use an intermediary name that doesnt have to change with version future changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

My thinking is that future upgrades would mean a new file with the appropriate version in the name. If we were no longer targeting a specific version, we would then delete the file for that version. So if were no longer targeting Roslyn v4.0, but instead wanted to target Roslyn v4.1, we would delete the 4.0 file and add a 4.1 file.

Do you have an idea on what an intermediary name pattern would look like that would make sense, but not require the version number in it?

@eerhardt
Copy link
Member Author

Windows failures are #58927.

Linux_musl x64 failures are infrastructure related.

This has passed CI previously before resolving merge conflicts. Libraries legs are building and tests are passing. Merging to unblock 6.0 work.

@eerhardt eerhardt merged commit 9035d94 into dotnet:main Sep 14, 2021
@eerhardt eerhardt deleted the MultiTargetSGs branch September 14, 2021 03:05
eerhardt added a commit to eerhardt/runtime that referenced this pull request Sep 14, 2021
…nd v4.0 (dotnet#58446)

* Multi-target LoggerMessageGenerator between Roslyn v3.11 and v4.0

* Include a .targets file in NuGet packages which will select the correct analyzer assembly depending on which Roslyn version will be used to compile.

* Multi-target JsonSourceGenerator between Roslyn v3.11 and v4.0

* Fix restore

* Update NuGet package MSBuild logic to detect when SupportsRoslynComponentVersioning is not available, and use the lowest analyzer available.

* Handle non-SDK projects by running after ResolveNuGetPackageAssets

* Respond to PR feedback

- Name .cs and .csproj files with Roslyn in the name
- Upgrade to Roslyn 3.11 so IsExplicitlyNamedTupleElement API is available
- Fix some references to the test projects
- Fix incremental pack of the analyzer targets
danmoseley pushed a commit that referenced this pull request Sep 15, 2021
…nd v4.0 (#58446) (#59074)

* Multi-target LoggerMessageGenerator between Roslyn v3.11 and v4.0

* Include a .targets file in NuGet packages which will select the correct analyzer assembly depending on which Roslyn version will be used to compile.

* Multi-target JsonSourceGenerator between Roslyn v3.11 and v4.0

* Fix restore

* Update NuGet package MSBuild logic to detect when SupportsRoslynComponentVersioning is not available, and use the lowest analyzer available.

* Handle non-SDK projects by running after ResolveNuGetPackageAssets

* Respond to PR feedback

- Name .cs and .csproj files with Roslyn in the name
- Upgrade to Roslyn 3.11 so IsExplicitlyNamedTupleElement API is available
- Fix some references to the test projects
- Fix incremental pack of the analyzer targets
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants