问题
We have an MSBuild script which we use to compile all our .ts files in our project. First we create a propery group containing all the .ts files;
<ItemGroup>
<AllTypeScriptFiles Include="XXXXX\Scripts\**\*.ts;" Exclude="XXXX\Scripts\**\*.d.ts;" />
</ItemGroup>
Then we dump this file list to an input file and run tsc.exe;
<WriteLinesToFile
File="typescriptcompiler.input"
Lines="@(AllTypeScriptFiles)"
Overwrite="true"
Encoding="Unicode"/>
<Exec Command=""$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript\$(TypeScriptVersion)\tsc" --target ES5 @typescriptcompiler.input"
CustomErrorRegularExpression="\.ts\([0-9]+,[0-9]+\):(.*)"
IgnoreExitCode="true" >
</Exec>
Now, the output states that some files can not be found;
Error reading file "XXXXX.ts": File not found
This happens to some files, but if I run tsc.exe giving the exact same path as the error message I get no errors and the file is compiled.
If I rather compile each file in sequence instead:
<Exec Command=""$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript\$(TypeScriptVersion)\tsc" --target ES5 "%(AllTypeScriptFiles.Identity)""
CustomErrorRegularExpression="\.ts\([0-9]+,[0-9]+\):(.*)"
IgnoreExitCode="true" >
</Exec>
All files are compiled without problems, except it takes 5 minutes instead of 10 seconds...
回答1:
Typescript version 0.8.3 solves this problem! No more erros.
I am now able to compile all the files with one go:
<ItemGroup>
<AllTypeScriptFiles Include="XXXXX\Scripts\**\*.ts;" Exclude="XXXX\Scripts\**\*.d.ts;" />
</ItemGroup>
<WriteLinesToFile
File="typescriptcompiler.input"
Lines="@(AllTypeScriptFiles)"
Overwrite="true"
Encoding="Unicode"/>
<Exec Command=""$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript\$(TypeScriptVersion)\tsc" --target ES5 @typescriptcompiler.input"
CustomErrorRegularExpression="\.ts\([0-9]+,[0-9]+\):(.*)">
</Exec>
回答2:
The easiest way to do this is to pick your top level file (for example app.ts) and set an output file on the compiler...
<Target Name="BeforeBuild">
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\$(TypeScriptVersion)\tsc" --out final.js --target ES5 @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
TypeScript will walk all the dependencies and compile it all into final.js.
Note - I recommended this way because you aren't using a --module flag. I would give a different answer for commonjs or amd programs.
I have just changed my TypeScript workflow to use this based on ideas from Mark Rendle.
Alternatively, you can use the following to compile all .ts files...
<ItemGroup>
<TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
</ItemGroup>
<Target Name="BeforeBuild">
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.1.1\tsc" --target ES5 @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
来源:https://stackoverflow.com/questions/14397972/compiling-many-typescript-files-at-once-resulted-in-file-not-found-error