I'm trying to do two things in WIX:
Create new environmental variable that points to specific directory, e.g. %test% which leads to a variable [DOCUMENTSPATH]
Create a shortcut to that folder on the desktop. Shortcut must be using the same variable [DOCUMENTSPATH]
Using the <RegistryKey> and <RegistryValue> I can create the environmental variable that leads to variable.
<Component Id="EnvironmentAlias" Guid="827d993f-32c0-4088-a72a-43888a5f496a">
<RegistryKey Root="HKLM" Key="SYSTEM\CurrentControlSet\Control\Session Manager\Environment">
<RegistryValue Type="string" Name="%NEW_PATH%" Value="[DOCUMENTSPATH]" Action="write"></RegistryValue>
</RegistryKey>
</Component>
This creates the shortcut
<Component Id="SampleDir" Guid="E9EAE95A-8234-406D-950D-397956287709" Directory="DesktopFolder">
<Shortcut Id="SampleDirSC"
Name="somename"
Target="[DOCUMENTSPATH]"
Advertise="yes"
Show="normal" />
</Component>
(Also tried with advertise=no)
The link and variable are created but the link type is file instead of folder - so both the behavior of it and looks are wrong. It looks like generic shortcut and does not open the folder on click - I need to right-click -> go to location to go to the [DOCUMENTSPATH] folder. This is because the [DOCUMENTSPATH] I'm using contains different environmental variable, e.g. %localappdata%.
Any ideas how to enforce target type of the shortcut in wix OR how to expand the environmental variables in wix?
Edit: additional explanation.
I am trying to make wix expand environmental variable (the one that starts with %, like %appdata%) when creating the shortcut because windows doesn't handle well dynamic variables in shortcuts.
Change your tag to this
<Component Id="SampleDir" Guid="E9EAE95A-8234-406D-950D-397956287709" Directory="DesktopFolder">
<Shortcut Id="SampleDirSC"
Name="somename"
Target="[DOCUMENTSPATH]"
WorkingDirectory="DOCUMENTSPATH"
Show="normal" />
</Component>
This is a part sample of my test code
<DirectoryRef Id="DesktopFolder">
<Component Id="ApplicationShortCutC" Guid="{CB93D6D1-AB98-4b45-98FF-4017EE5A0A09}">
<Shortcut Id="AppShortCutC" Name="!(wix.Product)"
Description="!(wix.ProductDesc)"
Target="[INSTALLDIR]"
WorkingDirectory="INSTALLDIR" />
<RegistryKey Root="HKCU" Key="!(wix.Manufacturer)\!(wix.Product)" Action="createAndRemoveOnUninstall">
<RegistryValue Name="ShortCutC" Type="integer" Value="1" KeyPath="yes" />
</RegistryKey>
<RemoveFolder Id="ShortCutFolder" Directory="ApplicationProgramsFolder" On="uninstall"/>
</Component>
</DirectoryRef
Shortcut element here, says that advertise=yes ignores the target.
Sample code
Related
I'm using SQLite Database and create installer of WPF application with WIX Toolset. The problem is, The below relative path works fine when I directly run from Visual Studio but does not work when I create installer with WIX and after install this installer run program then it gives fatal error for Database file.
In Project directory I've made a Database folder, in which the database files reside as you can see in below picture:
After creating installer by WIX Toolset, installed files as below:
inventory_control.db file path:
dbConnectionString path:
I've writen code for relative path connection string as under:
Relative Path:
string relativePath = #"Database\inventory_control.db";
string currentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
//string path = currentPath.Substring(0, currentPath.Length - 21);
string path = Path.GetDirectoryName(currentPath);
string absolutePath = System.IO.Path.Combine(path, relativePath);
string dbConnectionString = string.Format("Data Source={0};Version=3;Pooling=True;Max Pool Size=100;", absolutePath);
//string dbConnectionString = "Data Source=inventory_control.db";
sQLiteConnection = new SQLiteConnection(dbConnectionString);
dbConnectionString gives correct current path.
The above relative path works fine when I directly run from Visual Studio but does not work when I create installer with WIX. It gives a fatal error. How to resolve?
WIX File:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"><?define Inventory Control_TargetDir=$(var.Inventory Control.TargetDir)?>
<Product Id="f941ba49-4369-44d4-aa0c-b77f20aa41db" Name="Inventory Control" Language="1033" Version="1.0.0.0" Manufacturer="devtros.com" UpgradeCode="ce092371-53cc-4be9-ab5d-c7a2685af970">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<Icon Id="app_icon.ico" SourceFile="$(var.ProjectDir)app_icon.ico" />
<Property Id="ARPPRODUCTION" Value="app_icon.ico" />
<WixVariable Id="WixUIBannerBmp" Value="Images\background.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="Images\background.bmp" />
<WixVariable Id="WixUILicenseRtf" Value="$(var.ProjectDir)License.rtf" />
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<UIRef Id="WixUI_InstallDir" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<Feature Id="ProductFeature" Title="Inventory Control" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentRef Id="ApplicationShortcut" />
<ComponentRef Id="ApplicationShortcutDesktop" />
<ComponentGroupRef Id="Database_files" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Inventory Control">
<Directory Id="Files" Name="Files" />
<Directory Id="Database" Name="Database" />
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="Inventory Control" />
</Directory>
<Directory Id="DesktopFolder" Name="Desktop" />
</Directory>
</Fragment>
<Fragment>
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="9bd13330-6540-406f-a3a8-d7f7c69ae7f9">
<Shortcut Id="ApplicationStartMenuShortcut" Name="Inventory Control" Description="Inventory Control" Target="[INSTALLFOLDER]Inventory Control.exe" WorkingDirectory="INSTALLFOLDER" />
<RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\Inventory Control" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</DirectoryRef>
<DirectoryRef Id="DesktopFolder">
<Component Id="ApplicationShortcutDesktop" Guid="cde1e030-eb64-49a5-b7b8-400b379c2d1a">
<Shortcut Id="ApplicationDesktopShortcut" Name="Inventory Control" Description="Inventory Control" Target="[INSTALLFOLDER]Inventory Control.exe" WorkingDirectory="INSTALLFOLDER" />
<RemoveFolder Id="RemoveDesktopFolder" Directory="DesktopFolder" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\Inventory Control" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<!-- <Component Id="ProductComponent"> -->
<!-- TODO: Insert files, registry keys, and other resources here. -->
<!-- </Component> -->
<Component Id="Inventory_Control.exe" Guid="0a7e7061-201b-4d49-adeb-4449e9c4da3e">
<File Id="Inventory_Control.exe" Name="Inventory Control.exe" Source="$(var.Inventory Control_TargetDir)Inventory Control.exe" />
</Component>
<Component Id="Inventory_Control.exe.config" Guid="28323615-8159-4116-b1ac-e29a70bf2593">
<File Id="Inventory_Control.exe.config" Name="Inventory Control.exe.config" Source="$(var.Inventory Control_TargetDir)Inventory Control.exe.config" />
</Component>
<Component Id="System.Windows.Controls.Input.Toolkit.dll" Guid="7d678201-767a-416b-b645-b2cb7d514893">
<File Id="System.Windows.Controls.Input.Toolkit.dll" Name="System.Windows.Controls.Input.Toolkit.dll" Source="$(var.Inventory Control_TargetDir)System.Windows.Controls.Input.Toolkit.dll" />
</Component>
<Component Id="System.Data.SQLite.dll" Guid="178a5aef-c027-4215-81ae-f148ab6cd472">
<File Id="System.Data.SQLite.dll" Name="System.Data.SQLite.dll" Source="$(var.Inventory Control_TargetDir)System.Data.SQLite.dll" />
</Component>
<Component Id="Zen.Barcode.Core.dll" Guid="20e34fc3-0066-4ffd-b401-518bc1177098">
<File Id="Zen.Barcode.Core.dll" Name="Zen.Barcode.Core.dll" Source="$(var.Inventory Control_TargetDir)Zen.Barcode.Core.dll" />
</Component>
<Component Id="WPFToolkit.dll" Guid="8d974e65-defb-4675-b9e0-ff617e5ab1da">
<File Id="WPFToolkit.dll" Name="WPFToolkit.dll" Source="$(var.Inventory Control_TargetDir)WPFToolkit.dll" />
</Component>
</ComponentGroup>
</Fragment>
<Fragment>
<ComponentGroup Id="Database_files" Directory="Database">
<Component Id="Database_inventory_control.db" Guid="0104b919-0aa9-4dc5-9492-14c474d97cf1">
<File Id="Database_inventory_control.db" Name="inventory_control.db" Source="$(var.Inventory Control_TargetDir)Database\inventory_control.db" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
SQLite.Interop.dll: The file SQLite.Interop.dll needed to be installed along with the rest of the runtime files in order for SQLite
to function properly.
There are two flavors of the file, x86 and x64 format. It is
probably advisable to install both files in their respective folders:
Your installation folder hierarchy - mock-up:
YourBinary.exe
x86\SQLite.Interop.dll
x64\SQLite.Interop.dll
System.Data.SQLite.dll
Etc...
Read-Write DB Location: And then your database should be stored in a writeable path (or you need to make the path writeable for regular users using custom ACL permissioning - which is never a great idea).
Exceptions: Obviously try - catch your database connection, update and access code to detect these kinds of issues.
Folder Confusion: Is there a database file inside the Database folder? It sort of looks like the inventory_control.db file is installed to the main application folder, and not that Database sub-folder?
Maybe that file has been generated by the application.exe in the wrong folder?
Or maybe you have duplicated the file in the main folder for testing purposes?
Hard-Coded Dev-Box Sins?: What does it say in Inventory Control.exe.config?
Are there relevant settings in there that could override your code's values?
Could there be a hard-coded dev-box sin in there?
Path Builder: I assume you have "message boxed" the paths from the application during launch, in order to ensure that they are correct? I like to copy the path and do a Start => Run and paste the path to see that it opens. Press CTRL + C when the message box shows. Paste into Notepad. Extract the path and try it in Start => Run.
string path = currentPath.Substring(0, currentPath.Length - 21);. It is not very robust to hard code the number of characters in the file name to get the parent directory path?
Could you improve it by using Path.GetDirectoryName(currentPath)?
Or maybe even: string dir = currentPath.Substring(0,currentPath.LastIndexOf('\\'));
Attach Debugger & Debug Binaries?: Maybe you could install debug binaries and attach to them for debugging as described here: wix c# app doesn't launch after installing. Just to get a real step-through debugging session.
Path Spaces: That database connection string. Does it need quotes around its path? As in "path with spaces"? You may not have any spaces in the paths for your visual Studio project, but when installed there are spaces in the paths.
This constructs in your source does look weird, why is it necessary?:
<?define Inventory Control_TargetDir=$(var.Inventory Control.TargetDir)?>
I have mine custom installer and uninstaller, which install MSI and other resources to PC. Uninstall process works within the lines below:
<DirectoryRef Id="TARGETDIR">
<Component Id="AddRemovePrograms" Guid="*" KeyPath="yes">
<RegistryValue Id="ARPEntry1" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="DisplayName" Value="$(var.ProductName)"/>
<RegistryValue Id="ARPEntry2" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="DisplayVersion" Value="$(var.ProductVersion)"/>
<RegistryValue Id="ARPEntry3" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="Publisher" Value="$(var.Manufacturer)"/>
<RegistryValue Id="ARPEntry4" Type="integer" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="NoModify" Value="1"/>
<RegistryValue Id="ARPEntry5" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="UninstallString" Value="[CommonAppDataFolder]\[Manufacturer]\[ProductName]\Uninstaller.exe"/>
<RegistryValue Id="ARPEntry6" Type="string" Action="write" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\$(var.ProductCode)" Name="InternalVersion" Value="$(var.ProductVersion)"/>
</Component>
<Directory Id="CommonAppDataFolder">
<Directory Id="UninstallCompanyDir" Name="$(var.Manufacturer)">
<Directory Id="UninstallProductDir" Name="$(var.ProductName)">
<Component Id="UninstallerExe" Guid="*">
<File Id="UninstallerExeFile" Name="Uninstaller.exe" Source="..\Uninstaller.exe" Vital="yes" KeyPath="yes">
</File>
</Component>
</Directory>
</Directory>
</Directory>
</DirectoryRef>
In Uninstaller.exe i copy itself to TEMP folder and run it from there, but problem is my uninstaller left there (in TEMP).
Question:
How I can remove my executable file(from TEMP or original) with wix scripts ?
You can do this with batch!
something like
cmd.exe /C TIMEOUT 10 && del "{your uninstaller path}"
You run it at the uninstaller closing event. This will spawn a new cmd process and execute the delete command after 10seconds.
There is a documented "how to" for this scenario that doesn't require you to have an executable, using msiexec.exe instead of you own executable:
How To: Create an Uninstall Shortcut
You don't say whether your exe does anything other than call the uninstall, but IMO it's perfectly acceptable to copy to a temp folder and leave the executable there (and it doesn't need to be an exe because you can call CreateProcess on it as a .tmp file). There are standard tools that clear out temp folders (Disk Cleanup, server scripts) so don't worry about it.
In general you don't need an uninstall on the start menu from Windows 10 onwards. A right-click on an installed app brings up an uninstall anyway, and it may even suppress yours.
Create following batch file. This will run uninstaller, when uninstaller is done, it will delete uninstaller and batch file both.
START /WAIT YourUninstaller.exe
Del YourUninstaller.exe
Del ThisBatchFile.bat
I'm trying to create an installer using WiX. To includes DLLs into .msi package I tryied two different ways. One of these is:
<DirectoryRef Id="SETTINGSDIR">
<Component Id="CMP_CopySettings" Guid="AC7D1AA1-798B-48F5-AF8D-188B1050D47C" KeyPath="yes">
<CreateFolder />
<File Id="DBA.bat" Source="$(var.SolutionDir)\scr\A\A.WindowsService\bin\$(var.Configuration)\Settings\A_DB clear.bat" Checksum="yes"/>
<File Id="AConfiguration.xml" Source="$(var.SolutionDir)\scr\A\A.WindowsService\bin\$(var.Configuration)\Settings\AConfiguration.xml" Checksum="yes"/>
<File Id="ADB.CE.DEFAULT.sdf" Source="$(var.SolutionDir)\scr\A\A.WindowsService\bin\$(var.Configuration)\Settings\ADB.CE.DEFAULT.sdf" Checksum="yes"/>
<File Id="ADB.CE.sdf" Source="$(var.SolutionDir)\scr\A\A.WindowsService\bin\$(var.Configuration)\Settings\A.CE.sdf" Checksum="yes"/>
<RemoveFile Id="RemoveFileSettings" Name="*" On="uninstall"/>
</Component>
</DirectoryRef>
But as you can easily understand, it's very hard write an xml node for each DLL (6 projects with 200+ DLLs for each one).
The second one is faster, but WiX just creates a link to the folder instead of copy DLLs into msi package
<DirectoryRef Id="SETTINGSDIR">
<Component Id="CMP_CopySettings" Guid="AC7D1AA1-798B-48F5-AF8D-188B1050D47C" KeyPath="yes">
<CreateFolder />
<CopyFile Id="SettingsID" SourceProperty="SETTINGSSOURCEDIRECTORY" DestinationDirectory="SETTINGSDIR" SourceName="*" />
<RemoveFile Id="RemoveFileSettings" Name="*" On="uninstall"/>
</Component>
</DirectoryRef>
Is there a quick solution that can I add at my second way or I have to use heat.exe tool? In this case, can you explain me how to use it? The official documentation is very poor
Thanks
What you want is an harvest tool to do this for you. Luckily it already exists: Heat
In your specific case you might want to use the command heat dir ".\My Files" -gg -g1 -directoryid "YourDirectoryId" -sfrag -template:fragment -out directory.wxs but check what is exactly your need, which harvesting you want to skip etc...
Note the -t <xsl> switch which gives you the total control on how you want to tune the final output.
I need to reference some dlls files in my wix project, and i need to user relative path. If i use absolute path like this
C:\Users\MyUser\Documents\any\other\folder
it works perfectly, but i need a relative path like this:
../bin/dll
but it is unable to find the folder.
This is the "ComponentGroup" section where i need to get the dll folder
<ComponentGroup Id="DllsComponent" Directory="INSTALLFOLDER" Source="../bin/dll">
<Component Id="EntityFramework.dll">
<File Name="EntityFramework.dll" />
</Component>
<Component Id="EntityFramework.SqlServer.dll">
<File Name="EntityFramework.SqlServer.dll" />
</Component>
<Component Id="EntityFramework.SqlServerd.xml">
<File Name="EntityFramework.SqlServer.xml" />
</Component>
<Component Id="EntityFramework.xml">
<File Name="EntityFramework.xml" />
</Component>
<Component Id="ParodosService.exe.config">
<File Name="ParodosService.exe.config" />
</Component>
</ComponentGroup>
and the wix project structure is this:
ParodosService.Setup
|_bin
|_dll
|_EntityFramework.dll
|_EntityFramework.SqlServer.dll
|_other files...
|_Debug
|_Release
Thanks in advance...
You can use predefined directory properties from the list
System Folder Properties
Set the closest in the directory table and than use it in the source attribute.
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder">
</Directory>
</Directory>
Source attribute:
Source="$(var.DesktopFolder)../bin/dll
I am trying to create a installer for MVC4 application using Wix. I found an example that shows how to create an installer for a MVC4 Application at this link
But when I try to build the Wix Setup Project, it gives me errors like below
Error 16 Unresolved reference to symbol 'WixComponentGroup:MyWebWebComponents'
in section 'Product:{D16E42B5-3C6F-4EE5-B2F4-727BF8B74A92}'.
C:\Users\Baris\Desktop\New folder\WIXInstallerDemo-master\DemoWebsite.Setup\Product.wxs 15
1 DemoWebsite.Setup
Error 17 Unresolved reference to symbol 'WixComponentGroup:DemoWebsiteIssConfiguration'
in section 'Product:{D16E42B5-3C6F-4EE5-B2F4-727BF8B74A92}'.
C:\Users\Baris\Desktop\New folder\WIXInstallerDemo-master\DemoWebsite.Setup\Product.wxs 16
1 DemoWebsite.Setup`
I tried adding WixUIExtension as a reference but it doesn't work.
This is the Product.wxs. And feature node's children nodes causes this error
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="{D16E42B5-3C6F-4EE5-B2F4-727BF8B74A92}" Name="Demo website setup" Language="1033" Version="1.0.0.0" Manufacturer="Me" UpgradeCode="9279b740-8419-45c4-9538-6a45f8e949c7">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" Cabinet="DemoWebsite.cab" EmbedCab="yes" />
<Property Id="DB_USER" Value="sa"/>
<Property Id="DB_PASSWORD" Value="sa"/>
<Property Id="DB_SERVER" Value="LOCAL"/>
<Property Id="DB_DATABASE" Value="DemoWebsite"/>
<Feature Id="ProductFeature" Title="DemoWebsite.Setup" Level="1">
<ComponentGroupRef Id="MyWebWebComponents" />
<ComponentGroupRef Id="DemoWebsiteIssConfiguration" />
</Feature>
<!-- Specify UI -->
<UIRef Id="MyUI" />
<Property Id="WIXUI_INSTALLDIR" Value="INETPUB" />
</Product>
<Fragment>
<!-- Will default to C:\ if that is the main disk-->
<Directory Id="TARGETDIR" Name="SourceDir">
<!-- Will reference to C:\inetpub-->
<Directory Id="INETPUB" Name="Inetpub">
<!-- Will reference to c:\Inetpub\Demowebsite-->
<Directory Id="INSTALLFOLDER" Name="DemoWebsite">
</Directory>
</Directory>
</Directory>
</Fragment>
</Wix>
What am I doing wrong? I know its very specific for SO but I cannot find any solution on the web.
I am using VS 2012- Wix 4.0
The error message says it all: it expects a ComponentGroup-tag containing your components (containing e.g. files or registry keys). If you take a look at the example project that you linked in your question, the <ComponentGroupRef Id="DemoWebsiteIssConfiguration" />-element references a ComponentGroup with the name DemoWebsiteIssConfiguration. You can find this in the file DemoWebsite.Setup\IISConfiguration.wxs:
<ComponentGroup Id="DemoWebsiteIssConfiguration">
<ComponentRef Id="InstallWebsite" />
<ComponentRef Id="DemoWebsiteAppPool" />
</ComponentGroup>
It is a ComponentGroup which contains two components or, in this case, references to two components. These components are defined above the ComponentGroup-element in the same file.
Regarding the other ComponentGroupRef with the id MyWebComponents: The referenced ComponentGroup is created dynamically during the build. You can take a look at the file DemoWebsite.Setup\setup.build. This file is a MSBuild-file used to build the setup. It contains a target named Harvest that invokes heat, another tool in the WiX Toolset package. heat will parse e.g. a directory and gather all the files contained within and put them in a ComponentGroup that you can reference in your source file. I.e. you define a reference to a ComponentGroup and then you can create the content of this dynamically. This way you don't have to bother if a file is added to or removed from the project, as heat will gather them dynamically.
<Target Name="Harvest">
<!-- Harvest all content of published result -->
<Exec
Command='$(WixPath)heat dir $(Publish) -dr INSTALLFOLDER -ke -srd -cg MyWebWebComponents -var var.publishDir -gg -out $(WebSiteContentCode)'
ContinueOnError="false"
WorkingDirectory="." />
</Target>
The name of the dynamically created ComponentGroup is defined with the parameter -cg. you can invoke heat with the parameter -? for a short description of the possible parameters.