Search code examples
blazorwebassembly

How to add server and shared project to Blazor Web Assembly app?


When creating a new Blazor Web Assembly app, I had selected core hosted so I got the server and shared projects added.

But then someone else worked on the project, didn't think the server and shared projects would be needed so deleted them.

So now the project has got to the point where we need to do the database work. How do I add what the project had on creation (server and shared projects). I know I can right click solution and add Blazor server app, but is that the same thing? And then how to get the shared project back?


Solution

  • The easies solution is to

    • create a new Hosted solution in a different folder with exactly the same name
      so that the namespaces and default namespaces are correct.
    • copy the Shared and Server folders to your current Project
    • add both projects to your Solution (Add existing ...)
    • fix the dependencies:
      • Client and Server reference Shared
      • Server references the Client
    • make the Server Project the Startup

    Dependencies can be managed in the Solution Explorer with "Add Project reference".