Reputation: 2518
Although there are several articles on this issue, I can't seem to find any that are recent and apply to ASPNET Core 2.x, Visual Studio 2017.
How do I only publish my minified versions of JavaScript (.js) files?
It would be nice to do this via the publish profile (.pubxml) so that I can include/exclude by setting up different publish profiles (Dev, UAT, Staging, Production.
Upvotes: 4
Views: 2301
Reputation: 86
Just exclude all .css/.js files and then include .min files. The last rule overrides the previous.
<ItemGroup>
<Content Update="wwwroot\**\*.css" CopyToPublishDirectory="never" />
<Content Update="wwwroot\**\*.min.css" CopyToPublishDirectory="always" />
<Content Update="wwwroot\**\*.js" CopyToPublishDirectory="never" />
<Content Update="wwwroot\**\*.min.js" CopyToPublishDirectory="always" />
</ItemGroup>
Upvotes: 7
Reputation: 1
Publish profiles are essentially project file overrides and use the same schema as project files. Microsoft supplies an example here: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-2.2#exclude-files
<ItemGroup>
<Content Update="wwwroot/content/**/*.txt" CopyToPublishDirectory="Never" />
</ItemGroup>
Additionally, you can set any file in your project to be included or excluded based on build configuration directly in the project: Conditional Content Based Upon Configuration
Upvotes: 0