Blazor Server with NetPack
xavierpena opened this issue · 4 comments
I have followed your Blazor sample to try to configure the "hot reloading" in my Blazor Server project. Your project was 17 months old, so some issues were to be expected.
To this day, The Blazor template proposed by Microsoft (using dotnet new blazorserver -o BlazorApp
) does not have "hot reloading". This is why I was very excited when I ran into your project. Because of that and because as a dotnet developer, I really want to avoid using WebPack if possible.
I've tried to dig into your source code to try to solve the issues that I've found, but I've hit into several walls that I will try to enumerate here:
-
The file "(assembly).blazor.config" does not exist anymore. See this code line.
-
On
app.UseBrowserReload();
it throws the following runtime exception:Could not load type 'Microsoft.AspNetCore.SignalR.HubRouteBuilder' from assembly 'Microsoft.AspNetCore.SignalR, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Source=NetPack.BrowserReload
-
The aforementioned error could be related to this breaking change.
My efforts trying to at least find a workaround were unsuccessful.
@xavierpena I agree with your motives. Sorry I haven't gotten around to upgrading this project yet, thanks for looking into this, I hope the following may help.
The file "(assembly).blazor.config" does not exist anymore. See this code line.
So basically, it was looking for this file because it was using it to work out where the referenced blazor projects folders were on disk.
I believe this needs to be changed to look for a file now named: "(assembly).StaticWebAssets.xml"
- if you build your blazor project (the host project) and look in the build output folder you should see this file.
It's an xml file and it has multiple entries / nodes, if you open it up you'll see a node with a "base path" that matches the base path from your blazor projects csproj file - thats the node we need:
<ContentRoot BasePath="your/basepath" Path="C:\Users\YourUser\source\repos\YourRepo\src\YourProj\bin\Debug\net5.0\wwwroot\" />
That path is the one we want - and needs to be passed to create the file provider here:
When running / debugging locally on a development environment, the "(assembly).StaticWebAssets.xml" file should always be present and it basically maps a "BasePath="your/basepath" to its source location at development time. However when you dotnet publish
the application, the static content is physically copied to live directly under the servers wwwroot directory at a path like this:
"/wwwroot/[base-path/"
.. and there is no "(assembly).StaticWebAssets.xml" used for a published application not running on a development environment.
So basically the base path from the .csproj
file is staying constant and is the "Key" used to locate the blazor projects static content. That location is either mapped to an alternate location via the presence of that "(assembly).StaticWebAssets.xml" file, or they are expected to be under the hosts webroot directory i.e at "/wwwroot/[base-path]"
I am not 100% sure whether "dist" is still relevent so you might just be able to remove that code:
On app.UseBrowserReload(); it throws the following runtime exception: Could not load type
Note sure. Perhaps we just need to upgrade signal r nuget packages - did you try that?
@dazinator Thank you very much for the very detailed answer.
With the details you gave me, I would probably be able to repair the new Blazor way to store the ConfigFilePath and such. Although:
On app.UseBrowserReload(); it throws the following runtime exception: Could not load type
Note sure. Perhaps we just need to upgrade signal r nuget packages - did you try that?
I did try it: I updated all "signal r" nuget packages, but I wasn't able to make it work. Probably because I was a bit lost trying to manage the multiple NetPack
dependencies.
It's a very advanced project and I felt a bit intimidated trying to modify it. After a few hours I had to stop because I ran out of ideas.
Ok no probs, thanks for looking into it. I will try to take a look at this in the future, can't say precisely when right now - but will comment back here once I make any progress!
Just an update to say, progress on this issue could resume. I have made a file provider over here https://github.com/dazinator/Dazinator.Extensions.FileProviders/blob/develop/src/Dazinator.Extensions.FileProviders.Tests/MappingFileProviderTests.cs#L32 that can basically be configured from the new staticassets
xml file mentioned above. This would make it very easy to include the correct blazor project outputs into netpack.