Skip to content

Change analyzer versions such that the repo can be built with .NET 7 RC2 SDK #3077

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

Merged
merged 2 commits into from
Oct 25, 2022

Conversation

vitek-karas
Copy link
Member

Took the versions from dotnet/runtime.

…RC2 SDK.

Took the versions from dotnet/runtime.
@tlakollo
Copy link
Contributor

I was debugging some of the failures too for my runtime PR, after updating to MicrosoftCodeAnalysisVersion 4.5.* the roslyn analyzers will start generating duplicate warnings on attribute scenarios seems like the compilation now takes into account more stuff and creates callbacks for object creations that it didn't before. I though it was just going to be a change like removing the CheckAttributeInstantiation method but seems like it's more conversome than that

@tlakollo
Copy link
Contributor

Never mind, removing CheckAttributeInstantiation is the solution. I saw some tests failing after removing the method but it was because before CheckAttributeInstantiation was producing double warnings. With the current analysis, only one warning is produced (which is the right outcome).

@sbomer
Copy link
Member

sbomer commented Oct 24, 2022

@tlakollo would you mind porting the fixes from your branch to this PR?

@tlakollo
Copy link
Contributor

@tlakollo would you mind porting the fixes from your branch to this PR?

Sure, working on it

Remove global attributes since they are no longer necessary
Workaround the fact that compiler injects System.Runtime.CompilerServices.RefSafetyRulesAttribute into every assembly to describe the language version
@tlakollo tlakollo requested a review from sbomer as a code owner October 25, 2022 00:35
@@ -205,21 +188,6 @@ public override void Initialize (AnalysisContext context)
foreach (var extraSymbolAction in ExtraSymbolActions)
context.RegisterSymbolAction (extraSymbolAction.Action, extraSymbolAction.SymbolKind);

void CheckAttributeInstantiation (
Copy link
Member Author

Choose a reason for hiding this comment

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

Why is it OK to remove this?
Where is the place we perform this check now? (and why did it change with a new analyzer package version)

Copy link
Contributor

Choose a reason for hiding this comment

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

There is new callback calls in attributes, for at least one scenario (I didn't test all scenarios) instead of going through a type argument it went through an object creation, basically when it sees the use of the attribute it created a callback for object creation and then we have a CheckMemberCall that verifies that it has requires producing the warning. My guess is that it was a limitation of the analyzer that we had to work around, just like the global attribute and at somepoint it got fixed

Copy link
Member Author

Choose a reason for hiding this comment

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

OK - I guess if all the tests are passing, it's at least not completely broken

@vitek-karas
Copy link
Member Author

One observation on a machine with RC2 installed:
Clean clone of the repo

  • When built with "build.cmd" following usage in VS will fail (exception during build)
  • Building from command line with just dotnet build illink.sln will work and then VS also works
  • Running all tests in that mode is dotnet test illink.sln

Once the repo is built with build.cmd (which will use RC1), trying to build with RC2 may fail (and in VS it does).
If the repo is built with RC2 dotnet build illink.sln then building with build.cmd may work (it did for me), but I would suspect things will be weird eventually.

So unfortunately this means that if you need to use VS - don't use build.cmd. And make sure you clean the clone (git clean -xdf) before building for the first time.

I'm guessing that this is due to some kind of breaking change between RC1 and RC2.

The problems should go away once we switch the SDK to RC2 in the global.json (but we have to wait for dotnet/runtime to do that first).

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @tlakollo!

@vitek-karas
Copy link
Member Author

lint is even worse - so far I didn't find a way to run on the RC2 bits. It works when the repo is built with RC1.

Does anybody know where we get the dotnet format tool from? I can't find anything in the repo which says what version of that tool to use.

@sbomer
Copy link
Member

sbomer commented Oct 25, 2022

It's included in the SDK, and I don't think we try to override the dotnet-format version anywhere.

@vitek-karas
Copy link
Member Author

Unfortunately the RC2 dotnet format fails with:

Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.5.0.0,

So it seems that the only way to run linter is to clean the enlistment and use the lint.cmd which will download RC1. And then clean it again and rebuild to run VS.

@vitek-karas
Copy link
Member Author

I don't get it - RC1 ships format with Microsoft.CodeAnalysis 4.3.0.0 - and it works
RC2 ships format with Microsoft.CodeAnalysis 4.4.0.0 - and it doesn't work
I give up - let's merge this - so that at least there's some way to use VS.

@tlakollo
Copy link
Contributor

Notice that runtime has this same behavior, you cannot run dotnet format at all. I've been changing the versions.props file to be able to run the formater for the linker to runtime move PR. In the runtime repo it fails with "Could not load file or assembly 'Microsoft.CodeAnalysis.Workspaces, Version=4.4.0.0" which Im guessing is part of the Microsoft.CodeAnalysis

@tlakollo tlakollo merged commit c0bd208 into dotnet:main Oct 25, 2022
jtschuster pushed a commit to jtschuster/linker that referenced this pull request Oct 25, 2022
…RC2 SDK (dotnet#3077)

Change analyzer versions such that the repo can be built with .NET 7 RC2 SDK.
- Took the versions from dotnet/runtime.
- Remove CheckAttributeInstantiation method since is no longer necessary
- Remove global attributes since they are no longer necessary
- Workaround the fact that compiler injects System.Runtime.CompilerServices.RefSafetyRulesAttribute into every assembly to describe the language version

Co-authored-by: tlakollo <tlakaelel_axayakatl@outlook.com>
tlakollo pushed a commit to tlakollo/runtime that referenced this pull request Oct 27, 2022
…RC2 SDK (dotnet/linker#3077)

Change analyzer versions such that the repo can be built with .NET 7 RC2 SDK.
- Took the versions from dotnet/runtime.
- Remove CheckAttributeInstantiation method since is no longer necessary
- Remove global attributes since they are no longer necessary
- Workaround the fact that compiler injects System.Runtime.CompilerServices.RefSafetyRulesAttribute into every assembly to describe the language version

Co-authored-by: tlakollo <tlakaelel_axayakatl@outlook.com>

Commit migrated from dotnet/linker@c0bd208
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…RC2 SDK (dotnet/linker#3077)

Change analyzer versions such that the repo can be built with .NET 7 RC2 SDK.
- Took the versions from dotnet/runtime.
- Remove CheckAttributeInstantiation method since is no longer necessary
- Remove global attributes since they are no longer necessary
- Workaround the fact that compiler injects System.Runtime.CompilerServices.RefSafetyRulesAttribute into every assembly to describe the language version

Co-authored-by: tlakollo <tlakaelel_axayakatl@outlook.com>

Commit migrated from dotnet/linker@c0bd208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants