也许这是显而易见的,但我到处检查(除了正确的地方),谷歌它。什么都没有。


当前回答

我有VS2015,我必须用TypeScript 1.7运行一个构建,虽然我有1.8安装通过npm install TypeScript -g有两种方法(至少对我来说他们工作):

到你的.proj文件中,尽可能地添加<TypeScriptToolsVersion>1.7</TypeScriptToolsVersion>。重建,重新运行。如果不行,试试2。 进入“控制面板->系统->高级系统设置->环境变量”。确保你先添加了你想要的TypeScript版本:C:\Program Files (x86)\Microsoft sdk \TypeScript\1.7;C:\Users\serban\AppData\Roaming\npm

这也会影响你的CLI:

$ tsc -v
message TS6029: Version 1.7.5

其他回答

As far as I understand VS has nothing to do with TS installed by NPM. (You may notice after you install TS using NPM, there is no tsc.exe file). VS targets only tsc.exe installed by TS for VS extension, which installes TS to c:\Program Files (x86)\Microsoft SDKs\TypeScript\X.Y. You may have multiple folders under c:\Program Files (x86)\Microsoft SDKs\TypeScript. Set TypeScriptToolsVersion to the highest version installed. In my case I had folders "1.0", "1.7", "1.8", so I set TypeScriptToolsVersion = 1.8, and if you run tsc - v inside that folder you will get 1.8.3 or something, however, when u run tsc outside that folder, it will use PATH variable pointing to TS version installed by NPM, which is in my case 1.8.10. I believe TS for VS will always be a little behind the latest version of TS you install using NPM. But as far as I understand, VS doesnt know anything about TS installed by NPM, it only targets whateve versions installed by TS for VS extensions, and the version specified in TypeScriptToolsVersion in your project file.

对于非命令行方法,你可以打开扩展和更新窗口(工具->扩展和更新),并在安装下搜索Typescript For Microsoft Visual Studio扩展

我有VS2015,我必须用TypeScript 1.7运行一个构建,虽然我有1.8安装通过npm install TypeScript -g有两种方法(至少对我来说他们工作):

到你的.proj文件中,尽可能地添加<TypeScriptToolsVersion>1.7</TypeScriptToolsVersion>。重建,重新运行。如果不行,试试2。 进入“控制面板->系统->高级系统设置->环境变量”。确保你先添加了你想要的TypeScript版本:C:\Program Files (x86)\Microsoft sdk \TypeScript\1.7;C:\Users\serban\AppData\Roaming\npm

这也会影响你的CLI:

$ tsc -v
message TS6029: Version 1.7.5

如果你只为Visual Studio安装了TypeScript,那么:

启动Visual Studio命令提示符 输入tsc -v并按Enter


Visual Studio 2017版本15.3及以上将TypeScript版本绑定到单个项目,正如这个答案所指出的:

右键单击解决方案资源管理器中的项目节点 单击“属性” 进入TypeScript Build选项卡

你可以在Visual Studio 2013中的NuGet Package Manager Console中运行它。