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

Microsoft.CodeAnalysis.PublicApiAnalyzers disabled after moving to .NET 7 #7903

Closed
benvillalobos opened this issue Aug 22, 2022 · 14 comments
Closed
Assignees

Comments

@benvillalobos
Copy link
Member

Issue Description

Transitioning MSBuild to net7.0 has raised strange issues from roslyn api analyzers. RS0016 and RS0017 come up as issues but the issues don't seem to make sense. The complaints are about API's not existing (despite them existing). Maybe I'm missing something.

@benvillalobos benvillalobos added bug needs-triage Have yet to determine what bucket this goes in. and removed needs-triage Have yet to determine what bucket this goes in. labels Aug 22, 2022
@benvillalobos
Copy link
Member Author

@rainersigwald has an idea for a modern alternative: PackageBaselineValidator.

EnablePackageValidation=true and some baseline version (whatever the last shipped one was).

rainersigwald added a commit that referenced this issue Sep 19, 2022
Update target framework in MSBuild and related places (consolidating MSBuild references).

Add NoWarn for deprecation warnings (#7902) and API-stability analyzer problems (#7903).

Fix a issues around crypto API simplifications on .NET Core spotted by new analzyers.

Co-authored-by: Rainer Sigwald <[email protected]>
@benvillalobos
Copy link
Member Author

cc @jaredpar we're not sure if this is an actual roslyn bug we should file in the repo.

@benvillalobos
Copy link
Member Author

What's happening is: An analyzer has weird behavior after this retargeting. That analyzer happens to be owned by Roslyn. We're not sure if this is a compiler problem (it's running the analyzer funny and it's producing garbage results) OR it's an analyzer problem (being called correctly but is wrong)

If it's the latter, we should use the modern solution.

@jaredpar
Copy link
Member

Can you give an example of where this fails? Maybe a binlog, a failed build link, etc ... The only ref is a PR that is really long and has tons of builds associated with it.

@mavasani, @jmarolf

@rainersigwald rainersigwald changed the title Roslyn API Analyzers Build Errors In Net7.0 Microsoft.CodeAnalysis.PublicApiAnalyzers disabled after moving to .NET 7 Oct 4, 2022
@Forgind
Copy link
Member

Forgind commented Oct 11, 2022

@jaredpar, @masavani, @jmarolf

Build.txt
^ Binlog (you'll have to convert it back from .txt)

I got this by deleting the contents of all the PublicAPI.Shipped.txt files then trying to build. Note that although there are only 9 errors, if I try resolving just those instances (like with #pragma warning disable flags), others pop up.

@jmarolf
Copy link
Contributor

jmarolf commented Oct 11, 2022

So far these results make sense to me:

Microsoft.Build.Framework.csproj net472  → Build
    Target CoreCompile
        Task Csc
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\Framework\Sdk\SdkResultFactory.cs(24,35): error RS0026: Symbol 'IndicateSuccess' violates the backcompat requirement: 'Do not add multiple overloads with optional parameters'. See 'https://github.com/dotnet/roslyn...
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\Framework\Sdk\SdkResultFactory.cs(35,34): error RS0026: Symbol 'IndicateSuccess' violates the backcompat requirement: 'Do not add multiple overloads with optional parameters'. See 'https://github.com/dotnet/roslyn...
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\Framework\Sdk\SdkResultFactory.cs(59,34): error RS0026: Symbol 'IndicateSuccess' violates the backcompat requirement: 'Do not add multiple overloads with optional parameters'. See 'https://github.com/dotnet/roslyn...
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\Framework\Sdk\SdkResultFactory.cs(24,35): error RS0026: Symbol 'IndicateSuccess' violates the backcompat requirement: 'Do not add multiple overloads with optional parameters'. See 'https://github.com/dotnet/roslyn...
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\Framework\Sdk\SdkResultFactory.cs(35,34): error RS0026: Symbol 'IndicateSuccess' violates the backcompat requirement: 'Do not add multiple overloads with optional parameters'. See 'https://github.com/dotnet/roslyn...
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\Framework\Sdk\SdkResultFactory.cs(59,34): error RS0026: Symbol 'IndicateSuccess' violates the backcompat requirement: 'Do not add multiple overloads with optional parameters'. See 'https://github.com/dotnet/roslyn...
StringTools.csproj net7.0 
    Target CoreCompile
        Task Csc
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\StringTools\SpanBasedStringBuilder.cs(107,16): error RS0027: Symbol 'SpanBasedStringBuilder' violates the backcompat requirement: 'Public API with optional parameter(s) should have the most parameters amongst its ...
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\StringTools\SpanBasedStringBuilder.cs(107,16): error RS0027: Symbol 'SpanBasedStringBuilder' violates the backcompat requirement: 'Public API with optional parameter(s) should have the most parameters amongst its ...
            Error C:\Users\namytelk\Documents\GitHub\msbuild\src\StringTools\SpanBasedStringBuilder.Simple.cs(80,16): error RS0027: Symbol 'SpanBasedStringBuilder' violates the backcompat requirement: 'Public API with optional parameter(s) should have the most parameters amongs...

You should get the same error for each TFM in a multi-tfm project because there are that many compilations happening

@jmarolf
Copy link
Contributor

jmarolf commented Oct 11, 2022

@benvillalobos @Forgind what are the repo steps? I cloen MSBuild, do a build with the repo targeting .net 6 and then do another targeting .net7?

@Forgind
Copy link
Member

Forgind commented Oct 11, 2022

@benvillalobos @Forgind what are the repo steps? I cloen MSBuild, do a build with the repo targeting .net 6 and then do another targeting .net7?

I got this by deleting the contents of all the PublicAPI.Shipped.txt files then trying to build.

No retargeting necessary.

I'm not worried about there being multiples of a single line; as you say, that part is expected. My confusion is around why RS0026/RS0027 should pop up after deleting the contents of the public api files but not before.

In any event, the more clearly wrong behavior is around RS0016 and RS0017. We currently NoWarn those in Directory.Build.props. If you remove those NoWarns and try building, you'll get those to pop up, saying things are part of the public API but cannot be found. On the other hand, if you open Visual Studio (with the NoWarns removed) and look at, for example, NativeMethods.IFixedTypeInfo.ReleaveVarDesc, it has the green squiggle saying it isn't part of the declared API and should be. Those two statements are directly contradictory.

@rainersigwald
Copy link
Member

@jmarolf #8053 should fail and produce binlogs.

@rainersigwald
Copy link
Member

Yeah, there we go

https://dev.azure.com/dnceng-public/_apis/resources/Containers/28745810/FullOnWindows%20Release%20build%20logs?itemPath=FullOnWindows%20Release%20build%20logs%2FBuild.binlog

Errors
    D:\a\1\s\src\Tasks\IVbcHostObject5.cs(23,13): error RS0016: Symbol 'CompileAsync' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(34,14): error RS0016: Symbol 'GetTypeAttr' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(36,14): error RS0016: Symbol 'GetFuncDesc' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(37,14): error RS0016: Symbol 'GetVarDesc' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(39,14): error RS0016: Symbol 'GetRefTypeOfImplType' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(42,14): error RS0016: Symbol 'Invoke' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(44,14): error RS0016: Symbol 'GetDllEntry' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(45,14): error RS0016: Symbol 'GetRefTypeInfo' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(46,14): error RS0016: Symbol 'AddressOfMember' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(51,14): error RS0016: Symbol 'ReleaseTypeAttr' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(53,14): error RS0016: Symbol 'ReleaseFuncDesc' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\NativeMethods.cs(55,14): error RS0016: Symbol 'ReleaseVarDesc' is not part of the declared API [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1323,1): error RS0017: Symbol 'Microsoft.Build.Tasks.Hosting.IVbcHostObject5.CompileAsync(out System.IntPtr buildSucceededEvent, out System.IntPtr buildFailedEvent) -> int' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1332,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.AddressOfMember(int memid, System.Runtime.InteropServices.ComTypes.INVOKEKIND invKind, out System.IntPtr ppv) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1335,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.GetDllEntry(int memid, System.Runtime.InteropServices.ComTypes.INVOKEKIND invKind, System.IntPtr pBstrDllName, System.IntPtr pBstrName, System.IntPtr pwOrdinal) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1337,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.GetFuncDesc(int index, out System.IntPtr ppFuncDesc) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1342,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.GetRefTypeInfo(System.IntPtr hRef, out Microsoft.Build.Tasks.IFixedTypeInfo ppTI) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1343,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.GetRefTypeOfImplType(int index, out System.IntPtr href) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1344,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.GetTypeAttr(out System.IntPtr ppTypeAttr) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1346,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.GetVarDesc(int index, out System.IntPtr ppVarDesc) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1347,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.Invoke(object pvInstance, int memid, short wFlags, ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams, System.IntPtr pVarResult, System.IntPtr pExcepInfo, out int puArgErr) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1348,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.ReleaseFuncDesc(System.IntPtr pFuncDesc) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1349,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.ReleaseTypeAttr(System.IntPtr pTypeAttr) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]
    D:\a\1\s\src\Tasks\PublicAPI\netstandard\PublicAPI.Shipped.txt(1350,1): error RS0017: Symbol 'Microsoft.Build.Tasks.IFixedTypeInfo.ReleaseVarDesc(System.IntPtr pVarDesc) -> void' is part of the declared API, but is either not public or could not be found [D:\a\1\s\src\Tasks\Microsoft.Build.Tasks.csproj]

@jmarolf
Copy link
Contributor

jmarolf commented Oct 11, 2022

hmm, looking at the binlog it doesn't appear that the path to the PublicAPI.Shipped.txt/PublicAPI.Unshipped.txt files is correct in your build:

AdditionalFiles
    D:\a\1\s\src\BannedSymbols.txt
        Link = BannedSymbols.txt
    PublicAPI/netstandard/PublicAPI.Shipped.txt
    PublicAPI/netstandard/PublicAPI.Unshipped.txt

I assume these should be absolute paths?

<AdditionalFiles Include="PublicAPI/$(PublicApiTfm)/PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI/$(PublicApiTfm)/PublicAPI.Unshipped.txt" />

@jmarolf
Copy link
Contributor

jmarolf commented Oct 11, 2022

nevermind the existing targets are correct

@Forgind
Copy link
Member

Forgind commented Oct 25, 2022

@jmarolf, what's the status on this? Just want to make sure you have everything you need to continue investigating.

@Forgind Forgind self-assigned this Dec 7, 2022
JaynieBai pushed a commit that referenced this issue Dec 20, 2022
Fixes-ish #7903

Context
Our previous analyzer is not helpful due to #7903. This switches to using a more modern api analyzer.

Notes
The note that inspired this suggested including a version as well, but the documentation I found didn't mention a version.
@AR-May
Copy link
Member

AR-May commented Jun 6, 2023

We moved to Dotnet SDK integrated code analysis, so we do not need this anymore.

@AR-May AR-May closed this as completed Jun 6, 2023
@AR-May AR-May reopened this Jun 6, 2023
@AR-May AR-May closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2023
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants