Tuesday, September 15, 2015

Updating Path Variables for Advanced Installer

Unfortunately, Advanced Installer does not have great command-line support or API support for Path Variables, therefore, you often have to resort to workarounds to accomplish things that would otherwise be easily possible if Advanced Installer had better command-line or API support.

One such case is when dealing with Path Variables.  If you look at Advanced Installer's command-line for Path Variables, you will notice that there is only support for adding New Path Variables or Deleting Path Variables:

http://www.advancedinstaller.com/user-guide/new-path-variable.html

http://www.advancedinstaller.com/user-guide/delete-path-variable.html

But what if you want to simply update your existing Path Variables stored in your PathVariables.xml file?  Well, unfortunately, there is no solution for that built into Advanced Installer's command-line support!

Therefore, you can use a workaround courtesy of MSBuild and MSBuild Extension Pack as in the following code snippet:
<Target Name="BuildPackageWithPathVars" DependsOnTargets="PrepareNRClaims">
   <Message Text="This is the Advanced Installer Path $(AdvancedInstallerPath)" />
   <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute" File="$(PathVariablesFile)" XPath="/PathVariables/Var[@Name='Published_Dir']" Key="Path" Value="$(PublishFolder)" />
   <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute" File="$(PathVariablesFile)" XPath="/PathVariables/Var[@Name='PackagingFiles_Dir']" Key="Path" Value="$(PackagingFilesDir)" />
   <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute" File="$(PathVariablesFile)" XPath="/PathVariables/Var[@Name='Prerequisites_Dir']" Key="Path" Value="$(PrerequisitesFilesDir)" />
   <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateAttribute" File="$(PathVariablesFile)" XPath="/PathVariables/Var[@Name='PackagingSigning_Dir']" Key="Path" Value="$(CodeSigningDir)" />
   <ItemGroup>
     <BuildArg Include="/rebuild" />
     <BuildArg Include="&quot;$(AdvancedInstallerProjectFilePath)&quot;" />
   </ItemGroup>
   <Exec Command="&quot;$(AdvancedInstallerPath)&quot; /loadpathvars $(PathVariablesFile)" />
   <Message Text="This is the command to be run: &quot;$(AdvancedInstallerPath)&quot; @(BuildArg, ' ')" />
   <Exec Command="&quot;$(AdvancedInstallerPath)&quot; @(BuildArg, ' ')" ContinueOnError="False"  />
 </Target>

 

Once you have loaded the Path Variables into Advanced Installer, you should then be able to successfully build the installation package using the update PathVariables.xml file values!

No comments:

Post a Comment