visual-studiotypescriptmsdeployone-click-web-publishing

Exclude transpiled/non-existent .JS files from TypeScript Web Publish


While trying to web publish a TypeScript project in Visual Studio 2015, Update 2; the build succeeds, but the Package/Publish fails at:

Error: Copying file typescript-filename.js to obj\Release\Package\PackageTmp\typescript-filename.js failed. Could not find file 'typescript-filename.js'.

The error appears when the project specifies a directory for TypeScript intermediate/output files. To reproduce this error, simply create a tsconfig.json file in the root of a new Visual Studio TypeScript HTML Application project, with the following contents:

{
    "compilerOptions": {
        "outDir": "transpiled"
    }
}

If don't use the outDir intermediate/output directory option, I get my source files published, which I do not want. (Also the project output gets mixed in with source, and the project becomes a mess.)

How can I exclude these TypeScript transpiled files from the Package/Publish?

Since I run WebPack to create separate deployable .JS bundle files (which are included in my project and perform package/publish successfully), I actually don't want any of these transpiled files included anyway.


Additional research:

I've already tried excluding the .TS source in the Solution Explorer, setting it to None/Do not copy. But here's the really strange thing about that:

ANY change between "None" and "TypeScript Compile" (setting OR unsetting) on a .TS file in my project will allow my project to publish to the server successfully, and none of the transpiled .TS/.JS files are deployed; but only until I've made another change that requires the project to build again. Then the missing .JS file error reappears.

So, effectively, I have some voodoo I can perform to force a publish, but I'd still really like to fix this problem.

Somehow, C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Transform\Microsoft.Web.Publishing.AspNetCompileMerge.targets reaches line 615 with a list of files that (AFAIK) never existed at any time during the build or packaging process, in the variable @(FilesForPackagingFromProject). It's as though one of the targets does a direct replacement of any .TS extension with .JS if it just ran the build, but without regard to what actually happened in the build.

<CopyPipelineFiles PipelineItems="@(FilesForPackagingFromProject)"
                       SourceDirectory="$(WebPublishPipelineProjectDirectory)"
                       TargetDirectory="$(_PreAspnetCompileMergeSingleTargetFolder)"
                       SkipMetadataExcludeTrueItems="True"
                       UpdateItemSpec="True"
                       DeleteItemsMarkAsExcludeTrue ="True">

Solution

  • I had the same issue. I upgraded my TypeScript tools for Visual Studio to 2.1.4 and now it's all good.

    https://www.microsoft.com/en-us/download/details.aspx?id=48593