针对项目上下文的VS 2010解决方案配置构建 [英] VS 2010 Solution Configuration build for a project context

查看:73
本文介绍了针对项目上下文的VS 2010解决方案配置构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含30多个项目的Visual Studio解决方案.有2个构建配置,调试"和发布".十个项目文件( .csproj )是使用外部工具合理频繁地生成的,并且该生成的模板包括Debug和Release配置.修改模板以包括其他配置实际上不是一个选择.

I have a Visual Studio solution containing 30+ projects. There are 2 build configurations, Debug and Release. Ten of the project files (.csproj) are generated reasonably frequently using an external tool and the templates for that generation include the Debug and Release configurations. Modifying the templates to include additional configurations is not really an option.

所以我的问题是我有一个托管在AppFabric/IIS中的新项目.我正在使用Web.Config转换来更新Web.Config,以将其部署到4个不同的环境中:开发,测试,登台,生产.我已经使用配置管理器将这些上下文添加到特定项目中.那行得通,所以我可以例如更新Configuration Manager.发布版本以使用项目的生产上下文.右键单击并为该项目构建部署包,将导致将适当的转换应用于Web.Config.

So the problem I have is that I have a new project that is hosted in AppFabric/IIS. I'm using Web.Config transformations to update the Web.Config for deployment to 4 different environments: Development, Test, Staging, Production. I've add those contexts to the specific project using the Configuration Manager. That works so I can update the Configuration Manager for e.g. the Release build to use the Production context for the project. Right-clicking and building a deployment package for the project results in the appropriate transformation being applied to the Web.Config.

现在,我想自动化该过程,因此我有一个MSBuild脚本:

Now I want to automate the process so I have an MSBuild script:

<ItemGroup>
    <BuildMode Include="Dev"/>
    <BuildMode Include="Test"/>
    <BuildMode Include="Staging"/>
    <BuildMode Include="Prod"/>
</ItemGroup>

<Target Name="Build" DependsOnTargets="Package"></Target>

<!--
  Build deployment package for each target environment
-->
<Target Name="Package" Outputs="%(BuildMode.Identity)">
    <Message Text="Building %(BuildMode.Identity)"/>
    <MSBuild Projects="..\SynchWorkflow\SynchWorkflow.csproj"
        Targets="Package"
        Properties="Platform=AnyCPU;Configuration=%(BuildMode.Identity);"/>
</Target>

不幸的是,此错误是因为它正在尝试构建例如 Prod 配置(不存在时)- Prod 只是SynchWorkflow项目的上下文.我想做的是使用 Release 配置生成的 Prod 上下文包.使用 MSBuild 任务有可能吗?我可以在 Properties 属性中为 MSBuild 任务提供额外的设置吗?

Unfortunately this errors because it is trying to build e.g. a Prod configuration when it doesn't exist - Prod is only a context for the SynchWorkflow project. What I want to do is have the Prod context package generated using the Release configuration. Is that possible using the MSBuild task? Is there an extra setting I can provide to the MSBuild task in the Properties attribute that would allow this?

推荐答案

我为每个环境添加了新的解决方案配置(不添加新的项目配置),然后使用Configuration Manager将上下文设置为 Release 对于依赖项目.不幸的是,这不起作用,因为MSBuild任务是针对项目文件而不是针对解决方案而构建的.使用 Julien Hoarau的SO答案解决.添加新的解决方案配置是正确的方法,但是链接的答案对我来说是一个循环.构建脚本已更新为以下内容:

I added new solution configurations for each environment (without adding new project configurations) and then used Configuration Manager to set the contexts to Release for the dependent projects. Unfortunately this didn't work because the MSBuild task was building against the project file and not the solution. Resolved using Julien Hoarau's SO answer. Adding the new solution configurations was the correct approach but the linked answer closed the loop for me. The build script has been updated to the following:

  <ItemGroup>
    <BuildMode Include="Development"/>
    <BuildMode Include="Test"/>
    <BuildMode Include="Staging"/>
    <BuildMode Include="Production"/>
  </ItemGroup>
  <PropertyGroup>
    <PackageLocation>$(MSBuildProjectDirectory)</PackageLocation>
  </PropertyGroup>

  <Target Name="Build" DependsOnTargets="Package"></Target>

  <!--
    Build deployment package for each target environment
  -->
  <Target Name="Package" Outputs="%(BuildMode.Identity)">
    <Message Text="Building %(BuildMode.Identity)"/>

    <MSBuild Projects="..\SynchWorkflow.sln"
       Properties="Platform=Any CPU;
                   Configuration=%(BuildMode.Identity);
                   DeployOnBuild=true;
                   DeployTarget=Package;
                   PackageLocation=$(PackageLocation)\SynchWorkflow.%(BuildMode.Identity)Package.zip;"/>
  </Target>

该脚本根据解决方案文件构建,并为每个目标环境生成正确的程序包.出于示例脚本的目的,我在 MSBuildProjectDirectory 中创建了一些次优的包.

The script builds against the solution file and generates the correct package for each target environment. For the purposes of the example script I'm creating the packages in the MSBuildProjectDirectory which is a bit suboptimal.

这篇关于针对项目上下文的VS 2010解决方案配置构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