简体   繁体   English

TeamCity MSBuild,在部署期间重新映射文​​件夹

[英]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. 目前没有使用CI,使用zip文件> _ <手动进行部署,但是我正在设置它,但遇到了一些困难。 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. 该解决方案需要一个App_Config文件夹,该文件夹在根目录中包含该站点的所有配置,但是这些配置不同于每个托管服务器,其中一个是管理服务器,另一个是交付服务器。

Each individual server configurations is stored in a separate folder at /Configs/servername/ containing a web.config file and the App_Config folder. 每个单独的服务器配置都存储在/ Configs / servername /处的单独文件夹中,其中包含web.config文件和App_Config文件夹。 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. 另外,也不希望部署/ Configs /文件夹。

Preferably no changes should have to be done to the Visual Studio solution. 最好不要对Visual Studio解决方案进行任何更改。

Is it possible to automate this before deployment in TeamCity? 在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”

<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.////// ////////最好不必对Visual Studio解决方案进行任何更改。//////

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. 而不是在csproj文件中进行很多有时很难遵循的自定义更改。...使用基本的.msbuild文件。

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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