如何通过 .msi 包修改 machine.config

发布于 2024-07-18 05:17:11 字数 546 浏览 7 评论 0原文

我正在尝试创建一个将部署 .NET 托管数据提供程序的安装程序。 为了使数据提供程序在应用程序下拉列表中显示为提供程序,我必须在 machine.config 部分中添加提供程序:

<system.data>
    <DbProviderFactories>
      <add name="My Data Provider" 
           invariant="Sample.MyDataProvider" 
           description="My Data Provider" 
           type="Eli.Sample.MyDataProvider, Sample.MyDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5b9d34470b87a97f" 
      />
    </DbProviderFactories>
</system.data>

我该如何执行此操作? 只要有一个指针就可以了。 谢谢。

I'm trying to create an installer that will deploy a .NET Managed data provider. In order for the data provider to appear as a provider in application drop-downs, I have to add the provider in the machine.config's section:

<system.data>
    <DbProviderFactories>
      <add name="My Data Provider" 
           invariant="Sample.MyDataProvider" 
           description="My Data Provider" 
           type="Eli.Sample.MyDataProvider, Sample.MyDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5b9d34470b87a97f" 
      />
    </DbProviderFactories>
</system.data>

How do I do this? Just a pointer would be fine. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你不是我要的菜∠ 2024-07-25 05:17:11

如果您使用 Wix,则可以使用 XmlConfig 元素。

<util:XmlConfig 
        Id="Machine_Config_Xml_Root"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        Action="create" 
        On="install"
        ElementPath="//configuration/system.data/DbProviderFactories" 
        Name="add"
        Node="element" 
        Sequence="1"> 
 </util:XmlConfig> 
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="name"
        Value="My Data Provider" 
        Sequence="2"> 
 </util:XmlConfig>
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="invariant"
        Value="Sample.MyDataProvider" 
        Sequence="2"> 
 </util:XmlConfig>
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="description"
        Value="My Data Provider" 
        Sequence="2"> 
 </util:XmlConfig>
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="type"
        Value="Eli.Sample.MyDataProvider, Sample.MyDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5b9d34470b87a97f" 
        Sequence="2"> 
 </util:XmlConfig>

 <util:XmlConfig 
    Id="Machine_Config_Xml_Uninstall_1"
    File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
    Action="delete"
    On="uninstall"
    ElementPath="//configuration/system.data/DbProviderFactories/add[\[]@invariant='Sample.MyDataProvider'[\]]"
    Sequence="1">
 </util:XmlConfig>

If your using Wix you can use the XmlConfig element.

<util:XmlConfig 
        Id="Machine_Config_Xml_Root"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        Action="create" 
        On="install"
        ElementPath="//configuration/system.data/DbProviderFactories" 
        Name="add"
        Node="element" 
        Sequence="1"> 
 </util:XmlConfig> 
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="name"
        Value="My Data Provider" 
        Sequence="2"> 
 </util:XmlConfig>
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="invariant"
        Value="Sample.MyDataProvider" 
        Sequence="2"> 
 </util:XmlConfig>
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="description"
        Value="My Data Provider" 
        Sequence="2"> 
 </util:XmlConfig>
 <util:XmlConfig 
        Id="Machine_Config_Xml_2"
        File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
        ElementPath="Machine_Config_Xml_Root"
        Name="type"
        Value="Eli.Sample.MyDataProvider, Sample.MyDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5b9d34470b87a97f" 
        Sequence="2"> 
 </util:XmlConfig>

 <util:XmlConfig 
    Id="Machine_Config_Xml_Uninstall_1"
    File="[WindowsFolder]Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.Config"
    Action="delete"
    On="uninstall"
    ElementPath="//configuration/system.data/DbProviderFactories/add[\[]@invariant='Sample.MyDataProvider'[\]]"
    Sequence="1">
 </util:XmlConfig>
落叶缤纷 2024-07-25 05:17:11

您需要创建自定义安装程序操作并将其添加到您的 MSI 中以执行此操作(我假设您正在使用 Visual Studio 安装项目来执行此操作)。

You need to create a custom installer action and add it to your MSI to do this (I'm assuming you're using a Visual Studio setup project to do this).

御守 2024-07-25 05:17:11

您可以嵌套 XmlConfig 元素以获得稍微简洁的解决方案。 这就是我使用 WiX 工具集 v3.11 for .NET Framework 4 的效果:

<util:XmlConfig Id="AddElement32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config"
                ElementPath="//configuration/system.data/DbProviderFactories"
                Action="create" On="install" Node="element"
                Name="add">
    <util:XmlConfig Id="NameAttribute32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config" ElementId="AddElement32"
                    Name="name"
                    Value="My Data Provider"
                    />
    <util:XmlConfig Id="InvariantAttribute32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config" ElementId="AddElement32"
                    Name="invariant"
                    Value="Sample.MyDataProvider"
                    />
    <util:XmlConfig Id="DescriptionAttribute32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config" ElementId="AddElement32"
                    Name="description"
                    Value="My Data Provider"
                    />
    <util:XmlConfig Id="TypeAttribute32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config" ElementId="AddElement32"
                    Name="type"
                    Value="Eli.Sample.MyDataProvider, Sample.MyDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5b9d34470b87a97f"
                    />
</util:XmlConfig>

<util:XmlConfig Id="AddElement32Uninstall" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config"
                Action="delete" On="uninstall" Node="element"
                ElementPath="//configuration/system.data/DbProviderFactories"
                VerifyPath="//configuration/system.data/DbProviderFactories/add[\[]@invariant='Sample.MyDataProvider'[\]]"
                />

请注意,虽然您现在可以省略一些属性,因为您正在嵌套元素,但您仍然需要 FileElementId 属性。

卸载 XmlConfig 元素似乎也需要 VerifyPath 属性,以便它可以选择要删除的正确元素。

You can nest the XmlConfig elements for a slightly neater solution. This is what worked for me with WiX toolset v3.11 for .NET Framework 4:

<util:XmlConfig Id="AddElement32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config"
                ElementPath="//configuration/system.data/DbProviderFactories"
                Action="create" On="install" Node="element"
                Name="add">
    <util:XmlConfig Id="NameAttribute32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config" ElementId="AddElement32"
                    Name="name"
                    Value="My Data Provider"
                    />
    <util:XmlConfig Id="InvariantAttribute32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config" ElementId="AddElement32"
                    Name="invariant"
                    Value="Sample.MyDataProvider"
                    />
    <util:XmlConfig Id="DescriptionAttribute32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config" ElementId="AddElement32"
                    Name="description"
                    Value="My Data Provider"
                    />
    <util:XmlConfig Id="TypeAttribute32" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config" ElementId="AddElement32"
                    Name="type"
                    Value="Eli.Sample.MyDataProvider, Sample.MyDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5b9d34470b87a97f"
                    />
</util:XmlConfig>

<util:XmlConfig Id="AddElement32Uninstall" File="[NETFRAMEWORK40FULLINSTALLROOTDIR]Config\Machine.Config"
                Action="delete" On="uninstall" Node="element"
                ElementPath="//configuration/system.data/DbProviderFactories"
                VerifyPath="//configuration/system.data/DbProviderFactories/add[\[]@invariant='Sample.MyDataProvider'[\]]"
                />

Note that although you can now leave out some of the attributes because you're nesting the elements, you still need the File and ElementId attributes.

The uninstall XmlConfig element seems to need the VerifyPath attribute too, so that it can select the correct element to remove.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文