git VS 2015 + Bower:在防火墙后面不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28725727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:48:03  来源:igfitidea点击:

VS 2015 + Bower: Does not work behind firewall

gitbowerfirewallvisual-studio-2015git-config

提问by SeanKilleen

Problem

问题

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

在 Visual Studio 2015 中,使用 bower,我的包在防火墙后面恢复失败,错误类似于:

ECMDERR Failed to execute "git ls-remote --tags --heads git://github.com/jzaefferer/jquery-validation.git", exit code of #-532462766

ECMDERR 无法执行“git ls-remote --tags --heads git://github.com/jzaefferer/jquery-validation.git”,退出代码为#-532462766

I have updated my git config to use httpinstead of git. When I run from my command line, the command is successful:

我已经更新了我的 git 配置来http代替 git。当我从命令行运行时,命令成功:

enter image description here

在此处输入图片说明

But Visual Studio or one of its components appears to be using gitinstead of httpregardless.

但是 Visual Studio 或其组件之一似乎正在使用,git而不是http不管。

Background & First Attempt to Resolve

背景和首次尝试解决

Using Visual Studio 2015 and Bower for package management. It works great when not behind a firewall, but when behind a firewall I cannot use the git://protocol.

使用 Visual Studio 2015 和 Bower 进行包管理。当不在防火墙后面时它工作得很好,但是在防火墙后面时我不能使用该git://协议。

The solution -- documented in many other places on SO (example), is to run:

解决方案 - 在 SO(示例)的许多其他地方都有记录,是运行:

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

I did this, and now my git config -llooks like:

我这样做了,现在我的git config -l样子:

ore.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.name=Sean Killeen
[email protected]
url.http://.insteadof=git://

But despite this, either Visual Studio / npm is not respecting my configuration, or is using an old, cached version of it.

但尽管如此,要么 Visual Studio / npm 不尊重我的配置,要么正在使用它的旧缓存版本。

Second Attempt to Resolve

第二次尝试解决

Per this thread on npm issue, I saw that npm (which presumably bower is using in VS) uses the git@syntax. Even though this isn't what I saw in the output, I figured I'd give it a shot.

根据npm issue 上的这个线程,我看到 npm(大概 bower 在 VS 中使用)使用了git@语法。尽管这不是我在输出中看到的,但我想我会试一试。

I ran:

我跑了:

git config --global url."https://github.com/".insteadOf [email protected]:

I then restarted Visual Studio, but the issue still persists. The fix I'd read about was likely never applicable.

然后我重新启动了 Visual Studio,但问题仍然存在。我读过的修复程序可能永远不适用。

Any ideas on how to fix?

关于如何修复的任何想法?

回答by Rogerio Soares

Same problem using VS 2015, my workaround :

使用 VS 2015 的相同问题,我的解决方法:

  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"

  1. 安装 Git

    http://git-scm.com/

  2. 将 Git 配置为在 Git Bash 中使用 http 而不是 git://

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

    编辑(如 g.pickardou 所指出的)您可以使用 https 来更安全:

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

  3. 配置 VS 以使用新安装的 Git 而不是 VS Git

    右键单击 Bower 文件夹(在依赖项下),然后选择“配置外部工具”

    取消选中“$(DevEnvDir)\Extensions\Microsoft\Web Tools\External\git”

    使用“C:\Program Files (x86)\Git\bin”添加一个新节点

Hope this will help someone,

希望这会帮助某人,

Rogerio

罗杰里奥

回答by BrettJ

Microsoft's version of git that is installed (at least with VS2015 Update 1) doeshonor the .gitconfig file, but the tooling that is installed by default does not give you a way to manipulate it (like all the other answers show using git config to fix the problem).

已安装的 Microsoft 版本的 git(至少在 VS2015 Update 1 中)确实支持.gitconfig 文件,但是默认安装的工具并没有给你一种操作它的方法(就像所有其他答案显示使用 git config解决问题)。

To fix the problem without any extra installations and whatnot, simply create a .gitconfig file in C:\Users\YourUserName and put this content in there (which is the content that git config --global would do but since you dont have a git.exe that can change config, you cannot use that without installing something else you do not really need)

要在没有任何额外安装等的情况下解决问题,只需在 C:\Users\YourUserName 中创建一个 .gitconfig 文件并将此内容放在那里(这是 git config --global 会做的内容,但因为你没有 git .exe 可以更改配置,如果不安装其他你并不真正需要的东西,你就不能使用它)

    [url "https://github.com/"]
        insteadOf = [email protected]:
    [url "https://"]
        insteadOf = git://

回答by arcaner

The solution that worked for me with VS2015 Release is to :

在 VS2015 Release 中对我有用的解决方案是:

  1. Install git command line tool.
  2. Modify the file C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\bower.cmd with this content:

    set PATH=C:\Program Files (x86)\Git\bin\;%PATH%
    git config --global url."http://".insteadOf git://
    git config -l
    @"%~dp0\node\node" "%~dp0\bower\node_modules\bower\bin\bower" %*
    
  1. 安装 git 命令行工具。
  2. 使用以下内容修改文件 C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\bower.cmd:

    set PATH=C:\Program Files (x86)\Git\bin\;%PATH%
    git config --global url."http://".insteadOf git://
    git config -l
    @"%~dp0\node\node" "%~dp0\bower\node_modules\bower\bin\bower" %*
    

回答by MagicMau

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.

我有同样的问题。显然,VS2015 CTP 附带的 Git.exe 不使用 .gitconfig。但是您可以(手动)修复它,如果您在其他地方安装了 git 命令行工具。

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

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External您将需要编辑文件bower.cmd

Comment out lines 4 and 5:

注释掉第 4 行和第 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.

这将触发使用您已安装的 Git 的命令,该命令将获取本地 .gitconfig。

Make sure you have set the appropriate git setting:

确保您已设置适当的 git 设置:

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

回答by Mano Mangaldas

With VS 2015, Update 2 : Just install Git

使用 VS 2015,更新 2:只需安装 Git

http://git-scm.com/

http://git-scm.com/

回答by L.L.

I had the same problem in Visual Studio 2015 RC (not CTP) and got resolved.

我在 Visual Studio 2015 RC(不是 CTP)中遇到了同样的问题并得到了解决。

The bower.cmd in 2015 RC does not work well so I needed to disable it in my VS and use the official one installed on my PC. It is easy to do it just right click "Bower" folder in the project and select "configure external tools" then uncheck the section "$(DevEnvDir)\Extensions\Microsoft\Web Tools\External\git".

2015 RC 中的 bower.cmd 不能很好地工作,所以我需要在我的 VS 中禁用它并使用我的 PC 上安装的官方版本。只需右键单击项目中的“Bower”文件夹并选择“配置外部工具”,然后取消选中“$(DevEnvDir)\Extensions\Microsoft\Web Tools\External\git”部分即可,这很容易。

You may also need to change ".bowerrc" file to make GIT working in the right path for you project.

您可能还需要更改“.bowerrc”文件以使 GIT 在您的项目的正确路径中工作。

After doing this, everything works as expected.

执行此操作后,一切都按预期进行。

回答by pawan nepal

The easiest answer which definitely works is here. I had a big headache with this issue. Just download git and install it. While installing choose this option. Run Git from the windows command prompt

绝对有效的最简单答案在这里。我对这个问题很头疼。只需下载 git 并安装它。安装时选择此选项。 从 Windows 命令提示符运行 Git

回答by SirSquidness

I had this same problem in Visual Studio 2015 RC (not CTP). Since this is the only relevant thread I found anywhere, figured I'd add my 2c here.

我在 Visual Studio 2015 RC(不是 CTP)中遇到了同样的问题。由于这是我在任何地方找到的唯一相关线程,我想我会在这里添加我的 2c。

Expanding on @MagicMau's answer, the lines in bower.cmd referenced don't exist in 2015 RC, so I took a different approach and set the PATH env variable, so that my entire bower.cmd file now looks like this:

扩展@MagicMau 的答案,引用的 bower.cmd 中的行在 2015 RC 中不存在,所以我采用了不同的方法并设置了 PATH 环境变量,这样我的整个 bower.cmd 文件现在看起来像这样:

set PATH=C:\Program Files (x86)\Git\bin\;%PATH%
@"%~dp0\node\node" "%~dp0\bower\node_modules\bower\bin\bower" %*

Note that the first line is what I added, and the second line was the existing content.

请注意,第一行是我添加的内容,第二行是现有内容。

The first time I did this, Visual Studio crashed during package restore, but seems to be working after a restart of VS.

我第一次这样做时,Visual Studio 在包还原期间崩溃,但在 VS 重新启动后似乎可以正常工作。

回答by rdhainaut

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.

我使用 Visual Studio 2015 在 Windows 10 上工作。我必须在工作时设置代理设置并在家里删除它们。

To achieve this, you have 2 solutions.

要实现这一点,您有 2 个解决方案。

  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)
  1. 配置 Visual Studio 外部工具以使用适当的设置
  2. 在你的机器上安装工具(node、npm、bower)并使用它们(你可以设置 Visual Studio 选项来使用它们)

Solution 1 (Configure VS external tools)

方案一(配置VS外部工具)

  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:[email protected]:8080
    > npm.cmd config set --global http_proxy http.proxy http://proxyuser:[email protected]:8080
    
  2. Configure Git. Add a .gitconfig file located at C:\Windows\Users\%USERNAME%. Then add followings key/value.

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

    {
      "proxy": "http://proxyuser:[email protected]:8080",
      "https-proxy": "http://proxyuser:[email protected]:8080"
    }
    
  1. 配置 NPM。在管理员提示符下执行以下 cmd。

    > 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:[email protected]:8080
    > npm.cmd config set --global http_proxy http.proxy http://proxyuser:[email protected]:8080
    
  2. 配置 Git。添加位于 C:\Windows\Users\%USERNAME% 的 .gitconfig 文件。然后添加以下键/值。

    [http]
        proxy = http://proxyuser:[email protected]:8080
    [https]
        proxy = http://proxyuser:[email protected]:8080
    
  3. 配置 Bower。添加位于 C:\Windows\Users\%USERNAME% 的 .bowerrc 文件。然后添加以下键/值。

    {
      "proxy": "http://proxyuser:[email protected]:8080",
      "https-proxy": "http://proxyuser:[email protected]:8080"
    }
    

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

警告:如果您的代理密码中有特殊字符,则必须对代理 url 进行编码。例子:

Et Voilà :)

等等 :)

Solution 2 (Install tools on your machine)

解决方案 2(在您的机器上安装工具)

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).

我已经在我的机器上全局安装了 node.js、npm、git 和 bower(因为我需要有更多的控制权,而不仅仅是 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 WebsiteJust 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 PowerShellas Administrator
  1. 安装 Node.js:NodeJS 网站
  2. 安装 Npm注意:Npm 由 Node.js 自动安装。(换句话说,让 node.js 为您安装它)
  3. 安装 Git:Git 网站 请务必选中此选项以在 Windows 提示符下运行 Git 命令屏幕截图 git 安装
  4. 安装 Bower (globalement): npm install -g bower
  5. 配置 Visual Studio 工具以使用安装的新工具。为此,启动 Visual Studio => 工具 => 选项 => 打开节点“项目和解决方案” => 打开外部 Web 工具 => 取消选中“$(DevEnvDir)\Extensions\Microsoft\Web Tools\External\git”。添加新的“C:\Program Files (x86)\Git\bin”
  6. 设置代理设置。以管理员身份在PowerShell 中运行以下脚本

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

我为 Windows 创建了 2 个 powershell 脚本来设置/取消设置代理设置(在 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.ps1in a powershell

  • 工作中,我需要设置代理设置。

    > ./proxy.ps1在 powershell 中运行

  • 家里,我必须删除代理设置。

    > ./proxy.disabled.ps1在 powershell 中运行

proxy.ps1

代理.ps1

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

proxy.disabled.ps1

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:

警告:如果您的代理密码中有特殊字符,则必须对代理 url 进行编码。例子:

WARNING: UNSET PROXY => Some bower settings can be overrided in a .bowerrcfile 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:

警告:UNSET PROXY => 一些 bower 设置可以在位于 C:\Users\%USERNAME%的.bowerrc文件中被覆盖。换句话说,如果它不起作用,请检查您是否有 .bowerrc 文件。然后删除以下键(如果存在):

{
  ...
  "proxy": "http://proxyuser:[email protected]:8080",
  "https-proxy": "http://proxyuser:[email protected]:8080",
   ...
}

WARNING: UNSET PROXY => Some nmp/node settings can be overrided in a npmrcfile 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:

警告:UNSET PROXY => 某些 nmp/节点设置可以在位于 C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\node\etc的npmrc文件中覆盖. 换句话说,如果它不起作用,请检查您是否有 npmrc 文件。然后删除以下键(如果存在):

http_proxy="http://proxyuser:[email protected]:8080"
https_proxy="http://proxyuser:[email protected]:8080"

Et Voilà :)

等等 :)

回答by rdhainaut

If you want a global solution.

如果你想要一个全球解决方案

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

警告:它可以通过不同的应用程序影响多个代理设置,但它肯定是你想要的:)

NOTEIf 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%[email protected]:8080

注意如果您的代理设置中的 username:password 中有特殊字符,则需要对它们进行 URLENCODED。示例:http://DOMAIN%5Cuser+name%3AP%40%24%[email protected]:8080

You must add 2 environment variable.

您必须添加 2 个环境变量。

To do that on windows 10:

要在 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:[email protected]:8080)
  6. Create Variable (Variable name: HTTPS_PROXY, Variable value: http://proxyuser:[email protected]:8080)
  7. Restart Windows
  1. 开始
  2. 搜索“编辑系统环境变量”
  3. (在系统属性的高级选项卡中)单击“环境变量...)
  4. (在系统变量中)单击“新建...”
  5. 创建变量(变量名:HTTP_PROXY,变量值:http://proxyuser:[email protected]:8080
  6. 创建变量(变量名:HTTPS_PROXY,变量值:http://proxyuser:[email protected]:8080
  7. 重新启动 Windows