project-system icon indicating copy to clipboard operation
project-system copied to clipboard

Blazor page relocation causes non compilable project

Open hu1buerger opened this issue 3 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

  1. Initialize a blazor project.
  2. Create a blazor page (in /Pages) Example.razor:
@page "/Example"
<h3>Example</h3>


@code {

    protected override void OnInitialized()
    {
        base.OnInitialized();
        Console.Out.Write("this should run, and compile");
    }
}
  1. Move the code to a code behind class

Pages/Example.razor.cs

namespace Project.Pages;

public partial class Example
{
    protected override void OnInitialized()
    {
        base.OnInitialized();
        Console.Out.Write("this should run, and compile");
    }
}
  1. Move the Example.razor from /Pages to /Areas/Core/Pages and change the namespace to Project.Areas.Core.Pages
  2. Run the project.
  3. Find that the project is not compiling due to no suitable method to overide in Example.razor.cs

Expected Behavior

Relocating a blazorpage with code-behind should compile, like a relocated blazorpage with code within is compiling

Steps To Reproduce

S.a.

Exceptions (if any)

No response

.NET Version

6.0.104

Anything else?

Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET

hu1buerger avatar May 08 '22 14:05 hu1buerger

Removing the ItemGroups including the Pages directorys


<ItemGroup>
    <AdditionalFiles Include="Areas[...]\Index.razor" />
</ItemGroup>
<ItemGroup> 
  <Folder Include="Areas\DatasetFeatures\Pages" />
</ItemGroup>

from the .csproj seems to fix the build exception

hu1buerger avatar May 08 '22 14:05 hu1buerger

@NTaylorMullen I suspect this might be something that CSP is doing?

/cc: @jaredpar

javiercn avatar May 09 '22 10:05 javiercn

Moving to project system. This seems like an issue with the sync namespaces feature.

If I follow the repro steps above, the namespace in Example.razor.cs is not updated. If I follow the repro, but in step 4 I just move the Example.razor.cs file directly, it does get updated. Seems project-system/CPS is not correctly syncing namespaces of nested files.

davidwengier avatar Jul 04 '22 05:07 davidwengier