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,安装到离线环境即可