【问题标题】:msbuild + visual studio executing the wrong typescript version despite installing from nuget尽管从 nuget 安装,但 msbuild + Visual Studio 执行错误的打字稿版本
【发布时间】:2017-06-21 14:55:19
【问题描述】:

我已将 typescript 编译器和 MSBUILD 安装到项目中。 这是一个针对框架 4.6.1 的 dotnet 核心项目 (csproj)

`.csproj file...`
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
  <TargetFramework>net461</TargetFramework>
  <PreserveCompilationContext>true</PreserveCompilationContext>
  <AssemblyName>Ignite.Web</AssemblyName>
  <OutputType>Exe</OutputType>
  <PackageId>Ignite.Web</PackageId>
  <CodeAnalysisRuleSet>..\Ignite.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
  <DocumentationFile>bin\Debug\net461\Ignite.Web.xml</DocumentationFile>
  <CodeAnalysisRuleSet>..\Ignite.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
...

该文件还包含用于编译器和 msbuild 的 nuget 包

<ItemGroup>
  <PackageReference Include="Microsoft.TypeScript.Compiler" Version="2.3.3" />
  <PackageReference Include="Microsoft.TypeScript.MSBuild" Version="2.3.3" />

然而,当我使用 Visual Studio 2017 或 msbuild 构建时,由于使用了错误版本的编译器,我得到了错误。

我该如何在 IDE 和 msbuild 中完全禁止构建 typescript(我仍然在使用 webpack),或者修复路径

PreComputeCompileTypeScriptWithTSConfig:
  C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.2\tsc.exe --project "C:\Projects\Github\Ignite\Ignite.Web\tsconfig.json" --listEmitted
  Files
CompileTypeScriptWithTSConfig:
  C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.2\tsc.exe --project "C:\Projects\Github\Ignite\Ignite.Web\tsconfig.json" --listEmitted
  Files

从输出中可以看出,当我执行 msbuild 时,它使用的是 2.2 版本。

【问题讨论】:

  • 顺便说一句,如果您希望通过 WebPack 完成 TS 编译,为什么还要包含这些 NuGet 包?我假设编译器将通过 npm 引入
  • 我使用 Visual Studio 编辑打字稿文件,在 IDE 中显示错误/警告很有用,我不知道我该怎么做?

标签: typescript msbuild visual-studio-2017


【解决方案1】:

VS中包含的导入目标允许使用禁用编译

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

csproj 文件中。

强制 typescript 编译器使用包含的 2.3 版本的 Microsoft.Typescript.Compiler 使用

<TypeScriptToolsVersion>2.3</TypeScriptToolsVersion>

csproj 文件中。

【讨论】:

  • 感谢您的回答!就我而言,我们希望 VS 在构建期间编译 TypeScript。如果我将 nuget 包更新为(例如)3.3.1 版本,是否需要将 更新为 3.3?
猜你喜欢
  • 2019-05-08
  • 1970-01-01
  • 2016-11-24
  • 1970-01-01
  • 2022-11-24
  • 2014-10-15
  • 1970-01-01
  • 2018-11-11
  • 2017-05-21
相关资源
最近更新 更多