Exclude .js` files but not .min.js files from the MSBuild publication.

Using Visual Studio and MSBuild, I would like to be able to exclude all .js files and include all .min.js in my deployments.

I know this can be achieved using the file properties in visual studio, but this is not an option since there are too many files.




I have the following PublishProfile in my Visual Studio project. Everything works fine except for <ItemGroup>

 <?xml version="1.0" encoding="utf-8"?> <!-- This file is used by the publish/package process of your Web project. You can customize the behavior of this process by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. --> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <WebPublishMethod>FileSystem</WebPublishMethod> <LastUsedBuildConfiguration>Delpoy-Static</LastUsedBuildConfiguration> <LastUsedPlatform>Any CPU</LastUsedPlatform> <SiteUrlToLaunchAfterPublish /> <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> <ExcludeApp_Data>True</ExcludeApp_Data> <publishUrl>\\***\wwwroot\***.com\static</publishUrl> <DeleteExistingFiles>False</DeleteExistingFiles> </PropertyGroup> <!--This does not work, but gives the idea of what I want to achieve--> <ItemGroup> <Deploy Exclude="**\*.js" Include="**\*.min.js" /> </ItemGroup> </Project> 

Can this be done using PublishProfile ? If so, how?

+4
visual-studio build deployment msbuild msdeploy
Aug 27 '14 at 10:48
source share
2 answers
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <WebPublishMethod>FileSystem</WebPublishMethod> <!-- ... --> </PropertyGroup> <Target Name="BeforeBuild"> <ItemGroup> <Minified Include="**\*.min.js" /> <Maxified Include="**\*.js" Exclude="@(Minified)" /> <Content Remove="@(Maxified)" /> </ItemGroup> </Target> </Project> 

Edit:

 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <WebPublishMethod>FileSystem</WebPublishMethod> <!-- ... --> </PropertyGroup> <ItemGroup> <Minified Include="**\*.min.js" /> <Maxified Include="**\*.js" Exclude="@(Minified)" /> </ItemGroup> <PropertyGroup> <ExcludeFoldersFromDeployment>bin</ExcludeFoldersFromDeployment> <ExcludeFilesFromDeployment>@(Maxified);Web.config</ExcludeFilesFromDeployment> </PropertyGroup> </Project> 
+9
Sep 02 '14 at 17:26
source share

If you want to exclude files, you can put the files in the ExcludeFromPackageFiles element group. In your case, you want to take all .js files and exclude everything except *.min.js . To do this, in the .pubxml file, add the following to the .pubxml file.

  <ItemGroup> <ExcludeFromPackageFiles Include="js\**\*.js" Exclude="js\**\*min*.js"> <FromTarget>Project</FromTarget> </ExcludeFromPackageFiles> </ItemGroup> 

Note. This snippet assumes your .js files are in a folder named js .

+3
Sep 09 '14 at 18:18
source share



All Articles