简体   繁体   中英

TeamCity MSBuild, remap folders during deployment

We have a solution with a website project which is hosted on a load balanced environment. At the moment no CI is being used, and deployments are manual using zip-files >_< however I'm looking on setting it up, and have run into some difficulties. The solution requires a App_Config folder containing all the configurations for the site in the root, however these configurations differ from each of the hostingserver, where one is the management server and another is the delivery server.

Each individual server configurations is stored in a separate folder at /Configs/servername/ containing a web.config file and the App_Config folder. These have been manually copied from this folder to the root to overwrite those that already existed. Also deployment of the /Configs/ folder is not wanted.

Preferably no changes should have to be done to the Visual Studio solution.

Is it possible to automate this before deployment in TeamCity?

regards

You may want to set properties with different values based on the computer name. That's one trick of the trade.

<Choose>
    <When Condition=" '$(Computername)'=='MyManagementServer01' ">               
        <PropertyGroup>
            <MyCustomProperty001>Red</MyCustomProperty001>
            <MyCustomProperty002>Yellow</MyCustomProperty002>
        </PropertyGroup>
    </When>

    <When Condition=" '$(Computername)'=='MyDeliveryServer01' ">

        <PropertyGroup>
            <MyCustomProperty001>Black</MyCustomProperty001>
            <MyCustomProperty002>White</MyCustomProperty002>
        </PropertyGroup>

    </When>

    <Otherwise>

        <PropertyGroup>
            <MyCustomProperty001>NoMatchMyCustomProperty001</MyCustomProperty001>
            <MyCustomProperty002>NoMatchMyCustomProperty002</MyCustomProperty002>
        </PropertyGroup>        

    </Otherwise>

</Choose>

You could setup a property called

<ConfigurationSourceFolder>/Configs/MyManagementServer01/</ConfigurationSourceFolder>

Or setup a "DeploymentType"

<DeploymentType>ManagementServerType</DeploymentType>

You can also put Conditions on "Targets" and even Tasks.

<MakeDir Directories="C:\MyCoolDirectory" Condition="('$(MyCustomProperty001)'!='')"/>

//////Preferably no changes should have to be done to the Visual Studio solution.//////

So here is an "in-general" tip. Instead of putting alot of custom sometimes-hard-to-follow changes in the csproj files....use a basic .msbuild file.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
    <PropertyGroup>
        <!-- Always declare some kind of "base directory" and then work off of that in the majority of cases  -->
        <WorkingCheckout>.</WorkingCheckout>
    </PropertyGroup>

    <Target Name="AllTargetsWrapped">

        <CallTarget Targets="BuildItUp" />

    </Target>


    <Target Name="BuildItUp" >
        <MSBuild Projects="$(WorkingCheckout)\MySolution.sln" Targets="Build" Properties="Configuration=$(Configuration)">
            <Output TaskParameter="TargetOutputs" ItemName="TargetOutputsItemName"/>
        </MSBuild>
        <Message Text="BuildItUp completed" />
    </Target>

</Project>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM