Get file version of the running exe installer - visual-studio

I'm using Wix for my application installation and I trying to add to installation the Build Number from TFS as text in on of the dialogs.
All my application dll's and the installer itself has the build number as their file version.
I was able to accomplish this only by getting a file version of an existing EXE(from this post: Getting the file version of a native exe in MSBuild) but not of the running EXE.
<?define Property_ProductVersion = "!(bind.FileVersion.UXIDTEST)" ?>
<Product Id="$(var.ProductId)" Name="$(var.ProductDisplayName)" Language="1033" Version="$(var.Property_ProductVersion)" Manufacturer="$(var.Property_Manufacturer)" UpgradeCode="$(var.ProductUpgradeCode)">
<Package InstallerVersion="300" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated" />
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='xxx'>
<Component Id='ttt' Guid='{AA2A781C-2324-4F9C-B96C-DCB5BB643409}'>
<File Id="UXIDTEST" Source="OriginalDatabase" ></File>
</Component>
</Directory>
</Directory>
What can I use to get the file version of the running EXE?

Related

WiX: preserving recursive directory structure during component transfer

Wix 3.11.2 and Visual Studio Community 2019 here. My project has the following directory structure:
...\Source\Repos\my-app-setup\
my-app-setup\
bin\
obj\
testo\
fizz\
abc\
def\
ghi\
abba.txt
buzz\
bar.txt
foo.txt
my-app.exe
my-app-setup.wixproj
my-app-setup.wxs
my-app-setup.sln
Where my my-app-setup.wxs file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">​
<Product Id="*" Name="MyApp" Language="1033" Version="1.0.0.0" Manufacturer="MyCompany" UpgradeCode="1e540666-dda2-4cbe-91b7-ac9525d96c86">​
<Package Description="MyApp tool" Compressed="yes" />​
​
<MediaTemplate EmbedCab="yes"/>​
​
<Directory Id="TARGETDIR" Name="SourceDir">​
<Directory Id="ProgramFilesFolder">​
<Directory Id="INSTALLFOLDER" Name="MyApp" />​
</Directory>​
​
<Directory Id="DesktopFolder" Name="Desktop">​
<Component Id="ApplicationShortcutDesktop" Guid="*">​
<Shortcut Id="ApplicationDesktopShortcut"​
Name="MyApp"​
Description="Shortcut for MyApp"​
Target="[INSTALLFOLDER]my-app.exe"​
WorkingDirectory="INSTALLFOLDER"/>​
<RemoveFolder Id="DesktopFolder" On="uninstall"/>​
<RegistryValue​
Root="HKCU"​
Key="Software/MyApp"​
Name="installed"​
Type="integer"​
Value="1"​
KeyPath="yes"/>​
</Component>​
</Directory>​
</Directory>​
​
<Component Id="FooTxtComponent" Directory="INSTALLFOLDER">​
<File Source="testo/foo.txt" />​
</Component>​
​
<Component Id="AbbaComponent" Directory="INSTALLFOLDER">​
<File Source="testo/fizz/abc/def/ghi/abba.txt" />​
</Component>​
​
<Component Id="ExecutableComponent" Directory="INSTALLFOLDER">​
<File Source="my-app.exe" />​
</Component>​
<Feature Id="MainFeature" Title="MyApp" Level="1">​
<ComponentRef Id="FooTxtComponent" />​
<ComponentRef Id="AbbaComponent" />​
<ComponentRef Id="ExecutableComponent" />
​
<ComponentRef Id="ApplicationShortcutDesktop" />​
</Feature>​
</Product>​
</Wix>
So it basically just copies a bunch of files from the project into the C:\Program Files (x86)\MyApp directory and then creates a shortcut (to the EXE) on the desktop. Simple stuff.
When I build this and run the MSI the resulting C:\Program Files (x86)\MyApp directory looks like this:
C:\Program Files (x86)\
MyApp\
foo.txt
abba.txt
my-app.exe
So WiX is just plucking the files I specified and dropping them into the MyApp directory, at the same level as the EXE file. I don't want this; I want to preserve the same recursive directory structure as what exists in my VS project. So instead of the above I would like the WiX MSI to generate:
C:\Program Files (x86)\
MyApp\
testo\
fizz\
abc\
def\
ghi\
abba.txt
foo.txt
my-app.exe
What is the simplest way to accomplish this?
Thanks!
You need to nest the folders as shown in this sample (towards bottom): https://www.codeproject.com/Tips/105638/A-quick-introduction-Create-an-MSI-installer-with
Illustration:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="Example">
<Component>
<File Source="example.exe"/>
</Component>
</Directory>
</Directory>
</Directory>
Maybe also check:
My WiX Quick-Start Link Collection.
https://www.firegiant.com/wix/tutorial/

WIX setup with user input

I've struggled with WIX for some time now. I want my program to be installed at the location the user has defined, install a service and start a program after installation.
First my msi package doesn't ask for install path.
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Test" />
</Directory>
</Directory>
</Fragment>
May someone tell me how to prompt a screen with change install path?
Second when my service will be installed there is an error which says I miss some permissions:
<File Id="FILE_Service" Source="$(var.Service.TargetPath)" />
<ServiceInstall Id="INSTALL_Service"
Name="Servcie"
Description=""
Start="auto"
ErrorControl="normal"
Type="ownProcess"/>
<ServiceControl Id="CONTROL_Service"
Name="Servcie"
Start="install"
Stop="both"
Remove="uninstall"
Wait="yes" />
May someone tell me how to start my service with admin access?
Third the installed package contains only one EXE file, no referenced assembly. May someone tell me how to tell WIX to search for references and install them?
WiX Tutorial: Quite a bit here. You should try a WiX tutorial: https://www.firegiant.com/wix/tutorial/
Links: Here is my WiX quick start tip answer - various resources and hints to deal with WiX and deployment in general.
Please note that there are alternative deployment and package creation tools that might help you make setups quicker and more reliably if you have little experience with MSI and setups.
Learning Advanced Installer - Resources
Direct link Advanced Installer Video Tutorials
Concrete Answer: Here are some attempted answers for your concrete questions:
Configurable installation directory (a bit down the page). You essentially set the ConfigurableDirectory attribute for a feature element to allow the user to select a custom installation directory (you get to the dialog where you can change the installation path by selecting "Custom" installation):
<Feature Id="FeatureDirectory" Title="FeatureDirectory" ConfigurableDirectory="MYCUSTOMDIR">
<!-- your stuff here -->
</Feature>
Major Upgrade Installation Directory: You need to read back the custom directory for major upgrades. Here is how: The WiX toolset's "Remember Property" pattern. Or it will revert to default during the major upgrade. This is because a major upgrade is an uninstall of the old version and a (re)-install of the new version.
Files: To install all required files you need to figure out by dependency scanning what files need to be deployed for your application to work, and then add them to your packages manually (or use heat.exe to auto-generate the files list to include). See the above quick start links for help, or see this hello wix style article: https://www.codeproject.com/Tips/105638/A-quick-introduction-Create-an-MSI-installer-with
Service Permissions: Services should be installed with admin rights if you install the setup after a UAC elevation prompt. Most likely it does not start because there are missing files and hence broken dependencies. What credentials does the service use to run? LocalSystem?
Mock-Up: Here is a quick mock-up of something along the lines of what you need. You need to add all files and dependencies and insert the Service constructs among other things:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="WiXSample" Language="1033" Version="1.0.0.0"
Manufacturer="Someone" UpgradeCode="cb24bedf-e361-4f25-9a06-ac84ce5d6f5c">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<!--Default GUI - add reference to WixUIExtension.dll -->
<UIRef Id="WixUI_Mondo" />
<Feature Id="Core" Title="Core" Level="1" ConfigurableDirectory="INSTALLFOLDER" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="WiXSample">
<Component Feature="Core">
<File Source="D:\MyBinary.exe" />
</Component>
</Directory>
</Directory>
</Directory>
</Product>
</Wix>

Visual Studio 2015 crashes on WiX installer build when PermissionEx is used

