如何在.net核心控制台应用程序中编译Visual Studio 2015中的typescript?

问题描述 投票:0回答:2

我知道当你转到.net core / dnx时有一个简单的答案,但我需要在.net核心世界中得到答案。

我有一个控制台应用程序,它自行托管owin web服务器。我将typescript文件添加到项目中,语法高亮/ intellisense开箱即用。

但是,我无法弄清楚如何将.ts文件编译成我自己托管的Web服务器随后将提供的javascript文件。

在类型脚本文件属性选项卡上,构建操作被选为“TypeScriptCompile”,但它似乎不会影响任何内容。

我猜测编写一个特殊的msbuild脚本可以实现这一点,但我很想知道是否有更简单的解决方案可以内置到Visual Studio中。

.net visual-studio typescript compilation console
2个回答
0
投票

在属性中,将自定义工具设置为MSBuild:CompileTypeScript。在构建时,如果.ts已被修改,它将生成.js文件。


0
投票

根据this answer,将以下行添加到项目文件中:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" />`

在此之后它应该开始工作。对于.ts文件,您可以通过在项目文件中为这里的每个.ts文件添加这些行来使生成的.js,.js.map在visual studio中可见:

<ItemGroup>
  <None Include="file1.js">
    <DependentUpon>file1.ts</DependentUpon>
  </None>
  <None Include="file1.js.map">
    <DependentUpon>file1.ts</DependentUpon>
  </None>
</ItemGroup>

这假定您的.ts文件(已在项目中)称为file1.ts。

这看起来类似于以下内容:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.