Visual Studio 不编译 TypeScript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37262323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:29:23  来源:igfitidea点击:

Visual Studio not compiling TypeScript

visual-studiotypescriptvisual-studio-2015asp.net-core

提问by BanksySan

I have a Visual Studio project with a structure like so:

我有一个结构如下的 Visual Studio 项目:

Folder structure

文件夹结构

My tsconfig.jsonlooks like:

我的tsconfig.json样子:

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "outDir": "../wwwroot/"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

However, VS isn't compiling the app.tsinto the wwwrootfolder.

但是,VS 不会将其编译app.tswwwroot文件夹中。

What am I missing?

我错过了什么?

采纳答案by David Pine

From within Visual Studio, Project >Properties >Build >ensure that the "Compile TypeScript on build" is checked:

Visual Studio 中,Project >Properties >Build>确保选中“Compile TypeScript on build”:

enter image description here

在此处输入图片说明

Also, in your tsconfig.jsonyou should specify a rootDirso that TypeScriptknows where to look for *.tsfiles it should compile:

此外,tsconfig.json您应该指定 arootDir以便TypeScript知道在哪里查找*.ts它应该编译的文件:

{
  "compileOnSave": true,
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "outDir": "../wwwroot/",
    "rootDir": "../wwwroot/"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

The details are called out on the TypeScriptpage hereand here.

详细信息在此处此处TypeScript页面上调出。

Don't forget to actually build it. It isn't a file watcher scenario.

不要忘记实际构建它。这不是文件观察器方案。

回答by ericbowden

Try adding "compileOnSave": trueto your tsconfig.json:

尝试添加"compileOnSave": true到您的tsconfig.json

{
    "compilerOptions": {
        "noImplicitAny": false,
        "noEmitOnError": true,
        "removeComments": false,
        "sourceMap": true,
        "target": "es5",
        "outDir": "../wwwroot/"
     },
     "exclude": [
        "node_modules",
        "wwwroot"
    ],
    "compileOnSave": true
}

It should compile every time you save now.

现在每次保存时它都应该编译。