I'm trying to set folder permissions on creation. I want to modify permissions, instead of overwriting current, so I have used <PermissionEx/> tag from WiXUtilExtension instead of classic <Permission/> tag. I have added reference to WixUtilExtension.dll v4.0.0.0. WiX version is v4.0.4305.0. In WiX header I have added namespace <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">. When I try to set permission like
<Component Id="CreateFolder" Directory="DIRECTORYID" Guid="MY_GUID">
<CreateFolder>
<Permission User="[LogonUser]" GenericAll="yes"/>
</CreateFolder>
</Component>
installer build succesfully.
However, when I use
<Component Id="CreateFolder" Directory="DIRECTORYID" Guid="MY_GUID">
<CreateFolder>
<util:PermissionEx User="[LogonUser]" GenericAll="yes"/>
</CreateFolder>
</Component>
installer build stops with exception
and Visual Studio 2015 Community Edition crashes completely.
Directory is created like:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" >
<Directory Id="APPLICATIONFOLDER" >
<Directory Id="DIRECTORYID" Name="TestDir"/>
</Directory>
</Directory>
</Directory>
</Fragment>
Do you have any clues, if I am something doing wrong, or it is bug in newest WiX build?

Migrate Wix Project to version 4.0

I recently ugraded Wix to Version 4.0.
After updating the namespaces Visual Studio (2015) won't recognize these new ones.
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Product Id="*" Name="_any_name" Language="1033" Version="1.0.0.0" Manufacturer="Anyone" UpgradeCode="8c568038-54cf-43ff-aa2c-581f4dd0aea0" Codepage="1252">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<Feature Id="ProductFeature" Title="_any_title" Level="1">
<ComponentGroupRef Id="group_ProductComponents" />
</Feature>
<Property Id="pro_SetupExe" Value="INSTALLFOLDER" />
<CustomAction Id="ca_LaunchSetupExe" Property="pro_SetupExe" ExeCommand="/FORCE_HIDE_FIRST_RUN /UNATTENDED_INSTALL /AUTOACCEPT_ALL /FORCE_CLOSE_WHEN_DONE /ON_REBOOT_MESSAGE:”NO”" Execute="commit" />
<CustomAction Id="ca_SetSetupPath" Property="pro_SetupExe" Value="[INSTALLFOLDER]x64ATIDriver\setup.exe" />
<InstallExecuteSequence>
<Custom Action="ca_SetSetupPath" Before="ca_LaunchSetupExe" />
<Custom Action="ca_LaunchSetupExe" Before="InstallFinalize" />
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="TempFolder">
<Directory Id="INSTALLFOLDER" />
</Directory>
</Directory>
</Fragment>
</Wix>
The Wix element has an incorrect namespace of 'http://wixtoolset.org/schemas/v4/wxs'. Please make the Wix element look like the following: Wix xmlns = "http://schemas.microsoft.com/wix/2006/wi"
I founde these: Migrate Wix Project to v4.0 instructions
But I don't get what this means:
Fix: Explicitly set absent Id attributes on File element to the Name attribute or filename from the Source attribute.
So currently I just have the kind of "crashed" project and can't build.
I'd really appreciate some help.
regards Muffex
The namespace error makes it sound like the project is still being built by WiX v3. Also, that migrate to v4 page that you found is for the WixCop tool which automates everything you found there. It's in the bin directory of the WiX installation directory.

Using WiX to create an IIS virtual directory

I'd ask this on the WiX mailing list, but it seems to be down.
I have an application which is both a desktop app and a web app which runs locally. I've created a couple of basic WiX installers, but haven't yet used the IIS extension to create a virtual directory under IIS. I haven't been able to find a simple example of how to do this. All I need to do is create the virtual directory, set its port, and point it at a real directory which I'm creating with the rest of the installer.
A bonus would be enabling IIS on the machine if it's not already enabled, but I'm guessing that's not possible, and isn't a dealbreaker for me anyway.
If it matters, this installer will only be run on Vista machines.
Since the article mentioned by David seems lost, here is an example. This also creates an application in the virtual directory.
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
<Product Id="6f2b2358-YOUR-GUID-HERE-aa394e0a73a2" Name="WixProject" Language="1033" Version="1.0.0.0" Manufacturer="WixProject" UpgradeCode="225aa7b2-YOUR-GUID-HERE-110ef084dd72">
<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<!-- Reference existing site at port 8080 -->
<iis:WebSite Id="My.Site" Description="My Site">
<iis:WebAddress Id="My.Web.Address" Port="8080"/>
</iis:WebSite>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="WixProject">
<Component Id="IIS.Component" Guid="{6FAD9EC7-YOUR-GUID-HERE-C8AF5F6F707F}" KeyPath="yes">
<iis:WebVirtualDir Id="My.VirtualDir" Alias="foo" Directory="INSTALLLOCATION" WebSite="My.Site">
<iis:WebApplication Id="My.Application1" Name="Web Application 1"/>
</iis:WebVirtualDir>
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="WixProject" Level="1">
<ComponentRef Id="IIS.Component" />
</Feature>
</Product>
</Wix>
Use iis:WebVirtualDir and iis:WebApplication from http://schemas.microsoft.com/wix/IIsExtension namespace.
I had a similar question earlier and I found the following article quite useful: Wix 3.0 Creating IIS Virtual Directory
Digging in the Google cache (which I think is now been purged by Google) I think the following is the code to the missing blog entry David Pokluda included in his answer. I had to do some reformatting to get this into SO, sorry if it's ugly.
<?xml version="1.0" encoding="UTF-8"?>
<!--
IMPORTANT
1. need to add the schema iis.xsd to the property window
2. add the following iis namespace
3. add the Visual Studio reference WixIIsExtenion
-->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
<Product Id="7b523f47-YOUR-GUID-HERE-fea6be516471"
Name="Vince Wix 3 Web Service"
Language="1033"
Version="1.0.0.0"
Manufacturer="Vince LLC"
UpgradeCode="0a8c10df-YOUR-GUID-HERE-50b9ecdb0a41">
<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="WebAppWixProject.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="WebApplicationFolder" Name="MyWebApp">
<Component Id="ProductComponent" Guid="80b0ee2a-YOUR-GUID-HERE-33a23eb0588e">
<File Id="Default.aspx" Name="Default.aspx" Source="..\MyWebApp\Default.aspx" DiskId="1" />
<File Id="Default.aspx.cs" Name="Default.aspx.cs" Source="..\MyWebApp\Default.aspx.cs" DiskId="1"/>
<iis:WebVirtualDir Id="MyWebApp" Alias="MyWebApp" Directory="WebApplicationFolder" WebSite="DefaultWebSite">
<iis:WebApplication Id="TestWebApplication" Name="Test" />
</iis:WebVirtualDir>
</Component>
</Directory>
</Directory>
</Directory>
<!--
IMPORTANT
Add a virtual directory to an existing web site
If put it inside the Component, a new Web Site will be created and uninstall will remove it
-->
<iis:WebSite Id='DefaultWebSite' Description='Default Web Site' Directory='WebApplicationFolder'>
<iis:WebAddress Id="AllUnassigned" Port="80" />
</iis:WebSite>
<Feature Id="ProductFeature" Title="Vince Wix 3 Web Service" Level="1">
<ComponentRef Id="ProductComponent" />
</Feature>
</Product>
</Wix>
<!--
IMPORTANT
To get rid of light.exe location error, do the following on the Linker Tab:
Set culture to: en-US
Supress Schema Validation in the Advanced Button
-->
I'm not familiar with WiX, but both IIS 6 and 7 can be managed using WMI (Windows Management Instrumentation) objects. I've used both PowerShell and C# to create websites, virtual directories, permissions etc on IIS. You should be able to get your hands on these objects from most scripting environments.
The above snippets use the iis:WebAddress in an improper way. You need to add IP="*" if you want this to work with all websites that match the name and the port. The above example fails during the install if there is an ip address assigned to the website in IIS (wix CA will not find it in general)
Rant: wix is terrible for many reasons, in my opinion and this is a good example. If the attribute is missing it will only work for websites with the default IP - how unintuitive is this. Wix should at least emit a waring for a missing IP element. Furthermore the default IP (localhost) is represented as * in IIS metabase, at the same time in the wix file * means all websites (not only *). So it is really confusing and not intuitive at all.

Resources