10

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

snekkke
  • 441
  • 1
  • 5
  • 15
  • Are you looking in the correct folder? Bower might be installing to a different folder than you might think... – Heretic Monkey Jul 08 '16 at 19:20
  • 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 Jul 08 '16 at 23:38
  • 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 Jul 08 '16 at 23:47
  • 1
    There are no settings for bower in VS. How could this be solved? – snekkke Jul 09 '16 at 03:13

6 Answers6

6

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.

bglee
  • 146
  • 5
6

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/

cronixis
  • 368
  • 5
  • 9
2

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.

Sebastián Guerrero
  • 1,055
  • 1
  • 19
  • 26
  • This doesn't seem to work for me. The script removes the --force-latest parameter perfectly, but Bower still just gets jQuery 3.1.1 (even though it thinks it downloaded 2.2.3) – Jobbo Oct 21 '16 at 13:36
  • @Jobbo check the into the hidden file "bower.json" (in your project root) the "resolutions" section, probably is referencing jQuery 3.1.1 as version to solve conflicts... ( by old wrong parameter ) – Sebastián Guerrero Oct 21 '16 at 23:04
  • After applying the fix to the .cmd file I also tried editing bower.json manually. I completely removed the 'resolutions' section and set the only 'dependency' as "jquery":"2.2.3", but Bower still gets 3.1.1. The description of --force-latest is 'Force latest version on conflict' so I'm not convinced removing it makes a difference in this case – Jobbo Oct 22 '16 at 12:28
  • @Jobbo, exactly, --force-latest is "Force latest version on conflic", I was getting 3.1.1 by a conflict with Bootstrap... After patch it worked by me, check: https://postimg.org/image/h4urheaed/ – Sebastián Guerrero Oct 23 '16 at 02:52
  • My bower.cmd is exactly as you've posted. I opened a new solution and uninstalled all existing packages, then added Bootstrap 3.3.6 and jQuery 2.2.4. Bower then downloaded Bootstrap 4 alpha, and jQuery 3.1.1. What could I be doing wrong?: https://postimg.org/image/5q4hgggsd/ – Jobbo Oct 23 '16 at 17:32
  • 1
    This fixed the issue (with the default bower.cmd from VS): http://stackoverflow.com/questions/37584520/bootstrap-3-3-6-jquery-2-2-4-version-exception/38460014#38460014 – Jobbo Oct 24 '16 at 15:34
  • 1
    This plus clearing bower cache as suggested by @cronixis solved it for me with VS2015 Update 3 and the preview 2 of the ASP.NET Core MVC Tooling for VS2015. I think there is chance that different combinations of versions may require a different fix. – Manfred Jan 19 '17 at 04:53
0

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.

drakkar
  • 403
  • 7
  • 10
  • 1
    It did not work for me. I've tried it manually, with the ui, but bower always installs the latest version. Also it happens for all the packages. Although i specify the version on any package, bower installs the latest. – snekkke Jul 08 '16 at 14:24
0

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.

Community
  • 1
  • 1
Nemesis
  • 434
  • 4
  • 9
0

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"
  }
}