views:

881

answers:

2

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.

A: 

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

Adam Robinson
+1  A: 

If your using Wix you can use the XmlFile 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>
Shay Erlichmen