如何部署不同的App.config值(使用WiX) [英] How to deploy different App.config values (with WiX)

查看:76
本文介绍了如何部署不同的App.config值(使用WiX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找关于如何使用WiX安装程序针对其App.config文件中的不同值部署应用程序的最佳实践建议.例如.

在本地开发计算机上,我将App.config设置用于我们的测试环境:

<configuration>
    <appSettings>
        <WorkingDirectory>C:\Working</WorkingDirectory>
    </appSettings>
    <connectionStrings>
        <add name="ApplicationEntities" 
             connectionString="[TestingConnectionString]" 
             providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>

当我部署到测试环境时,这些设置是可以接受的.但是,当我们部署到生产环境时,我希望它们有所不同.例如:

<configuration>
    <appSettings>
        <WorkingDirectory>\\prodserver\Working</WorkingDirectory>
    </appSettings>
    <connectionStrings>
        <add name="ApplicationEntities" 
             connectionString="[ProductionConnectionString]" 
             providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>

我的问题的答案很可能独立于WiX.但是以防万一,这是我的WiX Product.wxs文件的相关片段:

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
        <Component Id="ProductComponent" Guid="{MY-GUID}">    
            <File Id="Application.exe"
                  Name="Application.exe"
                  Source="..\Application.exe"
                  Vital="yes"
                  KeyPath="yes"
                  DiskId="1" />
            <File Id="Application.exe.config"
                  Name="Application.exe.config"
                  Source="..\Application.exe.config"
                  Vital="yes"
                  KeyPath="no"
                  DiskId="1" />
        </Component>
    </ComponentGroup>
</Fragment>

此设置以在生产服务器上手动编辑App.config结束,这会导致手动错误.有什么更好的方法来处理此问题以适应自动化部署?

解决方案

我可以想到两个选择,要么部署app.config文件,然后使用 ICE30 验证错误,此后通过复制文件可以避免此错误.

还要注意,我有一个与组件相关的条件,您需要确定如何确定要部署到的环境.一些想法可能是使用计算机名称,OU,或者只是将其作为属性传递给命令行.

<Component Id="development.app.config" Guid="*">

    <Condition>DEVELOPMENT</Condition>
    <File Name="development.app.config" KeyPath="yes">
        <CopyFile Id="development.app.config" DestinationName="app.config" />
    </File>

    <util:XmlFile
        Id="WorkingDirectory"
        Action="setValue"
        File="app.config"
        ElementPath="/configuration/appSettings"
        Name="WorkingDirectory"
        Value="C:\Working"
        Permanent="no" />

</Component>

<Component Id="production.app.config" Guid="*">

    <Condition>PRODUCTION</Condition>
    <File Name="production.app.config" KeyPath="yes">
        <CopyFile Id="production.app.config" DestinationName="app.config" />
    </File>

    <util:XmlFile
        Id="WorkingDirectory"
        Action="setValue"
        File="app.config"
        ElementPath="/configuration/appSettings"
        Name="WorkingDirectory"
        Value="\\prodserver\Working"
        Permanent="no" />

</Component>

I've been looking for a best practice recommendation on how to deploy an application with a WiX installer for different values in its App.config file. For example.

On my local development machine, I use App.config settings for our test environment:

<configuration>
    <appSettings>
        <WorkingDirectory>C:\Working</WorkingDirectory>
    </appSettings>
    <connectionStrings>
        <add name="ApplicationEntities" 
             connectionString="[TestingConnectionString]" 
             providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>

When I deploy to a test environment, those settings are acceptable. However, when we deploy to a production environment, I'd like them to be different. For example:

<configuration>
    <appSettings>
        <WorkingDirectory>\\prodserver\Working</WorkingDirectory>
    </appSettings>
    <connectionStrings>
        <add name="ApplicationEntities" 
             connectionString="[ProductionConnectionString]" 
             providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>

The answer to my question may very well be independent of WiX. But just in case, here is my WiX Product.wxs file's relavent fragment:

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
        <Component Id="ProductComponent" Guid="{MY-GUID}">    
            <File Id="Application.exe"
                  Name="Application.exe"
                  Source="..\Application.exe"
                  Vital="yes"
                  KeyPath="yes"
                  DiskId="1" />
            <File Id="Application.exe.config"
                  Name="Application.exe.config"
                  Source="..\Application.exe.config"
                  Vital="yes"
                  KeyPath="no"
                  DiskId="1" />
        </Component>
    </ComponentGroup>
</Fragment>

This setup ends with a manual edit of the App.config on the production server, which invites manual error. What would be a better way to handle this to accommodate an automated deployment?

解决方案

I can think of two options, either deploy the app.config file and edit it using the XmlFile Element, or maintain multiple app.config files each representing your target environment, then deploy the appropriate file.

Here's an exmaple of both options, notice that I copy the file rather than just placing it on the file system. This serves two purposes, firstly you can see by the filename which one has been deployed, secondly if development.app.config and production.app.config are placed in the same location you will get an ICE30 validation error, by copying the file afterwards it avoids this error.

Notice also that I have a condition associated with the component, you'll need to decide how you identify which environment you are deploying to. Some ideas could be to use the machine name, the OU or simply pass it in on the command line as a property.

<Component Id="development.app.config" Guid="*">

    <Condition>DEVELOPMENT</Condition>
    <File Name="development.app.config" KeyPath="yes">
        <CopyFile Id="development.app.config" DestinationName="app.config" />
    </File>

    <util:XmlFile
        Id="WorkingDirectory"
        Action="setValue"
        File="app.config"
        ElementPath="/configuration/appSettings"
        Name="WorkingDirectory"
        Value="C:\Working"
        Permanent="no" />

</Component>

<Component Id="production.app.config" Guid="*">

    <Condition>PRODUCTION</Condition>
    <File Name="production.app.config" KeyPath="yes">
        <CopyFile Id="production.app.config" DestinationName="app.config" />
    </File>

    <util:XmlFile
        Id="WorkingDirectory"
        Action="setValue"
        File="app.config"
        ElementPath="/configuration/appSettings"
        Name="WorkingDirectory"
        Value="\\prodserver\Working"
        Permanent="no" />

</Component>

这篇关于如何部署不同的App.config值(使用WiX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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