10
votes

i´m having problems with bower inside VS on an aspnet core 1.0 project. My bower.json is this

{
  "name": "asp.net",
  "private": true,
  "dependencies": {
    "bootstrap": "3.3.6",
    "jquery": "2.2.4",
    "jquery-validation": "1.14.0",
    "jquery-validation-unobtrusive": "3.2.6"
  }
}

But when I go to the libs that bower downloaded i find that jquery is v3.1.0

/*eslint-disable no-unused-vars*/
/*!
 * jQuery JavaScript Library v3.1.0
 * https://jquery.com/
 *
 * Includes Sizzle.js
 * https://sizzlejs.com/
 *
 * Copyright jQuery Foundation and other contributors
 * Released under the MIT license
 * https://jquery.org/license
 *
 * Date: 2016-07-07T21:44Z
 */

I thought it was my machine but it happened to me in three different machines. am i doing something wrong??

Edit: I tried with this:

{
  "name": "asp.net",
  "private": true,
  "dependencies": {
    "jquery": "~2.2.4"
  },
  "resolutions": {
    "jquery":  "<=2.2.4"
  }
}

The only package configured in bower.json is jquery and still installs jquery 3.0.1. Why is bower doing that? The Output window for npm/bower says:

PATH=.\node_modules.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\Bower.cmd" install --force-latest

bower jquery#~2.2.4 cached https://github.com/jquery/jquery-dist.git#2.2.4

bower jquery#~2.2.4 validate 2.2.4 against https://github.com/jquery/jquery-dist.git#~2.2.4

bower jquery extra-resolution Unnecessary resolution: jquery#<=2.2.4

bower jquery#~2.2.4 install jquery#2.2.4

jquery#2.2.4 wwwroot\bower\jquery

6
Are you looking in the correct folder? Bower might be installing to a different folder than you might think... - Heretic Monkey
Yes, i´m looking at the right folder. I've configured a different folder. I also tried with the default project and it has the same behaviour - snekkke
Oh, I just saw something... --force-latest is appended to your bower command, so, it's doing exactly that. There's probably a setting for that somewhere in visual studio. I don't have it in front of me, but I'd look for bower settings in Tools>Options... probably under Web, then something about packages. - Heretic Monkey
There are no settings for bower in VS. How could this be solved? - snekkke

6 Answers

6
votes

This is a known issue in the tooling repo:

https://github.com/aspnet/Tooling/issues/575

I simply switched to npm, which resolves the correct package version just fine.

6
votes

I was facing the same issue and have successfully resolved it. There is a problem with bower that was shipped with Visual Studio 2015, possibly introduced in one of the Visual Studio updates. What you can do:

  1. install Git (dependency)
  2. install nodejs
  3. install bower
  4. Configure Visual Studio options to use your installed version of nodejs
  5. Delete bower cache folder %USERPROFILE%\AppData\Local\bower

reference: http://josharepoint.com/2016/05/04/how-to-configure-visual-studio-2015-integration-with-latest-version-of-node-js-and-npm/

2
votes

Another temporal hack, until Microsoft fix the problem could be change contents of bower.cmd to remove the --force-latest string from parameters list.

The file bower.cmd on my Visual Studio 2015.3 installation is located on C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External.

You should replace:

@"%~dp0\node" "%~dp0\node_modules\bower\bin\bower" %*

With:

ECHO OFF
set params=%*
ECHO %params% | %WINDIR%\system32\FIND "--force-latest" >nul & 
IF ERRORLEVEL 0 (call set params=%%params:--force-latest=%%%)
@"%~dp0\node" "%~dp0\node_modules\bower\bin\bower" %params%

The above piece of code will check parameters and, if --force-latest exists, will be removed and then execute bower with clear parameters string.

0
votes

I had the same issue. Fixed it be removing jquery package, add then add it manually to bower.json with right version: "jquery": "2.2.4", Hope this will help someone.

0
votes

This is a GIT wrapper problem, this post was very helpful resolving this issue: Installed GIT for windows and changed Visual Studio External Web Tools (Tools->Options->Projects and Solutions->External Web Tools) from "$(VSINSTALLDIR)\Web\External\git" to "C:\program files\git\bin" cleared the temp files and restored bower.

Everything works fine now.

0
votes

My, somewhat hackish, solution was to remove the explicit version of jQuery from bower.json and have bootstrap itself resolve that dependency.

My bower.json looks like this:

{
  "name": "asp.net",
  "private": true,
  "dependencies": {
    "bootstrap": "~3.3.6",
    "font-awesome": "4.7.0"
  }
}