【问题标题】:TeamCity MSBuild, remap folders during deploymentTeamCity MSBuild,在部署期间重新映射文​​件夹
【发布时间】:2013-10-01 12:17:18
【问题描述】:

我们有一个网站项目的解决方案,该项目托管在负载平衡的环境中。目前没有使用 CI,部署是手动使用 zip 文件 >_

每个单独的服务器配置都存储在 /Configs/servername/ 的单独文件夹中,其中包含 web.config 文件和 App_Config 文件夹。这些已从该文件夹手动复制到根目录以覆盖那些已经存在的。 也不需要部署 /Configs/ 文件夹。

最好不要对 Visual Studio 解决方案进行任何更改。

是否可以在部署到 TeamCity 之前自动执行此操作?

问候

【问题讨论】:

  • 您打算使用 webdeploy 来发布您的网站吗?
  • 是的,使用 msbuild 命令进行部署。

标签: deployment msbuild automation continuous-integration teamcity


【解决方案1】:

您可能希望根据计算机名称设置具有不同值的属性。 这是一种交易技巧。

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

您可以设置一个名为

的属性
<ConfigurationSourceFolder>/Configs/MyManagementServer01/</ConfigurationSourceFolder>

或者设置一个“DeploymentType”

<DeploymentType>ManagementServerType</DeploymentType>

您还可以将条件放在“目标”甚至任务上。

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

//////最好不要对 Visual Studio 解决方案进行任何更改。//////

所以这里有一个“一般”的提示。 而不是在 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>

【讨论】:

  • 这些更改是否在我的 Visual Studio 解决方案中的网站项目文件中完成?或者这是如何工作的?
  • 我会创建一个基本的 .msbuild(或 .xml 文件)来调用主 .sln 构建。让我附上我的答案。恕我直言,一个基本的 msbuild“持有人”将为您服务。给我一点时间。
  • 将最底层的代码放在一个名为 MySolution.msbuild 的文件中。然后让 TeamCity(或您拥有的任何“包装器”CI)调用它。如“MsBuild.exe MySolution.msbuild”.. 类似的东西。
  • GranadaCoder,关于管理 MsBuild 工件时的“.msbuild”文件命名约定的一些很好的建议:stackoverflow.com/questions/2007689/…
  • 好的。我的大部分是“.xml”,但标准建议是有意义的。谢谢。
猜你喜欢
  • 1970-01-01
  • 2012-08-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
相关资源
最近更新 更多