Create, Reference and use a Razor class library.

Rafaeleliasgri 25 Reputation points
2024-04-24T15:49:23.6733333+00:00

Hello!
I'm training on Microsoft Learn. My current stage is the following module:

https://zcusa.951200.xyz/en-us/training/modules/blazor-build-reusable-components/3-create-razor-class-library

User's image

First of all, this exercise starts saying that it uses the .NET 6.0 SDK. However, the instructions given on it are all for .NET 8.0 SDK.

I strictly followed the instructions for four times, initially using .NET 8.0 SDK, then tried with .NET 6.0 SDK (it wasn't possible to create a new blazor app with the option -f net6.0) and all times got the same problem showed below:

User's image

I've successfully made the reference to FirstClassLibrary as instructed.

It seems that there's some problem on this exercise's instructions. Maybe lacking some step.
I appreciate in advance any help given.
Thank you!

Rafael Elias.

This question is related to the following Learning Module

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,877 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,584 questions
0 comments No comments
{count} vote

Accepted answer
  1. Bruce (SqlWork.com) 65,576 Reputation points
    2024-04-24T16:22:57.96+00:00

    you seem to have missed the step:

    dotnet add reference ../FirstClassLibrary

    in the blazer project folder, or the folders are not siblings.

    note: I did the tutorial on my Mac with net 8, took a couple minutes and ran the first time.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. cantcacheme 0 Reputation points
    2024-08-19T19:17:39.46+00:00

    I ran into the same issues. I ran through the steps more than 4 times and always had an issue with "using" statement on the _Imports.razor file. I tried using only the command line commands, setting up projects as GUIs, saving the projects on my local computer and not my attached cloud storage provider, closing Visual Studio in between creating projects and saving edits, plus the suggestions listed on this page. I have been using Visual Studio (not Code) as that is what my school encourages us to use.

    I found that I was able to get a success message using the command line in Visual Studio about a successful reference if I used the following syntax:

    dotnet add [path to FirstClassLibrary.csproj] reference [path to FirstClassLibrary folder]
    

    Unfortunately, I still continued to have errors with the _Imports.razor file.

    I decided to run through the steps above using the terminal commands and Visual Studio Code to see if I got a different outcome and got it to work on my first try.

    I thought I'd mention my success here in case anyone else has a similar issue. I'm still not sure why it works in Visual Studio Code and not Visual Studio, but at least I got it to finally work!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.