Closed p2pbsh closed 2 years ago
Thanks @p2pbsh.
@dougbu @pranavkm Do either of you have any idea why this would have started happening?
Some extra info if it helps, not the only one experiencing the issue:
@dougbu Possibly related to work in https://github.com/dotnet/aspnetcore/pull/39293
Incredibly doubtful @p2pbsh. Did you mean another PR or issue❔
@dougbu @pranavkm Do either of you have any idea why this would have started happening?
The problem is unaligned Microsoft.CodeAnalysis versions. In dotnet/sdk, release/6.0.2xx references the 4.1.0-5.22116.13
version while the dotnet/razor-compiler repo's release/6.0.2xx branch references the 4.0.1
version. 4.0.1
and 4.1.0-*
must not be compatible. (The generator comes from dotnet/aspnetcore in the 6.0.1xx SDK. Those versions seem fine.)
@marcpopMSFT is this already a known issue in the 6.0.200 release❔
Hi @dougbu , was just speculation on my part, #39293 looked like the only PR in the changelog that could potentially impact the build process.
Should have also clarified , I can build locally with 6.0.200 using VS 17.1 just fine. Issue only occurs when invoking msbuild via the devops VS build task.
Greetings
i've managed to workaround the issue by adding a reference to Microsoft.CodeAnalysis.CSharp 4.0.1
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.2" PrivateAssets="all" />
<!-- Microsoft.CodeAnalysis.CSharp is an attempt to workaround https://github.com/dotnet/aspnetcore/issues/40333 -->
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
</ItemGroup>
</Project>
Thanks for contacting us and glad that you've found a way to resolve your issue. Looks like the underlying issue is framework MSBuild issue and we'll look into how we can address that in the future.
Just a note for anyone else running into this issue. I was using VS2022 Pro 17.0.5. I upgraded the .NET SDK from 6.0.101 to 6.0.200 and razor pages would not route when debugging on localhost or published versions. I upgraded VS2022 to 17.1 and razor pages started working again. I didn't need to add the above package reference workaround.
Edit: I originally tested this with an asp.net core app with razor pages. I also tested our blazor wasm project and its razor pages are routing as well.
After my devops pipeline started pulling in SDK 6.0.200 for the VS build task, Blazor projects now fail compilation with source generator errors.
To reproduce, created basic Blazor server project from VS template, added a call to OnAfterRenderAsync in a razor cs code behind file, attempted to build in a Windows 2022 Azure pipeline VS build task.
Following error encountered:
[warning]CSC(0,0): Warning CS8032: An instance of analyzer Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator cannot be created from C:\hostedtoolcache\windows\dotnet\sdk\6.0.200\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
CSC : warning CS8032: An instance of analyzer Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator cannot be created from C:\hostedtoolcache\windows\dotnet\sdk\6.0.200\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [D:\a\1\s\BlazorApp1\BlazorApp1.csproj]
[error]BlazorApp1\Pages\Counter.razor.cs(12,39): Error CS0115: 'Counter.OnAfterRenderAsync(bool)': no suitable method found to override
Build works fine using SDK 6.0.102
@dougbu Possibly related to work in #39293