VS 2015 + Bower: Does not work behind firewall

前端 未结 12 2163
一向
一向 2020-11-29 01:40

Problem

In Visual Studio 2015, using bower, my package restores fail when behind a firewall with an error similar to:

ECMDERR Failed to exec

相关标签:
12条回答
  • 2020-11-29 02:20

    If you want a global solution.

    WARNING: it can impact several proxy settings through different application but it certainly what you want :)

    NOTE If you have special characters in your username:password in your proxy settings, you need to URLENCODED them. Example: http://DOMAIN%5Cuser+name%3AP%40%24%24w0rd@proxy.server.com:8080

    You must add 2 environment variable.

    • HTTP_PROXY: http://proxyuser:proxypwd@proxy.server.com:8080
    • HTTPS_PROXY: http://proxyuser:proxypwd@proxy.server.com:8080

    To do that on windows 10:

    1. START
    2. Search "Edit the system environment variables"
    3. (in the adanced tab of system properties) click on "Environment Variables...)
    4. (in System variable) click "New..."
    5. Create Variable (Variable name: HTTP_PROXY, Variable value: http://proxyuser:proxypwd@proxy.server.com:8080)
    6. Create Variable (Variable name: HTTPS_PROXY, Variable value: http://proxyuser:proxypwd@proxy.server.com:8080)
    7. Restart Windows
    0 讨论(0)
  • 2020-11-29 02:21

    I had the same problem. Apparently the Git.exe that VS2015 CTP ships with does not use .gitconfig. But you can fix it (manually), if you have the git command line tools installed elsewhere.

    In C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External you will need to edit the file bower.cmd.

    Comment out lines 4 and 5:

    rem -- set GIT_PATH=%~dp0\git
    rem -- set PATH=%GIT_PATH%;%PATH%`
    

    This will trigger the command to use the Git you have already installed, which will pick up the local .gitconfig.

    Make sure you have set the appropriate git setting:

    git config --global url."http://".insteadOf git://
    
    0 讨论(0)
  • 2020-11-29 02:21

    It was so painfull to set properly proxy settings. I share my solution.

    I work On Windows 10 with Visual Studio 2015. I must set proxy settings when I am at work and remove them at home.

    To achieve this, you have 2 solutions.

    1. Configure Visual Studio external tools to use appropriate settings
    2. Install tools (node, npm, bower) on your machine and use them (you can set Visual Studio options to use them)

    Solution 1 (Configure VS external tools)

    1. Configure Npm. Execute following cmd in Admin prompt.

      > cd "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External"
      > npm.cmd config set --global http_proxy http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
      > npm.cmd config set --global http_proxy http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
      
    2. Configure Git. Add a .gitconfig file located at C:\Windows\Users\%USERNAME%. Then add followings key/value.

      [http]
          proxy = http://proxyuser:proxypwd@proxy.server.com:8080
      [https]
          proxy = http://proxyuser:proxypwd@proxy.server.com:8080
      
    3. Configure Bower. Add a .bowerrc file located at C:\Windows\Users\%USERNAME%. Then add followings key/value.

      {
        "proxy": "http://proxyuser:proxypwd@proxy.server.com:8080",
        "https-proxy": "http://proxyuser:proxypwd@proxy.server.com:8080"
      }
      

    WARNING: If you have specials characters in your proxy password, you must encode the proxy url. Example:

    • username: DOMAIN\user name
    • password: P@$$w0rd
    • proxy server: 10.80.0.0
    • proxy port: 8080
    • PROXY URL with authentification: http://DOMAIN%5Cuser+name%3AP%40%24%24w0rd@10.80.0.0:8080

    Et Voilà :)

    Solution 2 (Install tools on your machine)

    I have installed node.js, npm, git and bower globally on my machine (because I need to have more control than just external/tools available in VS).

    1. Install Node.js : NodeJS Website
    2. Install Npm NOTE: Npm is installed automatically by Node.js. (In others words, let node.js install it for you)
    3. Install Git: Git Website Just be sure to check this option to Run Git command in Windows prompt screen shot git installation
    4. Install Bower (globalement) : npm install -g bower
    5. Configure Visual Studio Tools to use new tools installed. To do that, Launch Visual Studio => Tools => Options => Open node "Projects and Solutions" => Open External Web Tools => Uncheck "$(DevEnvDir)\Extensions\Microsoft\Web Tools\External\git". Add new "C:\Program Files (x86)\Git\bin"
    6. Set Proxy settings. Run below scripts in PowerShell as Administrator

    I have created 2 powershell scripts for Windows to set/unset proxy settings (Tested on Windows 10).

    • At work, I need to set proxy settings.

      Run > ./proxy.ps1in a powershell

    • At home, I must remove proxy settings.

      Run > ./proxy.disabled.ps1 in a powershell

    proxy.ps1

    # System Environment variable
    $env:HTTP_PROXY = "http://proxyuser:proxypwd@proxy.server.com:8080"
    $env:HTTPS_PROXY = "http://proxyuser:proxypwd@proxy.server.com:8080"
    # Fix (some tools uses lowercase env variables)
    $env:http_proxy = "http://proxyuser:proxypwd@proxy.server.com:8080"
    $env:https_proxy = "http://proxyuser:proxypwd@proxy.server.com:8080"
    # Git config
    git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
    git config --global https.proxy http://proxyuser:proxypwd@proxy.server.com:8080
    # Npm config
    npm config set proxy http://proxyuser:proxypwd@proxy.server.com:8080
    npm config set https-proxy http://proxyuser:proxypwd@proxy.server.com:8080
    # Restart Windows
    Restart-Computer -Confirm
    

    proxy.disabled.ps1

    # Delete System Environment variable
    Remove-Item env:\HTTP_PROXY
    Remove-Item env:\HTTPS_PROXY
    Remove-Item env:\http_proxy
    Remove-Item env:\https_proxy
    # Reset Git Config
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    # Reset Npm Config
    npm config --global delete proxy
    npm config --global delete https-proxy
    # Restart Windows
    Restart-Computer -Confirm
    

    WARNING: If you have specials characters in your proxy password, you must encode the proxy url. Example:

    • username: DOMAIN\user name
    • password: P@$$w0rd
    • proxy server: 10.80.0.0
    • proxy port: 8080
    • PROXY URL with authentification: http://DOMAIN%5Cuser+name%3AP%40%24%24w0rd@10.80.0.0:8080

    WARNING: UNSET PROXY => Some bower settings can be overrided in a .bowerrc file located at C:\Users\%USERNAME%. In others words, if it doesn't work, check if you have a .bowerrc file. Then remove the following keys if they exist:

    {
      ...
      "proxy": "http://proxyuser:proxypwd@proxy.server.com:8080",
      "https-proxy": "http://proxyuser:proxypwd@proxy.server.com:8080",
       ...
    }
    

    WARNING: UNSET PROXY => Some nmp/node settings can be overrided in a npmrc file located at C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\node\etc. In others words, if it doesn't work, check if you have a npmrc file. Then remove the following key if they exist:

    http_proxy="http://proxyuser:proxypwd@proxy.server.com:8080"
    https_proxy="http://proxyuser:proxypwd@proxy.server.com:8080"
    

    Et Voilà :)

    0 讨论(0)
  • 2020-11-29 02:22

    Same problem using VS 2015, my workaround :

    1. Install Git

      http://git-scm.com/

    2. Configure Git to use http instead of git:// with Git Bash

      git config --global url."http://".insteadOf git://

      Edit (as pointed by g.pickardou) you can use https to be more secure:

      git config --global url."https://".insteadOf git://

    3. Configure VS to use the new installed Git over VS Git

      Right click on Bower folder (under Dependencies), then select "Configure external tools"

      Uncheck "$(DevEnvDir)\Extensions\Microsoft\Web Tools\External\git"

      Add a new node with "C:\Program Files (x86)\Git\bin"

    Hope this will help someone,

    Rogerio

    0 讨论(0)
  • 2020-11-29 02:30

    If you have a frendly firewall administrator, aks him to allow access to external git repositories by defining the following firewall-policy:

    TCP 9418 (no need for UDP)

    0 讨论(0)
  • 2020-11-29 02:32

    Running VS's Bower from the command line with a mapped home folder

    The answer given by @Rogerio Soares is a good one and I think many people will find it very useful (myself included).

    That said, here at work, the tools I can install are very, very restricted (meaning I can't install another version of Bower without getting permission from lots of people), plus my home directory is mapped to a network share at z:\ by policy. Each time I issued git config --global to configure git, the config settings would be placed in z:\.gitconfig. This config file is honored just fine using full-blown Git SCM. Apparently, however, libgit2sharp (used by the version of Git embedded with Visual Studio 2015) needs this file to be at c:\username\.gitconfig.

    So after copying my .gitconfig file from z:\ to c:\username\, I was able to run Visual Studio's version of bower directly from the command line.

    0 讨论(0)
提交回复
热议问题