Ken Smith
Ken Smith

Reputation: 20445

Include uglified files in website publish from Visual Studio

I'm using ASP.NET 4.6 (not 5.0/Core), and because some of the JS libraries I'm interested in are only available via NPM, I'm experimenting with the newish NPM and gulp-based pipelines that MS seems to be recommending. I've mostly managed to get everything working and configured the way that I want, with the caveat that I haven't figured out how to get the resulting minified files published out to the website without checking them into source and including them explicitly in the project. (TypeScript manages to do exactly this, though I've never been entirely clear on how.) And of course, I can always fall back to checking them into source and including them in the project - but I've done that before, in the early days of TypeScript, and I really didn't like it, and it seems like it's not the "right" way to do it.

Any suggestions? Is there a build target or something of that sort that could, say, automatically grab everything from a given specified folder (like the lib folder that ASP.NET Core uses, I think), and publish those?

Upvotes: 1

Views: 451

Answers (1)

Ken Smith
Ken Smith

Reputation: 20445

There's a good description of how to do this here: http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-extra-files.

Short version is that you include this in your .pubxml file(s):

 <Target Name="CustomCollectFiles">
    <ItemGroup>
      <_CustomFiles Include="..\ExtraFiles\**\*" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>

    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>

Just needed to find the right Google keywords ("msbuild publish build targets include other files", if you're interested) to turn it up.

Upvotes: 1

Related Questions