2016年9月23日 星期五

[vscode]extension 裡的 FileSystemWatcher 壞掉了?

Why is vs code’s FileSystemWatcher not working on my Windows 7?
You need .NET 4.5.

前言

這篇其實就是個一拳就解決的事情。但是為了要演滿20分鐘,所以傑諾斯一定要撐很久的情況。不能打贏對手,也不能一拳就躺下來休息。(我在講什麼?)

環境

出問題的環境多是 windows 7,其他的環境像是 windows 8, windows 10, mac os, linux 幾乎都沒人中招。

問題描述

這樣也可以撐三段,可以了。簡單來說,像是 Package-Watcher 這種會看某個檔案是否會被外部程式改變的。它需要一個 FileSystemWatcher 的實體,由 workspace.createFileSystemWatcher 產生,然後處理它的 onDidChage。
// 這是 TypeScript,微軟主推在 javascript 世界的前置語言,它會被編譯成合於 ES5、ES6、或 ES7 再交由 node.js 或瀏覽器執行。

let path = vscode.workspace.rootPath + "/package.json";
let watcher = vscode.workspace.createFileSystemWatcher(path);
watcher.onDidChange((e) => {
    console.log('package.json change')
})
但是!!這就是在我的 windows 7 裡不能執行。花了我快十個小時,弄到凌晨四、五點不得不去睡覺,但還是沒解。
今天上午去查 issue,看到這一句:
This issue is that Electron requires .NET 4.5 since it uses System.Threading.Tasks.Task.Delay(Int32) which came with .NET 4.5
來源:https://github.com/Microsoft/vscode/issues/5083
就是說,因為 windows 7 常常有人忘了要裝到 4.5,沒注意到的話,通常都留在 4.0。而其他版本,要嘛因為不能裝,要嘛太低使用者會自己裝,要嘛內建就 4.5,所以中招的就是 windows 7 最多!

解法

請裝 .NET 4.5。
一拳。

沒有留言:

張貼留言