Variable substitution in Deployment.BTDFPROJ for ODBC DSN

Topics: Server Deployment
Sep 19, 2012 at 6:06 PM

We are trying to use the SettingsFileGenerator.xml to do variable substitution within the Deployment.btdfproj file at deployment time to create an ODBC DSN.  Is this possible and if so how is it done?  We have it working with the variables stored in InstallWizard.xml but the issue is that the variables change across environments.  Here is what we have now that works with InstallWizard.xml:

<Target Name="CustomDeployTarget">
    <Exec Command="&quot;%windir%\System32\odbcconf.exe&quot; CONFIGSYSDSN &quot;SQL Anywhere 12&quot; &quot;DSN=$(WCSDSNName)|UID=$(WCSUserID)|PWD=$(WCSPassword)|Host=$(WCSHost)|Port=$(WCSPort)|ServerName=$(WCSServerName)|DatabaseName=$(WCSDatabaseName)&quot;" />
  </Target>

Any help is greatly appreciated.

Regards,

Keith

Sep 20, 2012 at 4:02 AM
Edited Sep 20, 2012 at 4:59 AM

A somewhat brute force mechanism would be to add the .btdfproj file to a <FilesToXMLPreprocess> section and then to add the appropriate XMLPreprocessor directives within the .btdfproj file.  I've also added a target to remove the ODBC DSN during uninstall.  Unfortunately, by modifying the original file you'll run into issues with trying to redeploy with a different settings file since the substitutions have already happened during the first deployment. 

  <ItemGroup>
    <FilesToXmlPreprocess Include="Deployment\Deployment.btdfproj"/>
  </ItemGroup>
  <Target Name="CustomDeployTarget">
    <!-- ifdef ${_xml_preprocess} -->
    <Exec Command="&quot;%windir%\System32\odbcconf.exe&quot; CONFIGSYSDSN &quot;SQL Anywhere 12&quot; &quot;DSN=${WCSDSNName}|UID=${WCSUserID}|PWD=${WCSPassword}|Host=${WCSHost}:${WCSPort}|ServerName=${WCSServerName}|DatabaseName=${WCSDatabaseName}&quot;" />
    <!-- endif -->
  </Target>
  <Target Name="CustomUnDeployTarget">
    <!-- ifdef ${_xml_preprocess} -->
    <Exec Command="reg delete &quot;HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources&quot; /v ${WCSDSNName}" />
    <Exec Command="reg delete &quot;HKLM\SOFTWARE\ODBC\ODBC.INI\${WCSDSNName}&quot;" />
    <!-- endif -->
  </Target>

UPDATE: Unfortunately, it appears that this will fail the first time the deployment is executed.  It seems that the .BTDFPROJ is already in memory and isn't reading the updates made by this proposed solution until after trying to deploy for a second time.
Coordinator
Sep 20, 2012 at 4:55 AM

This is actually very simple.  If you do not already have one, add an ItemGroup with a PropsFromEnvSettings element to your .btdfproj.  Now, list one or more configuration item names (column 1 of the spreadsheet) in the Include attribute value (separated by semicolons, or just add multiple PropsFromEnvSettings elements).

Now each of the named settings will have the current value automatically loaded into a same-named MSBuild property referenced as $(settingname).  [Note, () not {} as in matthewball's post.]

<ItemGroup>
 <PropsFromEnvSettings Include="WCSDSNName;WCSUserID;WCSPassword;WCSHost;WCSPort;WCSServerName;WCSDatabaseName" />
</ItemGroup>

Thanks,
Tom