error the in razor.g.cs file, can't find in VS, can't find the _razor.g.cs file
Asked Answered
S

4

17

I'm getting "; expected" error in my .razor file and in _razor.g.cs file,

In previous blazor versions I was finding these g.cs files in the solution folder, now I can't find them there, and double clicking on the error message in VS doesn't point me to anywhere (error message has no line number, the one for .g.cs has a line number), and I can't find the problem.

Where are the _razor.g.cs files located now ?

Senegambia answered 18/2, 2022 at 19:23 Comment(1)
the error was a missing ; after return <renderfragmentmarkup>, for some reason VS has trouble showing me this lineSenegambia
L
32

Edit the project file (.csproj) and add this:

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>   
</PropertyGroup>

The file will by default go to obj\debug\net6.0\generated\...
Click the "Show all files" button to find it.

Leakey answered 18/2, 2022 at 19:41 Comment(0)
D
0

In case it helps someone else, I got this exception when I named razor component the same name as my local model class.

Didynamous answered 21/3 at 14:9 Comment(0)
S
0

I just had this error, and for me the problem was on the Build Action property : When I created the Razor page, VS put a "None" Build Action instead of a "Content" Build Action.

Sawn answered 22/7 at 7:54 Comment(1)
But why make a razor page in a Blazor project?Leakey
E
0

To add to https://mcmap.net/q/695652/-error-the-in-razor-g-cs-file-can-39-t-find-in-vs-can-39-t-find-the-_razor-g-cs-file.

Edit the project file (.csproj):

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>    
    <Compile Remove="_Generated\**\*.g.cs" />
    <None Include="_Generated\**\*.g.cs" />
</ItemGroup>

This allows you to view the .g.cs file in the solution directory and not have it fail to compile.

Erlin answered 2/8 at 5:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.