Install component conditionally in Wix - wix

We have a Wix project for our Installer. Is it possible to check if a file exists?
Basically, for some of our config files, we want to pass in the path of the file that is actually not present in our installer script but pass in the path of the file to a public property on command line.
In this case we want the config file component to use this passed in config file during the installation instead of the default config file.
Is this possible?
I have tried something like this:
<?if FileExist([PORTALCONFIGPATH])?>
<File Id='webConfig' Name='web.config' DiskId='1' Source='[PORTALCONFIGPATH]' KeyPath='yes'/>
<?else?>
<File Id='webConfig' Name='web.config' DiskId='1' Source='web.config' KeyPath='yes'/>
<?endif?>
Someway to check that the passed in file name exists then install the passed in file otherwise use the default file.

The WiX FileSearch, DirectorySearch, Condition, and CopyFile elements are what you are looking to use. Create a property, when executing the msi if the property is set then the DirectorySearch and FileSearch elements will look in the path for that property, setting another property (MYFILEEXISTS for example) then if MYFILEEXISTS CopyFile will run with the path.

Related

How to set value of environment value based on install dir

In a Wix installer xml file, when creating an environment variable, how can I set the value of the env var based on the install directory that the user selected?
Currently, I have something like this, and the part I'm missing is ???:
<Component Id='CompId' Guid='xxx'>
<File Id='ProgramEXE' Name='foo.exe' DiskId='1' Source='foo.exe' KeyPath='yes' />
<Environment Id='FooInstall' Action='set' Name='FOO_INSTALL' Value='???'/>
</Component>
The Environment table's Value column is of type Formatted. Directory table entries become properties during CostFinalize so therefore you can just say [DIRECTORYNAME] such as [INSTALLLOCATION].

How to rename a file after install to a dynamic name with WIX?

What I want do is the follow:
<Component ...>
<File Id="xyz" Name="[SERVICE].exe" Source="..\prunmgr.exe">
</Component>
But name does not accept place holder properties. How can I rename the exe file to a dynamic file on installing?
My bad workaround are 2 CustomActions with a command shell. One after InstallFiles rename the file. And a second delete the file before InstallFiles.

No environment variable set after installation of MSI generated by WIX

My WSX file looks like this: https://gist.github.com/pyeremenko/891eceb779197e4be240#file-sample-wxs-L23-L25
Copying works fine, i.e. exe file available in Program Files/test/my_test folder, but I can't access TEST env variable after installation via echo %test% (of course I reload cmd)
I tried also to look for it in System Properties > Environment Variables, but there is no such var there
What should I do to make MSI register env variable?
Building the above WSX file with WIX 3.9 produces these errors:
Product.wxs(23,0): error LGHT0204: ICE18: KeyPath for Component: 'EnvVariable' is Directory: 'INSTALLDIR'. The Directory/Component pair must be listed in the CreateFolders table.
Product.wxs(23,0): error LGHT0204: ICE21: Component: 'EnvVariable' does not belong to any Feature.
To get installed, the component EnvVariable needs to be associated with a feature. Try combining <Environment...> with <File...> into a single component:
<Component Id='MainExecutable' Guid='77777777-8888-4fb0-892f-d62579f11b8d'>
<File Id='my_testexe' Name='hello.exe' DiskId='1' Source='D:\Robert\Documents\Visual Studio 2013\Projects\SetupProject1\Release\ConsoleApplication1.exe' KeyPath='yes' />
<Environment Id='UpdateTest' Name='TEST' Action='set' Permanent='yes' System='yes' Part='all' Value='TestTestTest' />
</Component>
Remove the now empty component <Component Id='EnvVariable'...>.
If you still have problems, you could try running the installer with diagnostic logging:
msiexec /l*v Install.log /i InstallPackage.msi
Search the file Install.log for MainExecutable to see how the component is being installed.

How to declare virtual path in .wxs file?

I am quite new in creating setup project using .wxs file.I am using WIX 3.9. I want to change the physical path to virtual path in .wxs file.
Currently .wsx file is using physical path like this -
<Component Id="cmp2CB74B07C01493F593A258BAE09C0B1C" Guid="08CD4620-DE67-4C7A-A97A-212AB5BA5E52">
<File Id="filCF6108D60D7B1865907043E2ABFE30DF" KeyPath="yes" Source="C:\ProjectName\Client\Bin\AjaxControlToolkit.dll" />
</Component>
I want to use virtual path something like this -
<Component Id="cmp2CB74B07C01493F593A258BAE09C0B1C" Guid="08CD4620-DE67-4C7A-A97A-212AB5BA5E52">
<File Id="filCF6108D60D7B1865907043E2ABFE30DF" KeyPath="yes" Source="~\ProjectName\Client\Bin\AjaxControlToolkit.dll" />
</Component>
How could I do this in .wxs file? Please suggest.
Assuming you are already using heat to generate your components, you can specify a variable by using -var <VariableName>. According to the docs this will:
Substitute File/#Source="SourceDir" with a preprocessor or a wix variable (e.g. -var var.MySource will become File/#Source="$(var.MySource)\myfile.txt" and -var wix.MySource will become File/#Source="!(wix.MySource)\myfile.txt".
I use this by running the heat command in the post-build event of the original project, and passing in -var var.$(ProjectName).TargetDir. The resulting File will have Source="$(var.ProjectName.TargetDir)\whatever.dll". As long as ProjectName is added as a reference to the wix setup project then the variable will be resolved properly.

Setting permissions for folder and all sub folders in Wix

All of the relevant links seem to assume that I am using DirectoryRefs and CreateFolder within these. When I run heat I get a .wxs file that consists of <Directory> tags and <Component> tags but not DirectoryRefs. I'd rather not rewrite the whole 5000 line file by hand. Is there a way to edit folder permissions for these tags?
You don't have to rewrite the heat auto-generated fragment. You can reference the directories defined there with the DirectoryRef elements in another fragment.
Most likely you'd like to do the following:
First, change the ID of the root directory in a heat-generated fragment. This can be done by a -dr <DirectoryName> command line switch of heat.exe. Choose a name for the DirectoryName, e.g. MY_ROOT_FOLDER. This is necessary for a convenient reference to that directory in a DirectoryRef element
Next, author a special component (in a different fragment), which is to contain the permissions functionality only. Something like this:
<DirectoryRef Id="MY_ROOT_FOLDER">
<Component DiskId="1" Id="Permissions" Guid="GUID-GOES-HERE">
<Condition>...</Condition>
<CreateFolder>
<util:PermissionEx GenericAll="yes" User="[LOGON_ACCOUNT]" Domain="[LOGON_DOMAIN]" />
</CreateFolder>
</Component>
</DirectoryRef>
Finally, don't forget to include this component to a feature of your choice.
Note, that by default the <util:PermissionEx> element appends permissions to the folder in question and all its descendants.