代码之家  ›  专栏  ›  技术社区  ›  roufamatic RichardJohnn

自动VS2010“发布”配置文件替换

  •  7
  • roufamatic RichardJohnn  · 技术社区  · 15 年前

    我正在使用visualstudio2010的“发布”功能的配置文件替换特性,如前所述 in this article

    我喜欢它的工作方式,但如果我不能自动化它,我将不得不切换到XmlMassUpdate或类似的。

    3 回复  |  直到 15 年前
        1
  •  5
  •   Julien Hoarau    15 年前

    解释

    要转换配置文件,必须执行 TransformWebConfig 目标。

    Web.config Web.$(Configuration).config Web.config文件

    此文件在以下文件夹中生成: obj\$(Configuration)\TransformWebConfig

    用法

    您并没有真正解释您想要实现什么,所以这里有一个基本用法,一个在给定文件夹中生成转换的配置文件的作业。

    在项目文件的末尾添加以下内容 *.csproj Microsoft.WebApplication.targets

    <PropertyGroup>
      <!-- Directory where your web.config will be copied -->
      <TransformedWebConfigDestination>$(MSBuildProjectDirectory)</TransformedWebConfigDestination>
    </PropertyGroup>
    
    <!--
      This target transforms the web.config based on current configuration and
      put the transformed files in $(TransformedWebConfigDestination) folder
    -->
    <Target Name="ConfigSubstitution">
      <CallTarget Targets="TransformWebConfig"/>
    
      <ItemGroup>
        <TransformedWebConfig Include="obj\$(Configuration)\TransformWebConfig\Web.config"/>
      </ItemGroup>
    
      <!-- Copy the transformed web.config to the configured destination -->
      <Copy SourceFiles="@(TransformedWebConfig)"
            DestinationFolder="$(TransformedWebConfigDestination)"/>
    </Target>
    

    您可以在生成中添加生成步骤,或创建一个配置如下的专用作业:

    • MsBuild生成文件: Your csproj file.
    • 命令行参数: /t:ConfigSubstitution /p:Platform=AnyCpu;Configuration=Test;TransformedWebConfigDestination=DestinationFolder
        2
  •  3
  •   Lukie    15 年前

    编辑您的web project.csproj

    在下面

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    


    <UseMsDeployExe>True</UseMsDeployExe>

    查看构建输出(确保VS Tools-Options-Project&解决方案-构建和;Run-MSBuild输出详细信息)

    您应该能够看到msdeploy命令VS用于生成包。据我所知,在使用MSBuild构建时,VS实际上使用Web平台管道API和.target文件来实际生成部署包,并且此命令改为使用MsDeploy。

    这些东西非常需要文档,非常令人沮丧。

        3
  •  1
  •   Cymen    15 年前

    /Property:Configuration=Release
    

    具体设置如下:

    Build
    MSBuild Version: msbuild-4 (configured to point to v4 msbuild)
    MsBuild Build File: project_name.sln
    Command Line Arguments: /Property:Configuration=Release
    

    您可以在项目目录中通过运行与以下类似的程序(因为您的.NET framework版本可能有所不同)对此进行测试:

    %SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319\msbuild project.sln /Property:Configuration=Release