Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Files generated before build (e.g. by NPM or Gulp) into the wwwroot folder might not be accessible

See original GitHub issue

I 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" />

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

rainersigwaldcommented, Apr 1, 2019

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 like

  <Target Name="NpmInstall" BeforeTargets="BeforeBuild">
    <Exec Command="npm install" />
    <Exec Command="gulp" />

      <None Include="path\to\generated\files\*.js" />

what is the best target to use here? Is BeforeBuild target the ideal one? I remember there is some complication here.

BeforeTargets="BeforeBuild" is a very good place for this. @livarcocc I think you’re thinking of AfterTargets="Build" which has some nasty edge cases.

@barthamark can you elaborate on

However, if the script finishes quickly (couple milliseconds) then it will be fine after the first build.

? That surprises me.

barthamarkcommented, Jun 28, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found