dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.

Home Page:https://asp.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Building assets using MSBuild & NPM needs further clarification

MarkStega opened this issue · comments

Last year @javiercn helped with a resource bundling issue (#35274). Unfortunately, there is an undesirable side-effect of the method (see the end of #42374 for a demonstration of the problem). I went back to the blog post https://devblogs.microsoft.com/dotnet/build-client-web-assets-for-your-razor-class-library/ and it appears that the reference library never made it out of the alpha stage of development. The sample app doesn't help as it is based upon the same alpha build.

My referenced csproj material.blazor.csproj does the build of js & css assets properly (and builds them only if the outputs are missing or out of date) but is apparently running the npm commands too late to have the generated assets in wwwroot recognized as static web assets.

So three questions/comments:

  1. A working demo of using npm to build static assets without the alpha library would be useful
  2. A new blog post addressing the issues revolving building static web assets would be useful
  3. Instead of content remove/include pairs in the csproj, can I just change the
BeforeTargets="PreBuildEvent"

to an earlier build step. If so, what step would be appropriate. (and are the build steps documented)?

Hey @MarkStega, thanks for reaching out. I believe #38445 may achieve what you're looking for here.

@MarkStega the package in the blog post should be completely usable (it's a bunch of MSBuild) and as @TanayParikh mentions, we are productionizing a "more complete" version of the package as part of #38445 built in directly into the SDK.

For an immediate solution, I would switch to the provided package. That should do all the invocations at the right time and handle all the incrementalism.

@TanayParikh Thanks, I believe I could make that work as long as I have the ability to have multiple 'generate' entries. I put in a longer comment in #38445 as to why I think that is desirable.

@javiercn I'll look at the package again but I couldn't figure out how to separate js & css builds.

@MarkStega the package is setup to build all the assets as a single step.

If you want to have separate sets of things to build, you can replicate what is done in the blog post to add a separate target for CSS.

The support we plan to build in the SDK will allow you to have multiple tools and commands out of the box.

@MarkStega we will be using #38445 to track this issue.