I am using Visual Studio 2019 to create a new Core RazorPage application. I need to run the following commands inside my WWWRoot folder
npm install
npm run build
I tried to add the following commands inside my pre-build script
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="npm i $(ProjectDir)wwwroot" />
</Target>
but nothing happen and i am getting the folowing warning
npm WARN saveError ENOENT: no such file or directory, open 'E:\Dev\package.json'
it seems that it completely ignores the wwwroot in the path
VS19 doesn't like not having the package.json at the root of the project. I was able to add a package.json at the root of the project, and add the script:
"scripts": {
"build": "cd wwwroot && npm i && npm run build"
},
the node_modules
folder was then created in the wwwroot
folder and the npm run build
command was run inside the child folder. I would also recommend the Extension "NpmTaskRunner" (https://github.com/madskristensen/NpmTaskRunner). You can then bind the root build script to the VS Build event.
After moving an ASP.NET Web Application to ASP.NET Core Application I had, almost, the same problem with npm. If I created the package.json file inside a Project I end up with:
After struggling for a while I followed a different approach, and it is working up to now:
There is a detailed description of this approach (compared to the usual) at the link below:
A better way to use Visual Studio with npm (and Gulp)
Please let me now if this works for your problem ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With