Gitlab私有存储库支持SourceLink 调试之使用proxy方式

前情概要

让你发布的nuget包支持源代码调试#为gitlab的私有源代码项目提供支持 小节中有介绍到如何让gitlab的私有存储库支持SourceLink. 其中有一个方法是说在vs中打开webbrower登录, 利用已登录session支持. 但是在时间车轮经过一段不短的距离后. vs2022 中已经没有web brower了, 同时gitlab也不再支持IE. 所以利用共享Session方式行不通了.
同时GCM+SourceLink任然不支持, 最后只能选择使用Proxy的方式来实现一把.

方案

VS --> SourceLink --> gitlab.com(127.0.0.1,gitlabproxy) --> gitlab.com(使用 用户token + gitlab api 下载源文件)

环境配置

修改hosts文件, 将gitlab.com 指向 127.0.0.1

# C:\Windows\System32\drivers\etc\hosts
127.0.0.1 gitlab.com

启动一个WebProxy. 让gitlabproxy可以访问真正的gitlab.com

用什么都可以, 反正就是一个Proxy, 例如我的http代理在 http://127.0.0.1:10809.

当然, 如果不选择使用webproxy的方式, 也可以配置gitlabproxy的gitlabHost, 将它改成一个真实的gitlab.com服务器ip, 然后配置requet.header.host=gitlab.com

准备 gitlab.com(127.0.0.1,gitlabproxy) 代理程序

https://gitlab.com/slcon/pub/repo/gitlabproxy repo clone 下来.
然后做一点修改

# gitlab 在12还是多少版本之后修改了路径规则, 之后的版本没有 "/-/" 部分了. 所以删除个.
new Regex(@"^\/(?<project>.+?)\/-\/raw\/(?<commit>[\da-f].+?)\/(?<filepath>.+)$");
# ==>
new Regex(@"^\/(?<project>.+?)\/raw\/(?<commit>[\da-f].+?)\/(?<filepath>.+)$");

# 使用代理, 访问真正的gitlab.com
response  = WebRequest.Create(remoteUrl).GetResponse() as HttpWebResponse;
# ==>
var request = WebRequest.Create(remoteUrl);
request.Proxy = new WebProxy("http://127.0.0.1:10809");
response = request.GetResponse() as HttpWebResponse;

将此修改的gitlabproxy程序部署到本地iis, 并绑定域名 https://gitlab.com:443

修改 gitlabproxy 的 web.config 文件

到https://gitlab.com/-/profile/personal_access_tokens 创建一个个人token, 然后添加到appSettings section 中.

<appSettings>
  <add key="gitlabHost"        value="https://gitlab.com" />
  <add key="{your gitlab group path}" value="glpat-****************" /> 
  <add key="{your gitlab project path}" value="glpat-****************" /> 
</appSettings>

完成

不出意外的话, 现在在vs里面F11调试就可以进入源代码了.

https://gitlab.com/slcon/pub/repo/gitlabproxy
https://github.com/dotnet/sourcelink/issues/281

posted @ 2022-08-29 18:58  czd890  阅读(156)  评论(0编辑  收藏  举报