Web Deployment: Exclude Directories Based on Project Configuration Name

I want to remove some image resources depending on which build I release using MsDeploy. I have three builds for different clients, which are a fundamentally different topic and a lot of configuration transformations to properly configure their environment.

I do not want to include image resources for client1 when deploying to client2.

This is used as a reference for my first stumbling blocks in configuring msdeploy, and it works well, but I don’t know which variable to get the configuration name.

In pseudo code: if $configurationName == "client1" exclude dirs gfx/client2 and gfx/client3 if $configurationName == "client2" exclude dirs gfx/client1, gfx/client3 and so on... 

Maybe you can even exclude everything and then include only the one you need?

+4
source share
3 answers

I posted a blog entry about this at http://sedodream.com/2010/08/15/WebDeploymentToolMSDeployHowToExcludeFilesFromPackageBasedOnConfiguration.aspx . Here is a summary:

You use the same approach as in my previous answer ExcludeFromPackageFiles, but you just put a condition on it. Therefore, if you have files under the script folder with "debug" in the file name that you want to exclude from any package that was not created in the debug configuration, how you do it is

 <ItemGroup Condition=" '$(Configuration)'!='Debug' "> <ExcludeFromPackageFiles Include="scripts\**\*debug*" /> </ItemGroup> 

More about my blog, but its a simple mod to the previous approach.

+9
source

Thank you for your responses. I fixed all the time, tried my best to enable assembly and migration for my database (migrator.net), but I cheated and did it through runcommand.

It seemed to me that I am posting the entire deployment process here so that the people who read this post can find out about all my mistakes. The main steps:

  • Web.config is converted to ensure that all settings are correct for each client.
  • Backing up files and web server databases on a production server
  • Exclude all gfx directories for all clients
  • Turn on gfx-dir, which this client needs.
  • Include additional binaries and license files that are not referenced by project compliance
  • Migrating the database to the current version
  • Webdeploy of all new files

Deploy.proj, imported <Import Project="Deploy.csproj" /> in the last line of the web project project project:

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <CopyAllFilesToSingleFolderForPackageDependsOn> ExcludeAllGfx; Client1Backup; Client1Include; Client1Migrate; CollectBinFiles; $(CopyAllFilesToSingleFolderForPackageDependsOn); </CopyAllFilesToSingleFolderForPackageDependsOn> </PropertyGroup> <Target Name="ExcludeAllGfx" BeforeTargets="ExcludeFilesFromPackage"> <ItemGroup> <ExcludeFromPackageFiles Include="gfx\client1\**\*.*"> <FromTarget>Project</FromTarget> </ExcludeFromPackageFiles> <ExcludeFromPackageFiles Include="gfx\client2\**\*.*"> <FromTarget>Project</FromTarget> </ExcludeFromPackageFiles> <ExcludeFromPackageFiles Include="gfx\client3\**\*.*"> <FromTarget>Project</FromTarget> </ExcludeFromPackageFiles> </ItemGroup> <Message Text="ExcludeFromPackageFiles: @(ExcludeFromPackageFiles)" Importance="high" /> </Target> <Target Name="CollectBinFiles"> <ItemGroup> <_CustomFiles Include="..\IncludeBin\Telerik\Telerik.ReportViewer.WebForms.dll" /> <_CustomFiles Include="..\IncludeBin\Telerik\Telerik.Reporting.dll" /> <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)"> <DestinationRelativePath>Bin\%(Filename)%(Extension)</DestinationRelativePath> </FilesForPackagingFromProject> </ItemGroup> </Target> <Target Name="Client1Migrate" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'"> <Exec Command="&quot;..\MigratorProject\Bats\Client1.bat&quot;" ContinueOnError="false" /> </Target> <Target Name="Client1Include" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'"> <ItemGroup> <_CustomFilesClient1 Include="gfx\Client1\**\*.*" Exclude="gfx\Client1\**\.svn\**\*.*"> <FromTarget>Project</FromTarget> </_CustomFilesClient1> <FilesForPackagingFromProject Include="%(_CustomFilesClient1.Identity)"> <DestinationRelativePath>gfx\client1\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath> </FilesForPackagingFromProject> </ItemGroup> </Target> <Target Name="Client1Backup" Condition="'$(Configuration)|$(Platform)' == 'Release Client1|AnyCPU'"> <Exec Command="&quot;C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe&quot; -verb:sync -source:contentPath=&quot;page of client1&quot;,computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass -dest:package=c:\Backups\deployments\client1.zip,computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass" ContinueOnError="false" /> <Exec Command="&quot;C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe&quot; -verb:sync -source:runCommand='C:\Backups\deployments\scripts\backup.cmd client1',waitInterval=20000 -dest:auto,computerName=http://10.8.1.1/MsDeployAgentService2,encryptPassword=pass" ContinueOnError="false" /> </Target> </Project> 

Backup.cmd:

 @echo off sqlcmd -v name=%1 -S . -i "C:\Backups\deployments\scripts\backupdb.sql" C:\Backups\deployments\scripts\stampme "C:\Backups\deployments\%1.zip" 

backupdb.sql:

 DECLARE @name NVARCHAR(50) -- database name DECLARE @path NVARCHAR(256) -- path for backup files DECLARE @fileName NVARCHAR(256) -- filename for backup DECLARE @fileDate NVARCHAR(20) -- used for file name SET @name = '$(name)' SET @path = 'C:\Backups\deployments\' SELECT @fileDate = REPLACE(REPLACE(CONVERT(VARCHAR(50),GETDATE(),120),':','-'), ' ', '@') SET @fileName = @path + @name + '_' + @fileDate + '.BAK' BACKUP DATABASE @name TO DISK = @fileName; 

stampme.bat: http://ss64.com/nt/syntax-stampme.html

Hope someone gets some help and examples from this post.

+5
source

You can extend Sayed examples using the Condition attribute on the ItemGroup and the $(Configuration) property.

eg:.

 <ItemGroup> <Content Include="a.jpeg" Condition=" '$(Configuration)' == 'Client1' " /> </ItemGroup> 
+1
source

All Articles