I would suggest an alternate way. There are other drawbacks to referring to WASM project from a server project, but personally I think it is an architecturally inelegant solution.
There are some critical areas where Blazor Server and WASM differ :
- Authentication: Blazor server allows you to customize access to specific areas at runtime. In WASM, the authorization happens in one go and the app code is sent in its entirety.
- Database is access : Blazor server allows direct access to EF core entities (since the code executes only on the server). In blazor, it is realistically not possible to access any database directly. It is also highly discouraged because you would be sending connection strings to the client. Hence you need to write a separate web API for data access.
3.Settings files : you can have as many settings files in server-side blazor. Client side blazor loads only appsettings.json by default. A special mechanism is required to include multiple .json files.
Therefore, for most applications (and definitely the ones that require database access) you will not be able to share 100% codebase between WASM and Server-side.
Here is what you should do instead:
For the points mentioned above, (auth, but mostly db access), create a data access service dependency (say IDataAccessLayer).
One implementation will access the database directly (to be used in server side)
The other implementation will access the database through an HttpClient (to be used in blazor WASM).
Now, put your entire app in an RCL. Call it "BlazorAppRCL". This RCL obviously does not have Startup.cs and Program.cs
Create a project for server and client specific db access implementation
Now, you have the following set of projects:
For Server Side:
BlazorServer (has only settings + Program.cs + Startup.cs). It refers to the RCL + Server specific implementation of IDataAccessLayer
For hosted WASM:
BlazorWebAPI : For database access, it has API to access database
BlazorClientDAL : WASM specific implementation of IDataAccessLayer
BlazorWASM : Blazor WASM project
All three refer to your BlazorAppRCL.
The crux is to use DI/ inversion of control pattern to address the divergence between WASM and Server.
This way, you can have a both instances WASM and Server instances with minimal code divergence. Note that the WASM WebAPI can simply use the server side blazor's implementation od IDataAccessLayer as it is. So beyond API related overhead, additional coding is not necessary.