上下文
我正在使用VS 2017.3。刚刚创建了一个ASP MVC项目,然后添加了两个nuget包,
在尝试配置typescript构建时,我发现TypeScript版本2.5不可用。
问题
我错过了什么?我认为添加这些nuget包将使项目(和构建)独立于开发机器的安装状态......
到目前为止我尝试了什么
答案 0 :(得分:4)
为什么添加的typescript编译器版本仍然不可用?
您需要从download center下载并安装typescripts SDK 2.5.3版并重新启动Visual Studio。
Microsoft.TypeScript.MSBuild
的NuGet包用于提供TypeScript MSBuild任务,以及匹配的编译器版本。
从Visual Studio 2017开始,我们可以安装多个TypeScript版本,并为每个项目选择特定版本,安装Microsoft.TypeScript.MSBuild
包后,您可以为项目选择特定版本,例如,我有在我的机器上安装几个版本的Typescripts SDK:
然后我将该软件包安装到我的ASP MVC项目中,版本为 2.3 ,重新启动Visual Studio,重新打开项目,在Typescripts构建选项卡上,您会注意到匹配的版本默认情况下选择了Typescript 2.3 :
当然,您可以手动选择其他版本的Typescript。
答案 1 :(得分:0)
可以接受的答案很重要,但是也许进一步的解释会有所帮助。
在Visual Studio 2017中,nuget软件包随附的Typescript编译器仅由msbuild使用,但TypeScript语言服务依赖于要在计算机上安装的TypeScript SDK。引用github问题"Currently, compile on save in VS requires a matching version of the TypeScript language service to be installed on the machine."
尽管问题是用Visual Studio 2017标记的,但可能会用Visual Studio 2019对此问题进行修订。从候选发布版本的声明:"The JavaScript/TypeScript language service will now be automatically loaded in projects that have the TypeScript NuGet package or npm package installed (TypeScript 3.2 and up is supported from the NuGet package and TypeScript 2.1 and up is supported from the npm package)."