Files generated before build (e.g. by NPM or Gulp) into the wwwroot folder might not be accessible
See original GitHub issueI have a BeforeTargets=“BeforeBuild” script defined in my csproj file that executes a Gulp task which generates a bunch of js files taking more than 4 seconds to finish. These files are not accessible by the web application only after rebuilding the solution. However, if the script finishes quickly (couple milliseconds) then it will be fine after the first build.
<Target Name="NpmInstall" BeforeTargets="BeforeBuild">
<Exec Command="npm install" />
<Exec Command="gulp" />
</Target>
This might be a duplicate by one of the following issues, however, none of the workarounds fixed this scenario where the goal is to access these files locally on my development environment and not after publishing the website.
https://github.com/aspnet/websdk/issues/114 https://github.com/dotnet/sdk/issues/1044
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Is there a way to automatically copy files to wwwroot?
1 Answer 1 ... This answer recommends using GULP which seems dated now. You are not supposed to access node_modules files from front-end...
Read more >justeat/gulp-build-fozzie
The pathBuilder object is used inside of gulp-build-fozzie in order to build the paths used in the gulp tasks. See the Path Builder...
Read more >Gulp for WordPress: Initial Setup
This is the first part of a two-part series on creating a Gulp workflow for WordPress theme development. This first part covers a...
Read more >Deploy files to App Service - Azure
In a local terminal window, navigate to the root directory of your app project. ... run all the build tasks (for example, npm...
Read more >ASP.NET Core 2.0 and the End of Bower - Shawn Wildermuth
I download NPM from internet and cd into my project root folder, and use NPM command to install jquery and bootstrap and webpack,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is the problem that the
NpmInstall
generates javascript files that you expect to be picked up by the build and deployed with your application?I suspect that the problem is that you don’t add the files to the appropriate item after generating them in
NpmInstall
. The default glob (wildcard) includes apply only to files that exist on disk before the build starts. If files are created during the build, they will be discovered for the next build (so it’ll work on rebuild) but not the current build. The solution is to explicitly create the items after creating the files on disk, perhaps something likeBeforeTargets="BeforeBuild"
is a very good place for this. @livarcocc I think you’re thinking ofAfterTargets="Build"
which has some nasty edge cases.@barthamark can you elaborate on
? That surprises me.
In the meantime I found that this is caused by the modular framework I am using. It gathers all the resources found in the module’s wwwroot folder (which is a .NET Standard project) and registers them as static resources. I couldn’t reproduce it in a simple ASP.NET Core project. The BeforeBuild task will block the project build until the NPM task is not finished which is the expected way so all the resources are accessible after the build meaning it can’t be a .NET bug (or at least I can’t reproduce it for now). Thank you for your help. I’ll close this issue.