Reputation: 2245
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
Upvotes: 7
Views: 14169
Reputation: 2139
You can also use .bat
file and run it in Debug mode
open build events and add this to pre-build events
if $(ConfigurationName) == Debug (
call "$(ProjectDir)prebuild.bat"
)
then open up prebuild.bat file and add yarn or npm command like this
cd ..
call yarn install
cd project1
call yarn install
call yarn build
cd ..
cd project2
call yarn install
call yarn build
cd ..
cd project3
call yarn install
call yarn build
cd ..
cd project4
call yarn install
call yarn build
cd ..
And for sure you can replace calling the .bat
file with its content
Upvotes: 0
Reputation: 89
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 ?
Upvotes: 3
Reputation: 131
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.
Upvotes: 8