Skip to content
This repository was archived by the owner on Jan 15, 2023. It is now read-only.
This repository was archived by the owner on Jan 15, 2023. It is now read-only.

I solved all ChromelyBlazor.WebAssembly build problems #109

@Jinjinov

Description

@Jinjinov

Problem 1:

  • xcopy doesn't work on Linux

Problem 2:

  • ChromelyBlazor.WebAssembly shouldn't know anything about ChromelyBlazor.WebAssemblyApp because ChromelyBlazor.WebAssemblyApp is using ChromelyBlazor.WebAssembly

Solution 1:

  • Remove this from ChromelyBlazor.WebAssembly:
  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="xcopy &quot;$(ProjectDir)wwwroot&quot; &quot;$(SolutionDir)\ChromelyBlazor.WebAssemblyApp\bin\x64\Debug\net6.0\win-x64\app&quot;   /i /s /r /y /c&#xD;&#xA;xcopy &quot;$(TargetDir)wwwroot&quot; &quot;$(SolutionDir)\ChromelyBlazor.WebAssemblyApp\bin\x64\Debug\net6.0\win-x64\app&quot;   /i /s /r /y /c" />
  </Target>
  • Add this to ChromelyBlazor.WebAssemblyApp:
  <ItemGroup>
    <None Include="$(SolutionDir)ChromelyBlazor.WebAssembly\wwwroot\**" CopyToOutputDirectory="PreserveNewest" LinkBase="app\" />
  </ItemGroup>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <ItemGroup>
      <AfterBuildWwwRoot Include="$(SolutionDir)ChromelyBlazor.WebAssembly\bin\$(ConfigurationName)\$(TargetFramework)\wwwroot\**\*.*" />
    </ItemGroup>
    <Copy SourceFiles="@(AfterBuildWwwRoot)" DestinationFiles="@(AfterBuildWwwRoot->'$(TargetDir)\app\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
  </Target>

Problem 3:

  • If you add any NuGet that has its own wwwroot content to the ChromelyBlazor.WebAssembly and use it there like this:
    <link href="_content/Blazorise/blazorise.css" rel="stylesheet" />
    or like this:
    <script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
    then Solution 1 will not work, because _content directory will not be created in the app directory.

Solution 2:

  • you have to publish ChromelyBlazor.WebAssembly so that _content directory will be created (it is not created on build, only on publish)
  • create a folder publish profile named FolderProfile.pubxml in ChromelyBlazor.WebAssembly
  • Visual Studio will save it as ChromelyBlazor.WebAssembly\Properties\PublishProfiles\FolderProfile.pubxml
  • add this to ChromelyBlazor.WebAssemblyApp:
  <PropertyGroup>
    <PublishProfileDirectory>$(SolutionDir)ChromelyBlazor.WebAssembly\Properties\PublishProfiles</PublishProfileDirectory>
    <PublishProfileFileName>FolderProfile</PublishProfileFileName>
  </PropertyGroup>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">

    <MSBuild 
      Projects="$(SolutionDir)ChromelyBlazor.WebAssembly\ChromelyBlazor.WebAssembly.csproj" 
      Properties="DeployOnBuild=true;PublishProfile=$(PublishProfileFileName);PublishProfileRootFolder=$(PublishProfileDirectory);PublishUrl=$(TargetDir);PlatformTarget=AnyCPU" />

  </Target>
  • publish will automatically create a wwwroot folder inside ChromelyBlazor.WebAssemblyApp\bin\x64\Debug\net6.0\win-x64 so we have to rename app to wwwroot in our code
  • change config.StartUrl = "http://app/index.html"; to config.StartUrl = "http://wwwroot/index.html";
  • change
    new UrlScheme(DefaultSchemeName.LOCALREQUEST, "http", "app", string.Empty, UrlSchemeType.LocalResource, false)
    to
    new UrlScheme(DefaultSchemeName.LOCALREQUEST, "http", "wwwroot", string.Empty, UrlSchemeType.LocalResource, false)

You can see a working solution here: https://github.com/Jinjinov/Ididit/blob/main/Ididit.Wasm.Chromely/Ididit.Wasm.Chromely.csproj

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions