How can I disable NPM package restore in Visual Studio 2015? - node.js

When I open a project with a package.json in Visual Studio 2015, an npm install is automatically started, and VS is unresponsive until the install is completed.
I would much rather prefer running npm install myself from the command line; how can I stop Visual Studio from doing it?

Try this:
Open Tools -> Options
Select Projects and Solutions / External Web Tools
Uncheck all four paths
Click OK
It doesn't seem that closing the solution, etc., is necessary. NPM and Bower functionality are now disabled in VS but will work fine on the command line (assuming you've globally installed npm, bower, etc.) You may get some error messages in the Output window, but no build errors or warnings.
To restore normal operation, go back to External Web Tools and click "Reset to Defaults" in the lower right.
I haven't tried this with Publish -- you might have to restore defaults to successfully publish, try it if you encounter errors at that point.

If you upgrade to Visual Studio 2017 (the free 'Community Edition' is fine) then the VS team have added an option to stop npm running when a project is opened. It's under Tools/Options/Projects and Solutions/Web Package Management/Package Restore. You can disable NPM (and Bower) restores on Project Open and on package.json Save separately.
Note also that for the node.js project types (NTVS) only the automatic package restore behavior is disabled completely in VS2017 at present.
Edit: the above answer also applies to Visual Studio 2019. The menu options are in the same place, although Bower support has been deprecated.

Visual Studio 2015 Update 2 fixed this issue! Install Update 2 and you should be good to go.
Direct download: http://go.microsoft.com/fwlink/?LinkId=691129
Update 2 Release Notes: https://www.visualstudio.com/news/releasenotes/vs2015-update2-vs
Edit: "fixed" may not be entirely accurate, and it may not be entirely fixed for all users. Maybe we can pin down what everybody's experiencing. To clarify, my experience has been as follows:
Prior to Update 2, VS would run 'npm install' every time I opened
the .sln, which was very hard to cope with.
After Update 2, VS runs 'npm install' in certain scenarios, which is tolerable (in my experience.)
In my experience, post-patch VS will, upon opening the .sln, run 'npm install' if any of the dependencies in package.json are missing from the node_modules folder (or if the folder itself is missing.)
You can't disable the 'npm install', so 'fixed' may not quite be correct - however, it doesn't do it on every launch as before, so I consider it a win. Can folks confirm this is the behavior, or are we experiencing different behaviors?

Related

Visual Studio Installer is not installing node.js

In Visual Studio Installer, I selected the Node.js development option. It runs successfully. But, if I try to run cmd node -v. It tells me node does not exist.
I tried a few other things including uninstalling and reinstalling the Node.js development option in VS Installer. Plus installing the latest version of node from the website.
However, when I try to run the pre-packed Angular solution that comes with VS 2017 I have issues. The solution will not even start.
The best I have been able to do is install Node 6.10.3. Once I do that, the web site comes up. But, I get a JavaScript error in the vendor.js file. I am able to continue but I get this error when I try navigate to another menu item. Plus the Hot Module Replacement does not seem to be working. (It does not automatically recompile my TypeScript file if I made a change).
I think the key is getting the Node.js development option installed correctly since I am able to run the pre-packed Angular solution on another PC and the Hot Module Replacement works fine.
Please let me know if anyone has any ideas on how to resolve.
I had a similar, if not the same, issue. Check the Visual Studio installation directory (2017 Professional in this case) for Node:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\NodeJs
If the executable is there, add the directory to your PATH.

How can I set up gulp to run identically in Visual Studio 2017 and msbuild without having to change my build scripts?

I'm struggling to get set up with gulp in Visual Studio 2017. I'm not sure where I'm going wrong but there are a few things I'm confused about and I can't really find any online resources that are of any use.
The build system I'm using is CruiseControl.NET and I would like gulp to work with it.
This is what I've done so far:
Installed Visual Studio 2017 with .NET Core cross-platform development and Node.js development selected (amongst other options).
Created a new project
Added a gulpfile.js file to the project
Right-click on the file and choose Task Runner Explorer
In the Task Runner Explorer I get the error Failed to load. See output window (Ctl+Alt+O) for more information..
Then if I do the following:
Open the Node.js Interactive Window
Run the command .npm install --global gulp-cli
Close Visual Studio and open it back up again
In the Task Runner Explorer, I then get the message (No tasks found).
First off, is this the correct way to set up Gulp in Visual Studio 2017?
The reason I'm asking this is because I'm not sure why I need to prefix commands with a period character (ie .npm as opposed to npm).
I'm also not sure where gulp was installed because I can't find it in the path C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\node_modules.
Because of this I can't really set up CruiseControl.NET.
The way I'm handling this is to first use the Web Essentials 2017 extension. This installs the Bundler & Minifier tool, which then adds a bundleconfig.json file to your project. Right-click on this file, go to the Bundler & Minifier menu item and you will see an option in there to Convert To Gulp.
Selecting convert to gulp will create the necessary gulpfile.js and also install the npm packages required for using Gulp. Wait for all of the npm packages to install and you can then right click on gulpfile.js, select Task Runner Explorer and you should be ready to set up Gulp-based tasks. If you see gulpfile.js failed to load message, npm packages may still be installing (check the progress bar on the VS 2017 status bar). Hit the Refresh icon in Task Runner Explorer when all packages are installed and the error should vanish.
There's probably a more manual way to add Gulp support but I find this more automated method ensures all the tooling is wired up to work properly and I don't miss anything.
I gleaned all this information from the awesome Microsoft Docs site, specifically this page on Bundling & Minification. There's also a Using Gulp section in there that may provide additional details for your situation.
https://learn.microsoft.com/en-us/aspnet/core/client-side/bundling-and-minification
Microsoft have now added documentation on how to get gulp running:
https://learn.microsoft.com/en-us/aspnet/core/client-side/using-gulp
Make sure you update Visual Studio 2017 to the latest version as it now comes shipped with Node.js, NPM and Gulp (you don't need to pick "Node.js support" when installing Visual Studio for this to work).
Create an npm Configuration File (package.json) in your project folder and edit it to reference gulp:
{
"version": "1.0.0",
"name": "example",
"private": true,
"devDependencies": {
"gulp": "3.9.1"
},
"scripts": {
"gulp": "gulp"
}
}
In the project folder, create a Gulp Configuration File (gulpfile.js) to define the automated process.
Add the following to the post-build event command line for each project requiring gulp support:
cd $(ProjectDir)
call dotnet restore
npm run gulp
To run the tasks in Visual Studio 2017, open the Task Runner Explorer (View > Other Windows > Task Runner Explorer).
Then on the build server just install Node.js and ensure the path to node is added to the environmental path variable then when the build server builds the project gulp will run too!
I found the solution here. More information on that part of VS from Mads himself.
You have to force Visual Studio run with your Node.js version:
Go to Tools > Options in Visual Studio 2017
Go to Projects and Solutions > External Web Tools
Add the following path: C:\Program Files\nodejs

Installing nvm for windows : Visual Studio npm debug fails because of illegal characters in path

the newest node.js 0.12.0 doesnt work together with the sqlite3 package. i found nvm for windows: nvm for windows https://github.com/coreybutler/nvm-windows/releases . i thought nice to use the old and new node.js versions on 1 computer.
after installing nvm for windows in c:\nvm , i get in visual studio 2013 in debug that there is a fault in npm : illigal characters in path resulting in exit debug program . Outside Visual Studio it works fine.
As I mentioned in my comment, I had a very similar problem. After installing node.js for purpose of using gulp I could not do a successful build. I would get the following error:
C:\Visual Studio
Projects\MyProject\packages\RazorGenerator.MsBuild.2.2.6\build\RazorGenerator.Ms‌​Build.targets(21,9):
error : Illegal characters in path.
After searching around I guessed that the problem had to do with the node.js utilizing "illegally" long path names. For some background go here: https://github.com/joyent/node/issues/6960
My solution was to install the Flatten Packages tool: https://visualstudiogallery.msdn.microsoft.com/cd0b1938-4513-4e57-b9b7-c674b4a20e79?SRC=VSIDE
I ran flatten packages on the "node_modules" folder, tried to build (failed but with a different error), restarted Visual Studio, and everything now seems to build ok. Hope this helps.
UPDATE
One thing to keep in mind is that, by design, Flatten Packages will move files up in the directory structure. As a consequence, however, Visual Studio will still look for some of the folder/files in the OLD location; VS will shows the [!] symbol to show that the file was there but no longer is. These old file references can gum up the build, so you need to simply delete these old file references/directories.
Since this post still is on top when searching for this topic..
I also had this problem with "Illegal characters in path" and found that the best solution for me and my team was to make Visual Studio use the latest npm version (>= 3.0) since the node_modules folder depth doesnt get as deep as with npm2 (used by Visual Studio).
This solution will work for you in the background, not needing to run extra commands and tools for flattening the folder.
See my post here for a complete how to: http://newsweb.se/how-to-use-visual-studio-2015-with-latest-nodejs-npm/

Do Not See when right Clicking "Manage npm modules"

I am following along with Shawn Wildermuth's Node.js for .NET Developers. I have already install NodeJS Tools for Visual Studio from nodejstools.codeplex.com.
Everything appears to have installed properly, I have just created a "NodeJS Blank Website".
However, when Shaun says to right click the NPM node in the solution and choose "Manage NPM Modules", I do not have it.
I circumvented the problem by doing an install from NodeJS command prompt directly but I sure would like to know why Visual Studio is ever changing and never consistent. I need a new & better IDE.
Help anyone?
I had same problem, and according to the Error message window, PATH in Environment Variable was not set to the location to nodejs folder. After I changed nodejs folder location to C:/Program Files/nodejs, right click and "Install new npm packages..." worked well to install Express. Hoping this would help for you too.

NuGet; unable to get package as wrong version reported in Visual Studio 2012

I'm trying to build a solution but I get this error,
he 'Microsoft.Bcl.Build 1.0.14' package requires NuGet client version '2.8.1' or above, but the current NuGet version is '2.6.40619.9041'.
I've just upgraded NuGet package manager in Tools/"Extensions and Updates" which reports the version as 2.8.50313.31.
I've restarted VS2012, restarted the computer, cleaned the project and rebuilt, but I still can't get Visual Studio to recognise the new version and hence can't compile.
Thanks
Run Console (cmd) as Administrator
Locate your .nuget folder that contains the NuGet.exe file (you may check error message to locate the path)
execute this command NuGet.exe update -self
Took me all day to find that NuGet was bound to the individual project.
I had to use the package manager console and run
Install-Package Microsoft.Bcl.Build -Version 1.0.14
to get it to work manually.
Edit (5/11/2014). The problem is actually that Nuget gets bundled with the solution and it is this that needs upgrading. I did this by finding the directory in the project with the nuget.exe file in it (.nuget for me, YMMV) going to that directory and running nuget update -self. If you go with the original solution, you have to do this manually for each package. HTH.
This worked for me in VS 2017 Enterprise-
Right click your solution and go to "Manage NuGet Packages for Solution..."
In the window that opens up, click the gear icon at the top right corner.
Select "General" and click the "Clear Clear All NuGet Cache(s)" button. This will run for a few seconds depending on the size of your
cache.
Clean and rebuild your solution.

Resources