views:

51

answers:

3

I want to delete some image resources depending on what build I'm releasing using MsDeploy. I have three builds for different clients which are basicly another theme and a lot of configuration transforms to setup their environments correctly.

I don´t want to include the image resources for client1 when deploying to client2.

Been using this as a reference for making my first stumbling steps into customizing msdeploy and it works good but I have no idea what 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...

May be its even possible to exclude all and then include just the one which is needed?

A: 

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

e.g.:

<ItemGroup>
    <Content Include="a.jpeg" Condition=" '$(Configuration)' == 'Client1' " />
</ItemGroup>
Ruben Bartelink
A: 

I have posted an entry on my blog about this at http://sedodream.com/2010/08/15/WebDeploymentToolMSDeployHowToExcludeFilesFromPackageBasedOnConfiguration.aspx. Here is the summary:

You use the same approach as in my previous answer, ExcludeFromPackageFiles but you just put a condition on it. So if you have files under scripts folder with 'debug' in the file name that you want to exclude from any package which not built under debug configuration the way you do it is

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

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

Sayed Ibrahim Hashimi
A: 

Thanks for both your answers. I fixed everything now, struggled alot with including a build and migration for my database (migrator.net) but I cheated and did it through the runcommand instead.

I thought I post my whole deployment process here so people who read this post might learn from all my misstakes. The basic steps are:

  • Web.config transforms to make sure all settings are correct for each of the clients
  • Backup of webserver files and database at the production server
  • Exclude all gfx directories for all clients
  • Include the gfx dir which is wanted by this client
  • Include extra binares and license-files which are not referenced by the project correclty
  • Migrate the database to the current revision
  • Webdeploy all the new files

Deploy.proj, imported by <Import Project="Deploy.csproj" /> at the last line of the webproject project file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    <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 anyone gets some help and examples from this entry.

kiteloop