2016-09-26 53 views
6

當我保存時,我無法讓visual studio將typescript編譯爲js。當tsconfig.json在項目中時,保存時的Typescript編譯不工作

enter image description here

我有一個xproj(淨框架asp.net核心) 打字稿2.0.3工具爲Visual Studio 2015年更新3

我試圖啓用tsconfig.json "watch" : true但它表示當前主機不受支持。

我去工具>選項>文本編輯器>打字稿>項目並啓用了「自動編譯打字稿文件不屬於項目的一部分」

enter image description here

儘管如此,.ts文件的變化將體現在.js文件中僅在編譯期間,但只有在編譯的c#服務器端文件發生更改時纔會生效。

編輯:我已經知道在項目目錄中tsconfig.json的簡單存在將防止保存編譯,即使配置文件爲空。

現在可以修正某種方式嗎?

這是我tsconfig.json的內容:

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "diagnostics": true 
    }, 
    "include": [ 
    "**/*.ts" 
    ], 
    "exclude": [ 
    "node_modules" 
    ] 
} 

編輯2:我也嘗試:

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "diagnostics": true 
    }, 
    "filesGlob": [ 
    "**/*.ts" 
    ], 
    "exclude": [ 
    "node_modules" 
    ] 
} 

,並沒有做任何事情。

+2

我有完全相同的問題。此外,自安裝Update 3和Typescript 2.0.3以來,智能感知不再有效。任何人都有解決方案? – Bluesight

回答

6

我卸載的Visual Studio 2015和打字稿2.0.3。然後我重新安裝了Visual Studio 2015.打開我的解決方案並檢查了Typescript 1.8.3後,我安裝了Typescript 2.0.3並在「compilerOptions」之前添加了「compileOnSave」。從那以後它對我有用。添加此選項後,您需要重新啓動Visual Studio。

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    ... 
} 
+3

您需要重新啓動Visual Studio!那是一個小屁屁手!謝謝@Bluesight – doker

+0

不能在這裏工作:( –

2

添加"compileOnSave":truetsconfig.json應該做的伎倆:

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    ... 
+0

我也這麼認爲,但這是一個默認選項,它不起作用。 – doker

相關問題