在 Visual Studio 中使用特定的 TypeScript 编译器版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23245395/
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
Use specific TypeScript compiler version in Visual Studio
提问by Alexander Puchkov
I wonder if there's a way to set specific TypeScript compiler version for project in Visual Studio. So I could configure a project to always use version 1.0, even if new versions would be released.
我想知道是否有办法在 Visual Studio 中为项目设置特定的 TypeScript 编译器版本。因此,我可以将项目配置为始终使用 1.0 版,即使会发布新版本。
I know it was not possible beforeand I wonder if things changes after TypeScript matured to 1.0 version.
我知道以前是不可能的,我想知道在 TypeScript 成熟到 1.0 版本后情况是否会发生变化。
I noticed that now Visual Studio creates <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion>
property in a project file, but couldn't find any documentation about it.
我注意到现在 Visual Studio<TypeScriptToolsVersion>0.9</TypeScriptToolsVersion>
在项目文件中创建属性,但找不到任何关于它的文档。
回答by Kristoffer Lindvall
If you try to compile a project with <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion>
using TypeScript version 1.0 you'll get the following error:
如果您尝试<TypeScriptToolsVersion>0.9</TypeScriptToolsVersion>
使用 TypeScript 1.0 版编译项目,您将收到以下错误:
Your project file uses a different version of the TypeScript compiler and tools than is currently installed on this machine. No compiler was found at C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.9\tsc.exe. You may be able to fix this problem by changing the element in your project file.
您的项目文件使用的 TypeScript 编译器和工具版本与此机器上当前安装的版本不同。在 C:\Program Files (x86)\Microsoft SDKs\TypeScript\0.9\tsc.exe 中找不到编译器。您可以通过更改项目文件中的元素来解决此问题。
So it's preventing you from compiling with newer version. It does not however put the compiler into some 0.9 compatibility mode.
因此,它阻止您使用较新版本进行编译。然而,它不会将编译器置于某种 0.9 兼容模式。
But if you have TypeScript 0.9 installed, it will compile against that version. So yes, you can force a specific version of the TypeScript compiler using the attribute.
但是如果您安装了 TypeScript 0.9,它将针对该版本进行编译。所以是的,您可以使用该属性强制使用特定版本的 TypeScript 编译器。
Basically what the <TypeScriptToolsVersion>
do is that it changes the path to the compiler:
基本上所做的<TypeScriptToolsVersion>
是它改变了编译器的路径:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\<TypeScriptToolsVersion>\tsc.exe
回答by O?uzhan Soykan
I have solved it by adding $(TypeScriptToolsVersion)\
after TypeScript\
in the condition statement.
我通过在条件语句中添加$(TypeScriptToolsVersion)\
after来解决它TypeScript\
。
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets"
Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript$(TypeScriptToolsVersion)\Microsoft.TypeScript.targets')" />
回答by Kent Aguilar
Visual Studio Version -> VS2013
Visual Studio 版本 -> VS2013
- Install Typescript 1.8 -> https://visualstudiogallery.msdn.microsoft.com/9d0e9172-244a-4943-94e5-bd24dffd9536
- Open the folder location of your project e.g. Right click on your project > Open Folder in File Explorer
- Find and open the project file via text editor e.g. WebApplication1.csproj
- Find the "TypeScriptToolsVersion" tag under the "PropertyGroup" element and use 1.8. Like so,
- 安装 Typescript 1.8 -> https://visualstudiogallery.msdn.microsoft.com/9d0e9172-244a-4943-94e5-bd24dffd9536
- 打开项目的文件夹位置,例如右键单击您的项目> 在文件资源管理器中打开文件夹
- 通过文本编辑器找到并打开项目文件,例如 WebApplication1.csproj
- 在“PropertyGroup”元素下找到“TypeScriptToolsVersion”标签并使用1.8。像这样,
<PropertyGroup> ...... <IISExpressUseClassicPipelineMode /> <TypeScriptToolsVersion>1.8</TypeScriptToolsVersion> </PropertyGroup>
<PropertyGroup> ...... <IISExpressUseClassicPipelineMode /> <TypeScriptToolsVersion>1.8</TypeScriptToolsVersion> </PropertyGroup>
回答by Prasad Shigwan
We can exclude type script file compilation in visual studio using below line in csproj file.
我们可以使用 csproj 文件中的以下行在 Visual Studio 中排除类型脚本文件编译。
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
after <TypeScriptToolsVersion>0.9</TypeScriptToolsVersion>
this line.
在<TypeScriptToolsVersion>0.9</TypeScriptToolsVersion>
这一行之后。