dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
496 stars 191 forks source link

Blazor Server does not see RCL components #9696

Open mayur-ekbote opened 10 months ago

mayur-ekbote commented 10 months ago

Is there an existing issue for this?

Describe the bug

I recently updated to .net 8. I have both VS 2022 and 2022 Preview version installed.

  1. When I run this project from Visual Studio Preview, the app runs fine.
  2. If I publish the project to a folder, the app cannot find static assets of the RCL (error in the browser console - 404 CSS not found)
  3. If I run this project from the non-preview version of Visual Studio, I still have the same problem

That was for an existing component. Now, if I add any new component to the RCL, it is not recognized by either of these versions at all! If I create SomeComponent.razor and use it anywhere in the Blazor server project, <SomeComponent /> gets rendered as <somecomponent/> and obviously does appear on the page.

I have tried:

  1. Removing everything in .vs .bin .obj folders everywhere.
  2. Repairing both VS editions
  3. Creating Directory.Build.props and adding
    <PropertyGroup>
      <AccelerateBuildsInVisualStudio>false</AccelerateBuildsInVisualStudio>
    </PropertyGroup>
  4. Creating another RCL and creating a component in that (same problem)

Now, here is the kicker: I wanted to create a repro, but I did not see the .net 8 in the create new project wizard! (.net 8 is installed and is being used by VS for running the app.)

Is there anyway to diagnose this? I remember encountering this problem a couple of years ago, but it was fixed.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.100

Anything else?

No response

garrettlondon1 commented 10 months ago

Misread - Blazor Server

mayur-ekbote commented 10 months ago

Can you please elaborate? I am not sure what you mean by AdditionalAssemblies

ghost commented 10 months ago

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

mayur-ekbote commented 10 months ago

@surayya-MS It is not possible to provide a repro:

Now, here is the kicker: I wanted to create a repro, but I did not see the .net 8 in the create new project wizard! (.net 8 is installed and is being used by VS for running the app.)

Also, this is not a new issue. Please see: #5001

Is there anyway to diagnose this? I remember encountering this problem a couple of years ago, but it was fixed.

surayya-MS commented 10 months ago

@mayur-ekbote , could you please create a .net 7 Blazor Server app and then update to .net 8?

danroth27 commented 10 months ago

Here's what I tried:

It seems to work fine:

image

mayur-ekbote commented 10 months ago

I followed the 'create .net 7 -> upgrade to .net 8' path and the issues seems to be stemming from VS losing intellisense.

  1. Create a .net 7 Blazor Server app
  2. Create a .net 7 RCL
  3. Refer RCL from the Blazor app and use a component from the RCL. It works fine
  4. Now upgrade both projects using Upgrade tool.
  5. Create a folder in RCL and add a component to that folder.
  6. At this point, the IDE neither sees the newly created folder, nor does it see the component itself.
  7. However, the runtime seems to be working once the reference is added.

(Please refer to attached video for the remaining)

https://1drv.ms/v/s!Am6vW_yz2H5DhOMuAYtoelJ6hW-Kyw?e=5Y72sS

Ideally, IntelliSense should tell that TestComponent is inside ReferenceLibrary.InnerComponent. Not only does it not, but also doesn't recognize the component even after it is added and program is run.

In a project with many folder hierarchies, it is hard to know which inner folders have been referred to - since IntelliSense doesn't even see those namespaces.

However, the divergence in the behavior between VS preview and VS seems to have been fixed after the last release of VS.

javiercn commented 10 months ago

However, the runtime seems to be working once the reference is added.

Do you mean it works fine when you run or if you build/run from the command-line?

Now upgrade both projects using Upgrade tool.

This might leave the projects in an unknown state. Does cleaning (physically removing) the bin/obj folders after this step makes the issue go away?

mayur-ekbote commented 10 months ago

Do you mean it works fine when you run or if you build/run from the command-line?

After the last update, it works fine from VS too. However, the IDE does not recognize the component. The actual output on running the project is fine (check the ending of the video). Which is to say that the original problem doesn't arise.

This might leave the projects in an unknown state. Does cleaning (physically removing) the bin/obj folders after this step makes the issue go away?

In a small repro, it does go away. However, in my actual project, it doesn't. (See the screenshot). Basically, I end up coding blind since IntelliSense shows no hints - rather keeps saying if I want to create a new component from the tag. The actual application works as expected. I haven't checked with the additional CSS yet.

UserInterface

javiercn commented 10 months ago

@mayur-ekbote thanks for the additional details.

It seems that this is tooling related, so I'll let them chime in here as they are the experts.

davidwengier commented 10 months ago

