即使从 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 文件中。
