buga
buga

Reputation: 1364

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

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 ?

Upvotes: 19

Views: 11422

Answers (4)

Jervis
Jervis

Reputation: 124

To add to https://stackoverflow.com/a/71179023/8163839.

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.

Upvotes: 0

Christian Navelot
Christian Navelot

Reputation: 1164

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.

Upvotes: 0

Henk Holterman
Henk Holterman

Reputation: 273464

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.

Upvotes: 34

Stephen N
Stephen N

Reputation: 9

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

Upvotes: 0

Related Questions