Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor Wasm] Razor Class libraries static assets are not published in the dist folder #13103

Open
ghidello opened this issue Aug 13, 2019 · 5 comments

Comments

@ghidello
Copy link
Contributor

commented Aug 13, 2019

When publishing a Blazor Webassembly App referencing a razor class library the _content folder for the class library is created in the publish/wwwroot/ path instead of publish/ProjectName/dist/ along with all the other app files.

To Reproduce

  1. Create a default Blazor Webassembly App named TestBlazorApp
  2. Create a default Razor Class Library
  3. In the Blazor app add a reference to the class library, a reference to the component in the index.cshtml file and a reference to the css in the index.html file
  4. The component should render correctly with the development server
  5. Perform a dotnet publish and inspect the bin\Debug\netstandard2.0\publish\TestBlazorApp\dist: the _content folder is missing but is present at bin\Debug\netstandard2.0\publish\wwwroot\_content

Expected behavior

The static assets for a Razor class library should be published in the same folder of the the other assets of a referencng Blazor Webassembly app.

Additional context

The static assets are published correctly for a Blazor Server app.

dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview8-013656
 Commit:    8bf06ffc8d

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\

Host (useful for support):
  Version: 3.0.0-preview8-28405-07
  Commit:  d01b2fb7bc
@pranavkm

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

/cc @javiercn

@javiercn

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

We might need to do some tweaks here. We can talk about when to get the changes in.

@arivoir

This comment has been minimized.

Copy link

commented Aug 20, 2019

Is there any workaround?

In server-side Blazor copying the files manually is working, but in client-side Blazor, not. In my project a necessary JavaScript file is not copied and the app is crashing.

@ghidello

This comment has been minimized.

Copy link
Contributor Author

commented Aug 20, 2019

@arivoir from my tests publishing a server-side project was working correctly but maybe I didn't check well enough. On client-side my temporary workaround is to copy the content of the publish/wwwroot/ into the publish/ProjectName/dist/ folder.

@michaeldaw

This comment has been minimized.

Copy link

commented Oct 3, 2019

From what I can tell, if a referenced Razor Class Library contains the "EmbeddedResource" elements that were present in early versions of the framework, the static assets of these projects will show up in the dist/_content folder. If the project does not contain the EmbeddedResource elements, it will show up in the wwwroot folder, as described by @ghidello.

To work around this, you can make sure the static content is in a folder called content in the referenced library (not wwwroot), and the following is in the csproj file:

  <ItemGroup>
    <!-- .js/.css files will be referenced via <script>/<link> tags; other content files will just be included in the app's 'dist' directory without any tags referencing them -->
    <EmbeddedResource Include="content\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
    <EmbeddedResource Include="content\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
    <EmbeddedResource Include="content\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
  </ItemGroup>

I personally don't know much about how the EmbeddedResource feature works, but it seems the folder name content is significant. It doesn't work if the folder is called wwwroot.

Seems to be related to removing the feature by which static files are automatically added to the deployed project (#13279). According to what was discussed in that issue, this "workaround" may not continue to work in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.