Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Blazor Web App (.net 8 server) - Razor Component Library RCL as NuGet (Local Feed) w MainLayout style sharing

$
0
0

Updated after finding answer for future reference of those with issue

What I was trying to do:

Use MainLayout on my webapp to make use of the RCL's razor component to pass in a navmenu and use the shared libraries styling etc.

I have a RCL that contains 2 razor components 'NavMenu.razor' and 'SharedLayout.razor'.

So any new team can bring in the nuget package and work with the default mainlayout styling component we determine. (later to add in a shared IdentityService).

TLDR : Answered on Reddit kept here for others with some edits for clarity and expediency.

The problem was that I had included a tag that explicitly caused the NuGet to generate razor files and place them into the project that added the NuGet, causing all manner of issues with naming conflicts and lack of references.

This is what my project looks like when referenced :Working Project Reference to RCL

The code works in this setup, just to share quickly what's going on with it for context:Routes file references this MainLayout.razor as the default layout

This looks like this when loaded:Working with proj ref

What I was Stuck on - as NuGet

However for the next step I wanted to create a NuGet to share the RCL across projects.So I setup the RCL project file like this:

proj file for the RCL

The Example Server project I marked as false.

** note the tag in the project calling for 'includeRazorContentInPack' this was the problem**

building the nuget

Then push to a local feed nuget location.push to local feed

I can then reference this nuget source from another project:Nuget local feed with package

Solution Structure with Nuget:

What my solution looks like after bringing in the Nuget

It placed the NuGets razor files in the solution. (resolved after moving tag)

Problems:

I have not edited the below problem section from when written. for fix see answer comment.

Log File - Proj Reload (resolved? via clean)Right away I was having issues with Visual Studio telling me that there was an unexpected problem loading of my project.

On bringing in the NuGet

By mucking around with _import and fully declaring components I can get this error to clear.Deleting .vs bin obj...

The log file talks about an issue with Base path:I can provide the full log if anyone thinks it'll help.

log for project load failure

Multiple Components Named the same.

When I brought in the nuget I received a multiple components using same tag error for both the SharedLayout and the NavMenu from the RCL NuGet.webapp mainlayout componentref

I added in a @ using statement to the _Import.razor of the NuGet to reference the components. Which wasn't needed when using the proj ref as they were in the same namespace.

_import razor of RCL using statement

I also explicitly referenced the NavMenu component in the SharedLayout.razor file.

shared layout in RCL explicit ref but failure?

In the MainLayout of the actual webapp I fully referenced the SharedLayout... all these seemed to clear up this error.

mainlayout on WebApp explicit

I'd rather find a different way to handle this error. As there is only 1 component of that name, so the error's a bit strange, like it's duplicating components into namespace.

No Errors but failure

A mix of me referencing components in the RCL before producing as a nuget allowed it to build with no errors. But It's obviously failed to load correctly. Is this still something I've gotten wrong with working with a RCL NuGet or is this some incompatibility to send @ body to a Nuget?

failure on run with no errors

I was expecting to be able to bring in a NuGet package that contained a Razor Component, and pass in parameters and values into the components. Including the body render fragment.

To use the NuGets Styling sheet (not included in this example as failure occurred before this attempt). To allow for a consistent look across any app that uses the sharedlayout component.

Allowing dynamic Nav by passing in the items to display.(as shown in the MainLayout.razor file and working as shown in proj example picture).

To work as it did when referencing a project.


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>