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

Razor components break source generators #24526

Closed
andrewlock opened this issue Aug 3, 2020 · 6 comments · Fixed by #25292
Closed

Razor components break source generators #24526

andrewlock opened this issue Aug 3, 2020 · 6 comments · Fixed by #25292
Assignees
Labels
bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Milestone

Comments

@andrewlock
Copy link
Contributor

Describe the bug

Source generators do not work correctly in any project project that contains a .razor component. If the compilation depends on the generator output, then compilation fails.

To Reproduce

I have uploaded a proof of concept, using the "Hello world" source generator and the latest .NET 5 preview (5.0.0-preview.7.20364.11): https://github.com/andrewlock/blazor-with-source-generators-poc

The solution includes 4 projects:

  • The Hello World Source Generator from here
  • A basic .NET 5 Console application, demonstrating usage of the source generator. This project compiles, builds, and runs perfectly.
  • A basic Blazor WASM application, demonstrating an identical usage, which doesn't compile, due to using the output of the generator in Program.cs
  • An empty Web project (dotnet new web), with the addition of a single basic Razor component. Without the component, the project builds. With the component, the build fails due to using the output of the generator in Program.cs
Program.cs(16,13): error CS0103: The name 'HelloWorldGenerated' does not exist in the current context [C:\repos\source-generator-poc\src\Web\Web.csproj]
Program.cs(17,13): error CS0103: The name 'HelloWorldGenerated' does not exist in the current context [C:\repos\source-generator-poc\src\BlazorApp1\BlazorApp1.csproj]

An interesting point is that the source generators do appear to be called and executed, but this is happening after the main application compilation. You can see this by viewing the dll produced by the Blazor/Web project, which shows that it contains the HelloWorld class (screenshot taken using Rider):

image

Further technical details

ASP.NET Core version: 5.0.0-preview.7.20364.11
IDE: None (building using .NET CLI)
dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.100-preview.7.20366.6
Commit: 0684df3a5b

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100-preview.7.20366.6\

Host (useful for support):
Version: 5.0.0-preview.7.20364.11
Commit: 53976d38b1

.NET SDKs installed:
1.1.14 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.1.604 [C:\Program Files\dotnet\sdk]
2.1.801 [C:\Program Files\dotnet\sdk]
2.2.203 [C:\Program Files\dotnet\sdk]
3.1.302 [C:\Program Files\dotnet\sdk]
5.0.100-preview.7.20366.6 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0-preview.7.20365.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0-preview.7.20364.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0-preview.7.20366.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Aug 3, 2020
@mkArtakMSFT mkArtakMSFT added this to the Next sprint planning milestone Aug 3, 2020
@ghost
Copy link

ghost commented Aug 3, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@jaredpar
Copy link
Member

@pranavkm

@chsienki
Copy link
Member

This appears to be caused by not passing the @(Analyzer) item group to the compiler.

We recently added a switch that allows you to pass the group, but disable the actual analyzers themselves; that means you generators will run, but you don't waste cycles running unneeded analyzers dotnet/roslyn#46669

@Pilchie
Copy link
Member

Pilchie commented Aug 26, 2020

👀

@chsienki
Copy link
Member

I opened #25292 with a proposed fix.

@mkArtakMSFT mkArtakMSFT linked a pull request Aug 28, 2020 that will close this issue
@mkArtakMSFT mkArtakMSFT added the Done This issue has been fixed label Aug 28, 2020
@mkArtakMSFT
Copy link
Member

Thanks for taking care of this, @chsienki!

@ghost ghost locked as resolved and limited conversation to collaborators Sep 27, 2020
@ghost ghost unlocked this conversation Oct 9, 2021
@dotnet dotnet locked as resolved and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants