25

为 .NET 各种开发工具设置网络代理,提升在大陆的网络性能

 4 years ago
source link: https://blog.walterlv.com/post/setting-up-proxies-for-development-tools.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

git、nuget、scoop 如何设置网络代理提升网络访问速度呢?

在下面的博客正文中,都假设我的本机搭设了代理服务,其中 SOCKS5 代理服务的端口号是 7777,HTTP 代理服务的端口号是 7778。

git

使用命令行设置

git 支持设置 http 代理和 socks5 代理,http 的代理和 https 的代理是分开设置的。

设置方法:

  1. 打开任意一个命令行工具;
  2. 在命令行中输入以下两个命令并回车。
git config --global http.proxy http://127.0.0.1:7778
git config --global https.proxy http://127.0.0.1:7778

或者:

git config --global http.proxy socks5://127.0.0.1:7777
git config --global https.proxy socks5://127.0.0.1:7777

在设置完成之后, 你无需担心内网访问的问题 ,因为 Git 会自动在代理的时候过滤掉内网代理。

直接修改配置文件

git 全局配置文件的路径在:

  • %USERPROFILE%\.gitconfig

在这个文件中,你需要添加以下几行:

[user]
        name = walterlv
        email = [email protected]
+   [http]
+       proxy = http://127.0.0.1:7778
+   [https]
+       proxy = http://127.0.0.1:7778

或者:

[user]
        name = walterlv
        email = [email protected]
+   [http]
+       proxy = socks5://127.0.0.1:7777
+   [https]
+       proxy = socks5://127.0.0.1:7777

添加完成之后,你的 git 访问就会走代理,对于 GitHub 的访问,快速克隆大型仓库是非常有帮助的。

使用 TortoiseGit 设置

以上命令行的方法是最简单的,然而你也可以使用其他的工具设置,比如 TortoiseGit。

设置方法:

  1. 在任意的文件夹中打开 TortoiseGit 的设置页面,然后定位到网络一栏中,勾选“使用代理服务器”。
  2. 输入服务器地址和端口号,确定即可。

qMRbmaU.png!web

NuGet

使用 NuGet 直接拉取 的内容也是很慢的,如果有一个代理服务器的设置那么也能大大提速。

在命令行中设置

> nuget config -set http_proxy=http://127.0.0.1:7778

直接修改配置文件

git 全局配置文件的路径在:

  • %APPDATA%\NuGet\NuGet.Config

在这个文件中,你需要添加以下几行:

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
      </packageSources>
      <config>
+       <add key="http_proxy" value="http://127.0.0.1:7778" />
      </config>
    </configuration>

如果这么设置了,那么 NuGet 会为所有的包源设置代理。然而内部部署的包源并不需要代理,于是还需要设置 no_proxy

<configuration>
      <config>
        <add key="http_proxy" value="http://127.0.0.1:7778" />
+       <add key="no_proxy" value="localhost,127.0.0.1,*.walterlv.com" />
      </config>
    </configuration>

Scoop

Scoop 是一款优秀的包管理工具,可以以绿色的方式安装各种工具。

scoop config proxy 127.0.0.1:7778

参考资料


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK