Last active
January 21, 2016 12:28
-
-
Save chilversc/36669492c61b91b52b3b to your computer and use it in GitHub Desktop.
Target to remove old typescript output files after msbuild. This will remove all javascript files found in the typescript output directory that were not generated by typescript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Target Name="TypeScriptCleanOldOutput" DependsOnTargets="PreComputeCompileTypeScript" AfterTargets="Clean;Build" Condition=" '$(TypeScriptOutDir)' != '' "> | |
<!-- | |
Assumes the TypeScriptOutDir only contains generated code. | |
If a TypeScript file is deleted from the project the old js file | |
will remain in the output folder. | |
Find JS files in the output folder that were not generated by | |
TypeScript and delete them. | |
--> | |
<ConvertToAbsolutePath Paths="$(TypeScriptOutDir)"> | |
<Output TaskParameter="AbsolutePaths" PropertyName="TypeScriptOutDirAbsolute"/> | |
</ConvertToAbsolutePath> | |
<PropertyGroup> | |
<TypeScriptOutDirAbsolute Condition="!HasTrailingSlash('$(TypeScriptOutDirAbsolute)')">$(TypeScriptOutDirAbsolute)\</TypeScriptOutDirAbsolute> | |
</PropertyGroup> | |
<ItemGroup> | |
<OldGeneratedJavascript Include="$(TypeScriptOutDirAbsolute)**\*.js" Exclude="@(GeneratedJavascript)" /> | |
<OldGeneratedJavascript Include="$(TypeScriptOutDirAbsolute)**\*.js.map" Exclude="@(GeneratedJavascript)" /> | |
</ItemGroup> | |
<Delete Files="@(OldGeneratedJavascript)" /> | |
</Target> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[System.IO.Path]::GetFullPath
can error in VS2015 because the current working directory in msbuild wasC:\Windows\System32
.GetFullPath
resolves relative to the working directory rather than the project directory. UsingConvertToAbsolutePath
instead.