I know you said you removed the obj folders everywhere, which is good, but it is surprising that this fixes the issue in a simple repro project, but not in your real project. I just tried the full repro in that version (new .NET 7 projects, upgrade assistant on both, add new folder and component etc.) and it worked fine, which seems to confirm your results too.

Is there anything in your real project that does any "fancy" msbuild things, like configuring the IntermediateOutputPath, or even maybe opting in to the new artifacts layout? Are any of your projects multitargeting?

Would it be possible for you to list the file paths involved in your real project? It would be useful to get an idea of where the .sln file is, where all of the .csproj files are, their relationships to each other, etc. It would also be useful to get a list of all of the project.razor.vs.bin files anywhere on the file system, inside your solution directory.

It sounds a lot like the issue would be fixed by https://github.com/dotnet/razor/pull/9601, which has just shipped in Visual Studio 17.9 Preview 2, however it also should have been fixed by cleaning out all of the obj folders, so I can't be fully confident when I say that. If it is possible for you to try the new preview release, it would be very useful to know if the problem is fixed in that version.

mayur-ekbote commented 10 months ago

I am not doing anything fancy. (multi targeting, intermediateoutputpath etc). I upgraded to Preview 2. The issue persists, IntelliSense doesn't see the components, it also doesn't see all the namespaces. Check the screenshot:

No Namespaces

davidwengier commented 9 months ago

Thanks for the reply @mayur-ekbote, but unfortunately I'm not sure what the next steps here would be, if the issue only repros in your project, and not in a simple one.

Does the issue get fixed if you open one of the files that is missing from intellisense? Would it be possible for you to list the file paths involved in your real project? It would be useful to get an idea of where the .sln file is, where all of the .csproj files are, their relationships to each other, etc. It would also be useful to get a list of all of the project.razor.vs.bin files anywhere on the file system, inside your solution directory.

If you'd be willing, it would be most useful if you can zip up your project and email it to me (david.wengier at microsoft.com) so I could see if I can reproduce it on my machine, with the exact setup you have.

mayur-ekbote commented 9 months ago

It is not possible to share the project (proprietary + large). However, I can share my desktop over a remote zoom/teams session. You can look through any project files you want to figure out the conditions that can reproduce the bug.

mayur-ekbote commented 8 months ago

Any update on this? The latest VS updates don't fix this

phil-allen-msft commented 8 months ago

@mayur-ekbote , let's work out a time to meet and share screens, you can contact me

mayur-ekbote commented 8 months ago

Upon inspection of the csproj file, I saw that the following lines were added. I have no idea what triggered this addition and why this razor component was added (it doesn't happen with all malfunctioning razor components)

<ItemGroup>
    <UpToDateCheckInput Remove="Pages\Instruction\Fragments\SymbolLabel.razor" />
  </ItemGroup>
  <ItemGroup>
    <_ContentIncludedByDefault Remove="Pages\Instruction\Fragments\SymbolLabel.razor" />
  </ItemGroup>
zacuke commented 7 months ago

I'm creating a new Blazor Server app with components in a shared RCL. I noticed the designer was failing to recognize my components in the RCL, yet the application was running fine.

After deleting the bin and obj folders, the designer started recognizing the components in RCL correctly.

Then, I backed my RCL out of the solution and got the Blazor Server app to build and run stand alone again. After re-adding the RCL and referencing its components, this problem returns: I can run the Blazor Server app, but the designer has errors about missing classes for the shared components.

In summary, steps to reproduce seem to be:

  1. Create new Blazor Server app and run it at least once
  2. Create RCL and some components
  3. Reference these components from the Blazor Server app.
  4. The app runs correctly but the designer is showing errors.

And to fix:

  1. Close visual studio
  2. Delete bin and obj folders from Blazor Server app
danroth27 commented 7 months ago

I'm creating a new Blazor Server app with components in a shared RCL. I noticed the designer was failing to recognize my components in the RCL, yet the application was running fine.

@zacuke What version of Visual Studio are you using?

zacuke commented 7 months ago

Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.9.2

The projects both target .net 8

Output from dotnet --list-sdks: 6.0.419 [C:\Program Files\dotnet\sdk] 8.0.200 [C:\Program Files\dotnet\sdk]

mayur-ekbote commented 6 months ago

Is there any update on this? I am unable to create debug points in the file. Not that I can't create debug points at all. But I can create debug points till a line in the file and then I can't! Check the video:

https://github.com/dotnet/razor/assets/40038634/e0fc263c-d54e-4447-bc56-79a98ac0d01b

danroth27 commented 6 months ago

@mayur-ekbote The issue you're describing does look like a bug, but it seems different from this one. I recommend opening a Visual Studio feedback ticket with detailed steps on how to reproduce the problem you are seeing.