WIX cannot find app.exe in x86/x64 output directory - wix

I have a C# application which its build targets are x86 or x64. The build output is (for example) ProjectDir/bin/x86|x64/Debug|Release/*
In my *.wxs file I have defined thr following variable
<?define AppTargetPath = "$(var.MyApp.TargetPath)" ?>
Which points to ProjectDir/bin/Debug|Release/app.exe
If I build the installer, it fails because it does not find my app exe
<File Id="AppExe" Source="$(var.AppTargetPath)" KeyPath="yes"/>
If I look on Using Project References and Variables site (http://wixtoolset.org/documentation/manual/v3/votive/votive_project_references.html) I cannot find another variable.

Maybe try this:
Comment out your existing define.
Add the project building the EXE and your WiX project to the same solution.
Add a reference from the WiX project to the EXE / Binary project.
Try this markup (replace project name "TestConsoleApplication" with yours):
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component>
<File Source="$(var.TestConsoleApplication.TargetPath)" />
</Component>
</ComponentGroup>
</Fragment>
Rebuild All.
Toggle Release and Debug builds, then Rebuild All again.
Links:
Summary: My WiX Quick Start Tips.
Basic WiX Project: Step-by-step, Hello WiX project.
Real-World Sample: Real-World Example: WiX/MSI Application Installer

Actually I solved it by putting together the entire path on top of my wxs file:
<?define AppTargetFileName = "$(var.myApp.TargetFileName)" ?>
<?if $(var.Platform) = x64 ?>
<?define AppTargetPath = "$(var.myApp.ProjectDir)\bin\x64\$(var.myApp.Configuration)\$(var.AppTargetFileName)" ?>
<?elseif $(var.Platform) = x86 ?>
<?define AppTargetPath = "$(var.myApp.ProjectDir)\bin\x86\$(var.myApp.Configuration)\$(var.AppTargetFileName)" ?>
<?else ?>
<?define AppTargetPath = "$(var.myApp.TargetPath)" ?>
<?endif ?>

Related

Wix Installer with Major Version Subfolder

I have the following code in my Product.wxs file
<Wix>
<?define ProductVersion="!(bind.fileVersion._957E198E_2074_A3FA_A554_6FE5D8E9F4FD)" ?>
<?define MajorVersion="!(bind.property.ProductVersion.Major)" ?>
<Product Id='*' Name='Software v$(var.MajorVersion)' Version='$(var.ProductVersion)' Manufacturer='...' UpgradeCode='...' Codepage='...'>
[...]
</Product>
</Wix>
The above is based on this Binding WIX FileVersion sub values? question's answer.
It gives me the following error though
My Plan B was smth like
<?define MajorVersion="!(bind.fileVersion._957E198E_2074_A3FA_A554_6FE5D8E9F4FD.Major)" ?>
or
<?define MajorVersion="!(bind.fileVersion.major._957E198E_2074_A3FA_A554_6FE5D8E9F4FD)" ?>
but those don't work either.
Ultimately I want to use the MajorVersion property/variable to be part of the install directory.
<CustomAction Id='DIRCA_TARGETDIR' Property='TARGETDIR' Value='[ProgramFilesFolder][Manufacturer]\[MajorVersion]\[ProductName]' Execute='firstSequence' />
Any help is greatly appreciated.
After some more digging I eventually found an answer myself.
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
<?define MainAssemblyVersion="!(bind.fileVersion._957E198E_2074_A3FA_A554_6FE5D8E9F4FD)" ?>
<?define MajorVersion="!(bind.property.ProductVersion.Major)" ?>
<Product Id='*' Name='Software v$(var.MajorVersion' Language='1033' Version='$(var.MainAssemblyVersion)' Manufacturer='...' UpgradeCode='...' Codepage='...'>
[...]
<!-- Initialize the 'TARGETDIR' directory property. -->
<CustomAction Id='DIRCA_TARGETDIR' Property='TARGETDIR' Value='[ProgramFilesFolder][Manufacturer]\[ProductName] v$(var.MajorVersion)' Execute='firstSequence' />
[...]
</Product>
</Wix>
I believe I was partly confused by the fact that bind.property.ProductVersion already exists and doesn't have to be declared (which I did in my first example)
Once you have the major version part in a variable, using it $(var.MainAssemblyVersion) is really all it needs.

Installer conditionally picking up files

I'm building a Wix installer and I need two separate versions of said installer. One that picks up the latest development build of the project and one that picks up the latest release build. Currently my fragment looks like this:
<Property Id="Program.ReleaseBuild" Value="0" />
<?define ReleaseBuild = [Program.ReleaseBuild]?>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="InstallFolder">
<Component Id="TheExe" Guid="GUID_GOES_HERE">
<?if $(var.ReleaseBuild) = 1?>
<File Id="ProjectExe" Source="(Rel Project Path)/program.exe" />
<?else?>
<File Id="ProjectExe" Source="(Dev Project Path)/program.exe" />
<?endif?>
</Component>
</ComponentGroup>
</Fragment>
And I have a transform on the msi that transforms the file after build. But the problem is that the file is picked up on compile time not install time, so both version of the installer end up having the same file contained in them. Any idea how I can conditionally grab a dev file or a rel file in the same wix project?
If you want to create installation packages based on build quality (debug versus release), you can use two product configuration and select the source based on it. This way, you can run msbuild twice, one for each configuration. I don't understand the purpose of the transform you mentioned.
So here are steps you could take to accomplish this:
Create an empty solution.
Add your wixproj to it.
Add your csproj to it.
Add a reference of the csproj to the wixproj.
Modify your File[Source] to use the project reference, this way:
<File Source="$(var.MyProject.TargetPath)" Id="ProjectExe" />
The $(var.MyProject.TargetPath) will automatically get the exe from the correct path.
Create a batch file to run the msbuild twice, one for each configuration, with the following commands:
C:\> msbuild mySolution.sln /p:Configuration=Debug
C:\> msbuild mySolution.sln /p:Configuration=Release
The result will be two installation packages, one for each configuration.

How do I change url in .wxs file with build configuration

I have a Wix install project in Visual Studio 2012 and have an xml node like
<MsiPackage ... DownloadUrl="http://uat.mywebsite.com/MyMSI.msi">
I want to change the url depending on the build configuration. i.e. in uat I want it to be http://uat.mywebsite.com/... and in release http://mywebsite.com/...
Is this possible, and if so how do I do it?
Your WiX project has access to build parameters, like the Configuration (debug or release). You can conditionally include the correct DownloadUrl for the current configuration by referencing $(var.Configuartion) in your component declarations:
Not tested this but something similar should work:
<?if $(var.Configuartion) = Release?>
<?define DownloadUrl = "http://uat.mywebsite.com/" ?>
<?elseif $(var.Configuartion) = Debug?>
<?define DownloadUrl = "http://mywebsite.com/" ?>
<?endif ?>
<MsiPackage ... DownloadUrl="$(var.DownloadURL)">

WiX Relative Path to the Source File

I have a simple Solution for my Project, which works well. But I am unable to grasp how to make the Source paths relative. Can somebody help me?
<Component Id="Bla.exe" Guid="*">
<File Id="Bla.exe" Source="D:\Projects\Bla\Bla\bin\Debug\Bla.exe" KeyPath="yes" Checksum="yes"/>
</Component>
How can I make the Path relative to the Wix Solution? WiX and all necessary files are in the same Solution.
You can use the relative path like so:
<File Id="Bla.exe" Source="..\bin\Debug\Bla.exe" KeyPath="yes" Checksum="yes"/>
OR
You can add a configuration file to your project to define common variables. To do so, add a new "WiX Include" file to your project, call it config.wxi. Then in your include file, you can define a SourceDir variable like so:
<?xml version="1.0" encoding="utf-8"?>
<Include>
<?define SourceDir = "D:\Projects\Bla\Bla\bin\Debug" ?>
</Include>
Now in your .wxs file, you can add a reference to the config file at the top, ex:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?include "config.wxi"?>
Then just reference your SourceDir variable like so:
<File Id="Bla.exe" Source="$(var.SourceDir)\Bla.exe" KeyPath="yes" Checksum="yes"/>
Also, there are some built in WiX project variables that you may use.
There are many ways to do this but personally what I like to do is put my application installer projects in different solutions. I build the application solution first and use postbuild commands to publish the content to a deploy folder.
In my installer projects I set $(var.SourceDir)="..\deploy" and then $(var.SourceDir)\foo.exe for a source path.

How to decouple things in Wix?

I want to install a product with some dll with Wix 3.5.
These dll are determined during the msi installation through a radio buttons group.
I have :
a (fragment) wxs for myDllv1
a (fragment) wxs for myDllv2
a (UI fragment) wxs with the RadioButtonGroup to choose between myDll v1 and myDll v2 with a property INSTALLTYPE
a main wxs file which installs the correct version of myDll.
Problem : I have another set of dll to add and I want to modify as less files as possible.
I don't want to introduce bugs and I want to keep things decoupled.
I would like to modify only the UI fragment with the radio buttons and add a myDllv3 fragment (without doing any changes to my main wxs file, so no condition in that file..).
Is it possible?
Why don't you use pre-processors to select the correct fragments when building the msi?
<?if $(env.SomeBuildParameter) = SetA ?>
<?include myDllSetAv1.wxs ?>
<?include myDllSetAv2.wxs ?>
<?else ?>
<?include myDllSetBv1.wxs ?>
<?include myDllSetBv2.wxs ?>
<?endif ?>
I may be misunderstanding the question, but it sounds like your different set of Dlls should be grouped by features within WIX. I'd suggest creating independent WIX fragments that represents a feature for each of your set of Dlls and then you can tie your UI to install a specific feature as appropriate.
You represent a feature at the product level like so:
<Feature Id="Feature.One" Title="Feature One">
<ComponentGroupRef Id="FeatureOneDlls.Group" />
</Feature>
<Feature Id="Feature.Two" Title="Feature Two">
<ComponentGroupRef Id="FeatureTwoDlls.Group" />
</Feature>
And within each of the features I'd recommend using a separate wxs file to supply the fragment information that contains the files for that feature.