jsakamoto / BlazorWasmPreRendering.Build

When you publish your Blazor Wasm app, this package pre-renders and saves the app as static HTML files in your public folder.
https://jsakamoto.github.io/BlazorWasmPreRendering.Build/
Mozilla Public License 2.0
261 stars 15 forks source link

Publish failed with Visual Studio Publish #35

Closed fingers10 closed 1 year ago

fingers10 commented 1 year ago

Dear @jsakamoto ,

I tried to publish a blazor wasm app from Visual Studio Folder Publish Profile and the publish failed. However it works perfectly with command line publish dotnet publish.

Here are the necessary details:

  1. new dotnet 7.0.10 blazor wasm project.
  2. add <PackageReference Include="BlazorWasmPreRendering.Build" Version="3.0.0-preview.2" /> package.
  3. Program.cs:
    
    var builder = WebAssemblyHostBuilder.CreateDefault(args);

if (!builder.RootComponents.Any()) { builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); }

ConfigureServices(builder.Services, builder.HostEnvironment.BaseAddress);

await builder.Build().RunAsync();

static void ConfigureServices(IServiceCollection services, string baseAddress) { services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(baseAddress) }); }

4. `.csproj`:
```xml
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <LangVersion>latest</LangVersion>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <PublishTrimmed>true</PublishTrimmed>
    <BlazorEnableTimeZoneSupport>false</BlazorEnableTimeZoneSupport>
    <BlazorWebAssemblyLoadAllGlobalizationData>false</BlazorWebAssemblyLoadAllGlobalizationData>
    <BlazorWebAssemblyPreserveCollationData>false</BlazorWebAssemblyPreserveCollationData>
    <BlazorWasmPrerenderingDeleteLoadingContents>true</BlazorWasmPrerenderingDeleteLoadingContents>
    <!-- <BlazorWasmPrerenderingEnvironment>Production</BlazorWasmPrerenderingEnvironment> -->
    <BlazorWasmPrerenderingMode>WebAssemblyPrerendered</BlazorWasmPrerenderingMode>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BlazorWasmPreRendering.Build" Version="3.0.0-preview.2" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.10" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.10" PrivateAssets="all" />
  </ItemGroup>

</Project>
  1. FolderPublish.xml:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
  <PropertyGroup>
    <DeleteExistingFiles>true</DeleteExistingFiles>
    <ExcludeApp_Data>false</ExcludeApp_Data>
    <LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>bin\Release\net7.0\browser-wasm\publish\</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <_TargetId>Folder</_TargetId>
    <SiteUrlToLaunchAfterPublish />
    <TargetFramework>net7.0</TargetFramework>
    <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
    <ProjectGuid>385acf00-ae38-4e52-b370-b791fa4aacb2</ProjectGuid>
    <SelfContained>true</SelfContained>
  </PropertyGroup>
</Project>
  1. dotnet publish output
C:\Repos\Project\Web.Home>dotnet publish
MSBuild version 17.7.1+971bf70db for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  Web.Home -> C:\Repos\Project\Web.Home\bin\Debug\net7.0\Web.Home.dll
  Web.Home (Blazor output) -> C:\Repos\Project\Web.Home\bin\Debug\net7.0\wwwroot
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Compressing Blazor WebAssembly publish artifacts. This may take a while...
  Web.Home -> C:\Repos\Project\Web.Home\bin\Debug\net7.0\publish\
  Start fetching...[http://127.0.0.1:5050]
  Getting http://127.0.0.1:5050/...
  [INFORMATION] The requested URL (javascript: void(0)) was not navigatable.
  Fetching complete.
  1. Visual Studio Folder Publish

image

  1. Error log:
    
    Web.Home -> C:\Repos\Project\Web.Home\obj\Release\net7.0\browser-wasm\PubTmp\Out\
    "" "C:\Users\Abdul Rahman\.nuget\packages\blazorwasmprerendering.build\3.0.0-preview.2\build\../tools/net7.0/BlazorWasmPreRendering.Build.dll" --assemblyname "Web.Home" -t "Web.Home.App" --selectorofrootcomponent "#app,app" --selectorofheadoutletcomponent "head::after" -p "C:\Repos\Project\Web.Home\obj\Release\net7.0\browser-wasm\PubTmp\Out" -i "C:\Repos\Project\Web.Home\obj\Release\net7.0\." --assemblydir "C:\Repos\Project\Web.Home\bin\Release\net7.0" -m "" -f "net7.0" --serviceworkerassetsmanifest "" --environment "Prerendering" --emulateauthme "true" --locale "en" -o "IndexHtmlInSubFolders"  -d -u "" -r "WebAssemblyPrerendered" --serverport "5050-5999" --bwapoptionsdllext "bin"
    '""' is not recognized as an internal or external command,
    operable program or batch file.
    C:\Users\Abdul Rahman\.nuget\packages\blazorwasmprerendering.build\3.0.0-preview.2\build\BlazorWasmPreRendering.Build.targets(63,5): Error MSB3073: The command """ "C:\Users\Abdul Rahman\.nuget\packages\blazorwasmprerendering.build\3.0.0-preview.2\build\../tools/net7.0/BlazorWasmPreRendering.Build.dll" --assemblyname "Web.Home" -t "Web.Home.App" --selectorofrootcomponent "#app,app" --selectorofheadoutletcomponent "head::after" -p "C:\Repos\Project\Web.Home\obj\Release\net7.0\browser-wasm\PubTmp\Out" -i "C:\Repos\Project\Web.Home\obj\Release\net7.0\." --assemblydir "C:\Repos\Project\Web.Home\bin\Release\net7.0" -m "" -f "net7.0" --serviceworkerassetsmanifest "" --environment "Prerendering" --emulateauthme "true" --locale "en" -o "IndexHtmlInSubFolders"  -d -u "" -r "WebAssemblyPrerendered" --serverport "5050-5999" --bwapoptionsdllext "bin"" exited with code 9009.

2>Build failed. Check the Output window for more details.



Please let me know if any other details are required.
jsakamoto commented 1 year ago

@fingers10 Thank you for your reporting! I want to investigate this problem, but I don't have enough time right now. Please wait for a few days. Thanks!

jsakamoto commented 1 year ago

@fingers10

I published the fixed new version of the "BlazorWasmPreRendering.Build".

Could you try it out?

Thank you for your contributions!

fingers10 commented 1 year ago

@jsakamoto Thank you for your support. I checked and it works fine.

fingers10 commented 1 year ago

@jsakamoto I was deploying the published version and got the below runtime error. This error doesn't appear when I published the same blazor wasm project without this package.

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Cannot read properties of null (reading 'insertBefore')
      TypeError: Cannot read properties of null (reading 'insertBefore')
          at x (https://localhost:44354/_framework/blazor.webassembly.js:1:17125)
          at M (https://localhost:44354/_framework/blazor.webassembly.js:1:16836)
          at se.insertComponent (https://localhost:44354/_framework/blazor.webassembly.js:1:24352)
          at se.insertFrame (https://localhost:44354/_framework/blazor.webassembly.js:1:23075)
          at se.applyEdits (https://localhost:44354/_framework/blazor.webassembly.js:1:21490)
          at se.updateComponent (https://localhost:44354/_framework/blazor.webassembly.js:1:20774)
          at https://localhost:44354/_framework/blazor.webassembly.js:1:59545
          at Vt.Ke._internal.renderBatch (https://localhost:44354/_framework/blazor.webassembly.js:1:59917)
          at Object.Gt [as invokeJSFromDotNet] (https://localhost:44354/_framework/blazor.webassembly.js:1:62760)
          at Object.Ii (https://localhost:44354/_framework/dotnet.7.0.10.hufr6ztx9h.js:5:71974)
Microsoft.JSInterop.JSException: Cannot read properties of null (reading 'insertBefore')
TypeError: Cannot read properties of null (reading 'insertBefore')
    at x (https://localhost:44354/_framework/blazor.webassembly.js:1:17125)
    at M (https://localhost:44354/_framework/blazor.webassembly.js:1:16836)
    at se.insertComponent (https://localhost:44354/_framework/blazor.webassembly.js:1:24352)
    at se.insertFrame (https://localhost:44354/_framework/blazor.webassembly.js:1:23075)
    at se.applyEdits (https://localhost:44354/_framework/blazor.webassembly.js:1:21490)
    at se.updateComponent (https://localhost:44354/_framework/blazor.webassembly.js:1:20774)
    at https://localhost:44354/_framework/blazor.webassembly.js:1:59545
    at Vt.Ke._internal.renderBatch (https://localhost:44354/_framework/blazor.webassembly.js:1:59917)
    at Object.Gt [as invokeJSFromDotNet] (https://localhost:44354/_framework/blazor.webassembly.js:1:62760)
    at Object.Ii (https://localhost:44354/_framework/dotnet.7.0.10.hufr6ztx9h.js:5:71974)
   at Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.InvokeUnmarshalled[Int32,RenderBatch,Object,Object](String , Int32 , RenderBatch , Object , Int64 )
   at Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.InvokeUnmarshalled[Int32,RenderBatch,Object](String , Int32 , RenderBatch )
   at Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer.UpdateDisplayAsync(RenderBatch& )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
u @ blazor.webassembly.js:1
jsakamoto commented 1 year ago

@fingers10 Thank you for reporting! But please isolate issues for each problem. (So please create a new issue for this problem.)

And, unfortunately, I could not figure out the reason for this error from the log you provided. So, could you provide me the project file that caused this error? Thank you for being so understanding. 😊