简体   繁体   中英

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">

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM