VSCode离线环境中使用csharp扩展

VSCode C#官网插件:https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp
但是这里的插件,需要在线安装,即使Download Extension,下载的vsix安装之后,打开依然会出现下载提示

Installing C# dependencies...
Platform: win32, x86_64
Downloading package 'OmniSharp for Windows (.NET 4.6 / x64)' ...

看到github issue中讨论,需要手动编译离线包,参考:https://www.towfeek.se/2017/07/05/enabling-csharp-and-dotnet-core-debugging-in-vs-code-from-an-offline-environment/

我这边编译好的离线版本(在VSCode 1.46.1中测试通过):https://download.csdn.net/download/tangyin025/14046729

具体编译过程如下:
需要安装nodejs环境
https://nodejs.org/zh-cn/
我安装的版本是node-v10.15.3-x64.msi
安装之后在命令行确保node、npm可用

>node -v
v10.15.3
>npm -v
6.4.1

从github下载OmniSharp源码

git clone https://github.com/OmniSharp/omnisharp-vscode.git
cd omnisharp-vscode
npm i
npm run compile

然后官方的流程是修改 omnisharp-vscode/gulpfile.js,将其中的警告异常去掉,允许继续执行。但我取出的版本是 Branch_v1.23.2,代码结构不一样,进过尝试之后发现是 tasks/offlinePackagingTasks.ts
去掉里边的多平台配置,只保留win64(减少打包体积),再去掉windows offline异常

async function doPackageOffline() {
    ...
    const packages = [
        // 去掉其它的包
        new PlatformInformation('win32', 'x86_64')
    ];
    ...
}

async function doOfflinePackage(platformInfo: PlatformInformation, packageName: string, packageJSON: any, outputFolder: string) {
    if (process.platform === 'win32') {
        // 去掉异常,改为日志
        //throw new Error('Do not build offline packages on windows. Runtime executables will not be marked executable in *nix packages.');
        console.log('Do not build offline packages on windows. Runtime executables will not be marked executable in *nix packages.');
    }

然后编译打包

node node_modules/gulp/bin/gulp.js package:offline

我这边输出如下
在这里插入图片描述
在这里插入图片描述
最后生成 omnisharp-vscode/csharp.1.23.2-win32-x86_64.vsix,大概125MB

在离线环境中安装正常,但实际使用时,还会弹出要.net framework运行环境,因为我的离线环境中.net版本是3.5,但安装打包的机器用的是4.71的sdk,去官网:
https://dotnet.microsoft.com/download/dotnet-framework/net472
下载Offline 的 Runtime,安装到离线环境即可
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值