SonarSource/sonar-dotnet

TestFramework: razor analysis is not supported starting with dotnet 8.0.5

Closed this issue · 0 comments

Description

The latest version of dotnet moved the razor source generators to Microsoft.CodeAnalysis.Razor.Compiler.dll. Due to this razor file analysis is not supported by the test framework.

Before:

Directory: C:\Program Files\dotnet\sdk\8.0.202\Sdks\Microsoft.NET.Sdk.Razor\source-generators

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          1/3/2024   7:28 PM          81952 Microsoft.AspNetCore.Razor.Utilities.Shared.dll
-a----          1/3/2024   7:28 PM          46717 Microsoft.AspNetCore.Razor.Utilities.Shared.xml
-a----          1/3/2024   7:29 PM         101408 Microsoft.CodeAnalysis.Razor.Compiler.CSharp.dll
-a----          1/3/2024   7:29 PM        1091104 Microsoft.CodeAnalysis.Razor.Compiler.Language.dll
-a----          1/3/2024   7:29 PM          86552 Microsoft.CodeAnalysis.Razor.Compiler.Mvc.dll
-a----          1/3/2024   7:30 PM          19722 Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators.deps.json
-a----          1/3/2024   7:30 PM          66088 Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators.dll
-a----        10/26/2021  10:52 PM          23664 Microsoft.Extensions.ObjectPool.dll
-a----          1/3/2024   7:24 PM             71 RazorSourceGenerator.razorencconfig
-a----        10/18/2022   5:24 PM         198776 System.Collections.Immutable.dll

after:

Directory: C:\Program Files\dotnet\sdk\8.0.300\Sdks\Microsoft.NET.Sdk.Razor\source-generators

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         4/16/2024   9:43 AM          81448 Microsoft.AspNetCore.Razor.Utilities.Shared.dll
-a----         4/16/2024   9:43 AM          46717 Microsoft.AspNetCore.Razor.Utilities.Shared.xml
-a----         4/16/2024   9:43 AM          18321 Microsoft.CodeAnalysis.Razor.Compiler.deps.json
-a----         4/16/2024   9:43 AM        1352744 Microsoft.CodeAnalysis.Razor.Compiler.dll
-a----         11/1/2023  12:07 AM          25376 Microsoft.Extensions.ObjectPool.dll
-a----         4/16/2024   9:39 AM             71 RazorSourceGenerator.razorencconfig
-a----        10/31/2023   2:01 PM         252680 System.Collections.Immutable.dll

Now the test fail with:

Expected compilation.Compilation.SyntaxTrees to contain a single item, but the collection is empty.
   at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Execution.AssertionScope.FailWith(String message)
   at FluentAssertions.Collections.GenericCollectionAssertions`3.ContainSingle(String because, Object[] becauseArgs)
   at SonarAnalyzer.Test.TestFramework.Tests.Verification.VerifierTest.Compile_Cshtml_Snippet() in C:\src\work\sonar-dotnet\analyzers\tests\SonarAnalyzer.TestFramework.Test\Verification\VerifierTest.cs:line 295
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)