網站搜尋

即使從 NuGet 安裝,msbuild + visual studio 仍然執行錯誤的 TypeScript 版本


我已經在專案中安裝了 TypeScript 編譯器和 MSBUILD。這是一個 dotnet core 專案(csproj),目標框架為 4.6.1

`.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 版本。

答案#1

VS 中包含的匯入目標允許通過使用來禁用編譯

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

在 csproj 文件中。

要強制 TypeScript 編譯器使用包含的 2.3 版本的 Microsoft.Typescript.Compiler,請使用

<TypeScriptToolsVersion>2.3</TypeScriptToolsVersion>

在 csproj 文件中。