msbuild
msbuild copied to clipboard
Roslyn API Analyzers Build Errors In Net7.0
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.
@rainersigwald has an idea for a modern alternative: PackageBaselineValidator.
EnablePackageValidation=true and some baseline version (whatever the last shipped one was).
cc @jaredpar we're not sure if this is an actual roslyn bug we should file in the repo.
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.
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
@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.
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
@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?
@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.
@jmarolf https://github.com/dotnet/msbuild/pull/8053 should fail and produce binlogs.
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]
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?
https://github.com/dotnet/msbuild/blob/a440ea9cf00113537cde999052649b4a8922c488/src/Directory.Build.targets#L98-L99
nevermind the existing targets are correct
@jmarolf, what's the status on this? Just want to make sure you have everything you need to continue investigating.
We moved to Dotnet SDK integrated code analysis, so we do not need this anymore.