4

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">
shannon
  • 8,664
  • 5
  • 44
  • 74

3 Answers3

4

i had the same problem as you and I solved it using this approach:

  1. Edit the .targets file causing your error (you can find it in the ouput panel)

  2. Paste in node the xml provided in the link :

    <Target Name="CustomExcludeFiles" 
          DependsOnTargets="$(ExcludeFilesFromPackageDependsOn)"
          BeforeTargets="ExcludeFilesFromPackage">
    
    <Message Text="Custom exclude..." Importance="high"></Message>
    <WriteLinesToFile Condition="$(EnablePackageProcessLoggingAndAssert)"
                      Encoding="utf-8"
                      File="$(PackageLogDir)\CustomExcludeFilesBefore.txt"
                      Lines="@(FilesForPackagingFromProject->'
                      From:%(Identity) 
                      DestinationRelativePath:%(DestinationRelativePath) 
                      Exclude:%(Exclude) 
                      FromTarget:%(FromTarget) 
                      Category:%(Category)
                      ProjectFileType:%(ProjectFileType)')" Overwrite="True" />
    
    <ItemGroup>
      <FilesForPackagingFromProject Remove="@(FilesForPackagingFromProject)" Condition="!Exists('%(FullPath)')" />
    </ItemGroup>
    <WriteLinesToFile Condition="$(EnablePackageProcessLoggingAndAssert)"
                      Encoding="utf-8"
                      File="$(PackageLogDir)\CustomExcludeFilesAfter.txt"
                      Lines="@(FilesForPackagingFromProject->'
                      From:%(Identity) 
                      DestinationRelativePath:%(DestinationRelativePath) 
                      Exclude:%(Exclude) 
                      FromTarget:%(FromTarget) \
                      Category:%(Category)
                      ProjectFileType:%(ProjectFileType)')" Overwrite="True"/>
    </Target>
    
    1. Save, restart your Visual Studio and republish
Gregoire
  • 24,219
  • 6
  • 46
  • 73
  • Thank you. I would like to be able to share this project with a team in a manner that allows them to publish with less pain than editing system files; e.g. a patch with an installer, or a change to my project. I'll look at plugging your fix into a project .targets when I get a moment. – shannon May 21 '16 at 18:49
  • 1
    Thanks. This worked great in my case using Visual Studio 2013 and a tsconfig that emits a single javascript file. I just copied the xml into a separate .targets file and imported that in my .csproj using an tag. – MagicMau Dec 22 '16 at 14:29
0

You can exclude files from the package with the following MSBuild snippet:

<ItemGroup>  
  <ExcludeFromPackageFiles Include="Sample.Debug.xml">  
    <FromTarget>Project</FromTarget> 
  </ExcludeFromPackageFiles> 
</ItemGroup> 

Check out Sayed's blog for a full tutorial:

http://sedodream.com/2010/08/15/WebDeploymentToolMSDeployHowToExcludeFilesFromPackageBasedOnConfiguration.aspx

chief7
  • 14,263
  • 14
  • 47
  • 80
  • Have you used that solution? I can't tell due to what are probably just typos if there is a real existing package it is supposed to precede. – shannon May 05 '16 at 01:15
  • actually, the simpler solution will probably work for me and seems error free. will report back. – shannon May 05 '16 at 01:18
  • Yeah, this definitely doesn't work. Tried it a dozen different ways, then did a lot of diagnostics to ensure it was active. The problem is that the file doesn't exist, so excluding it using a glob doesn't exclude it. – shannon May 11 '16 at 03:32
  • If you will create a simple repro solution in GitHub I will troubleshoot it. – chief7 May 11 '16 at 10:50
  • Thanks! It may be simpler to generate than checkout in this case. In the process of reducing the problem to the smallest repro, I found you only need one file: Create a new Visual Studio TypeScript HTML Application, and add the tsconfig.json file shown above. Then Publish (Package will also error in the same way). – shannon May 12 '16 at 03:24
  • If you'd prefer to work with a GitHub project let me know and I'll create one. – shannon May 12 '16 at 03:35
  • Also, I'm thinking now the problem likely is a product defect, and possibly related to changes in VS 2015 Update 2 to better support tsconfig.json. – shannon May 12 '16 at 03:36
  • 1
    I have VS 2015 Update 2 and recreated the scenario but didn't have any problems deploying using the right click publish method. – chief7 May 12 '16 at 10:32
  • Ugh. I have a few other devices I'll check out to and try again. This one is only a month old. – shannon May 12 '16 at 14:20
  • 1
    Wait, did you perhaps build before adding the `tsconfig.json` file? If you have an `app.js` file (it wouldn't be included in the project) that is adjacent to the `app.ts` file, you must delete that to receive the error. – shannon May 12 '16 at 14:22
0

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

MemeDeveloper
  • 6,457
  • 2
  • 42
  • 58