This project is read-only.

integration with wix

Apr 30, 2013 at 9:50 PM
Hi Loren,

I have integrated XMLPreprocess with wix. I have a custom action which calls a cmd file where we do the actual preprocessing.
    <CustomAction Id="ConfigureApp_Cmd" Property="ConfigureApp" Execute="immediate"
        Value="&quot;[INSDIR]\Ed.Assets.Web\Environments\ConfigureWeb.cmd&quot; &quot;[ENVIRONMENT]&quot; nopause;" />
    <CustomAction Id="ConfigureApp" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no"/>
The construct of ConfigureWeb.cmd is pretty simple
@echo off
@echo Configuring the config files
call XmlPreprocess.exe /v /q /nologo /i appSettings.config /x EAP.EnvironmentSettings.xml /e %1 /clean /o ../appSettings.config
call XmlPreprocess.exe /v /q /nologo /i authentication.config /x EAP.EnvironmentSettings.xml /e %1 /clean /o ../authentication.config
call XmlPreprocess.exe /v /q /nologo /i connectionStrings.config /x EAP.EnvironmentSettings.xml /e %1 /clean /o ../connectionStrings.config
@echo on
When I invoke the installer via the commandline by passing ENVIRONMENT=Test1 I get the error message:
CAQuietExec:  Configuring the config files
CAQuietExec:  Error XMLPP101: Settings data source not found: "EAP.EnvironmentSettings.xml"
CAQuietExec:  Error XMLPP101: Settings data source not found: "EAP.EnvironmentSettings.xml"
MSI (s) (A0:F4) [15:29:41:816]: Executing op: ActionStart(Name=RegisterProduct,Description=Registering product,Template=[1])
CAQuietExec:  Error XMLPP101: Settings data source not found: "EAP.EnvironmentSettings.xml"
However when I execute the cmd file: "ConfigureWeb.cmd Test1" from the commandline, the files are preprocessed.

What am I missing?
May 1, 2013 at 2:56 PM
Hi Sourav,

I think the issue is with the current directory when running from the custom action. Try adding "pushd %~dp0" toward the beginning of your batch file. It looks weird, but it's one way to make sure the batch file runs with a current directory set to the directory in which it sits so all relative paths will be right.

@echo off
@echo Configuring the config files
pushd %~dp0
call XmlPreprocess.exe /v /q /nologo /i appSettings.config /x EAP.EnvironmentSettings.xml /e %1 /clean /o ../appSettings.config
call XmlPreprocess.exe /v /q /nologo /i authentication.config /x EAP.EnvironmentSettings.xml /e %1 /clean /o ../authentication.config
call XmlPreprocess.exe /v /q /nologo /i connectionStrings.config /x EAP.EnvironmentSettings.xml /e %1 /clean /o ../connectionStrings.config
@echo on

Also, it's always good to have XmlPreprocess be the last line in the batch file so that if an error is returned by the preprocessor, it gets noticed by the custom action, otherwise, subsequent lines in your batch file may reset the error level.

With that in mind, have you considered preprocessing all 3 files in one pass? I see you are not preprocessing in place, so unfortunately you can't use wildcards, but something like this works:

@echo off
echo Configuring the config files
pushd %~dp0
XmlPreprocess.exe /v /q /nologo /i appSettings.config;authentication.config;connectionStrings.config /x EAP.EnvironmentSettings.xml /e %1 /clean /o ..\appSettings.config;..\authentication.config;..\connectionStrings.config

Finally, have you looked at using CAQuietExec (see wixsetup2.wxs)? It will prevent a console from flashing up during install, and make sure everything from the batch file gets logged into the MSI log.
May 1, 2013 at 5:34 PM
Loren,
That did it!
pushd %~dp0
I have dropped all the config preprocessing to a single call of XmlPreprocess.exe and it works just fine.

I've not had a look at CAQuitExec yet, will do that once I fix the installers :)

Thank you so much Loren!
May 2, 2013 at 2:04 PM
Sourav,

I'm so glad it helped. The other recommendation is to always pass /f (or /fixFalse). It will save you some frustration if you ever have any replacement values with the value of "false" down the line. The behavior of false is one of my biggest regrets with the original version of the preprocessor and for backward compatibility I have never dared change it so /fixFalse is the default. It doesn't hurt anything to pass /f all the time, you just need to use a value of #undef to undefine a property instead of false (undefining a property is hardly ever done anyway).
Jun 5, 2013 at 5:41 PM
Hi Loren,
Earlier I did not think that I would require the /f feature, but yesterday I had an instance when a variable's default is set to false and based on the environment the value changes to true. Your preemptive suggestion saved me precious time. Thank you once again for that.

I did come across something unexpected though. I'm not sure if I was doing things the right way. I realized that if <!-- #ifdef _xml_preprocess -->is the first statement in a config file the preprocessing does not work:
<!-- #ifdef _xml_preprocess -->
<!--  
<compilation debug="${mode}" />
-->
<!-- #else -->
<compilation debug="false" />
<!-- #endif -->
But if I just place a comment before that then its all fine. Something like this:
<!--starting-->
<!-- #ifdef _xml_preprocess -->
<!--  
<compilation debug="${mode}" />
-->
<!-- #else -->
<compilation debug="false" />
<!-- #endif -->
The point is, there is no .error also being generated, the file is just being ignored for preprocessing. I am good with placing a comment as the first line, but just wanted to know if this was expected behavior.