1

I'm hoping to stop including the generated JavaScript files in TFS source control, but I haven't managed to get the compiler to run on a build.

I've followed this chap's example and edited the project file to give me:

  <ItemGroup>
    <TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
  </ItemGroup>
  <Target Name="BeforeBuild">
    <Message Text="Before Build" Importance="high" />
    <CallTarget Targets="TypeScriptBuild"/>
  </Target>
  <Target Name="TypeScriptBuild"  Inputs="@(TypeScriptCompile)" Outputs="%(Identity).Dummy" Condition="'$(CompileTypeScript)'=='true'">
    <Message Text="Building typescript file - @(TypeScriptCompile)"  Importance="high" />
    <Exec Command="&quot;$(MSBuildProgramFiles32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\tsc&quot; -target ES3 &quot;@(TypeScriptCompile)&quot;" />
  </Target>

I've changed the file location where the tsc executable is and removed the TypeScript version information, but it isn't doing anything for me. I'm a complete newbie at this build stuff so would appreciate any help, or tips on how to debug it.

Edit 1 Removed

<ItemGroup>
  <TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
</ItemGroup>

as it was redundant - this is added individually for every TypeScript file in the project.

The only warnings I'm getting are about inconclusive unit tests. I assumed that <Message Text="Before Build" Importance="high" /> would produce some kind of log message but I can't see it anywhere.

Edit 2 Got it working locally within Visual Studio by putting

<Target Name="BeforeBuild">
  <Message Text="Compiling typescript...">
  </Message>
<Exec Command="&quot;$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript\tsc&quot; -target ES3 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />

at the end of the .csproj file. For some reason this doesn't work when TFS is building it. If I change the TypeScript compiler file location to something nonsensical it complains, but when it's correct there are no JavaScript files produced.

4

1 回答 1

1

你真的不应该做任何这些。确保此行在您的 csproj 中,在</project>

<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />

然后在构建机器上安装 TypeScript。您还需要确保文件Build Action.ts设置为TypeScriptCompile. 此时,TypeScript 将编译您的 .ts 文件并生成 js 文件。您不会(也不应该)将 .js 文件检入代码存储库。

单元测试

您真的希望您的单元测试与您的其余代码一起构建。更重要的是,您可以在构建时运行这些单元测试,并在其中任何一个测试失败时使用它们来使构建失败!

查看msdn 上的这篇文章和codeplex上的这篇文章,以帮助您入门。它将涉及使用Chutzpah。另外,请注意,使用 Chutzpah 时,您的 .js 捆绑/交付方式可能会有所不同,因为 Chutzpah 必须为您构建该捆绑包,而我不确定您的实际站点是如何做到的。

于 2014-01-02T17:20:37.663 回答