Showing WixUI_dialog conditionally - wix3.11

Currently struggling with an installer that should have different behaviour depending on a registry value.
If the registry value is not set then the installer should show the classic dialog to select the installation path and then store that path in the registry so that next time the .msi file, or an updated version thereof, is processed, it "knows" exactly where the repair should be made or the update deployed.
I have these snippets in my product.wxs:
<!-- Registry key location -->
<Property Id="MBREGISTRYKEY" Value="SOFTWARE\MyCompany\MyApp" Secure="yes"/>
<Property Id="PREVIOUS_PATH" Secure="yes">
<RegistrySearch Root="HKLM" Key="[MBREGISTRYKEY]" Name="Path" Type="directory" Id="PreviousPath"/>
</Property>
and
<Fragment>
<WixVariable Id="WixUIBannerBmp" Value="$(var.SolutionDir)Assets\Visuals\wix-banner.bmp"/>
<WixVariable Id="WixUIDialogBmp" Value="$(var.SolutionDir)Assets\Visuals\wix-background.bmp"/>
<UI>
<UIRef Id="WixUI_InstallDir"/>
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg" Order="2">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">1</Publish>
</UI>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLATIONDIR">
<Directory Id="CONFIGINSTALLATIONDIR" Name="config" />
</Directory>
</Directory>
<SetDirectory Id="INSTALLATIONDIR" Value="[WindowsVolume]MyApp" />
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLATIONDIR" />
</Fragment>
I have found plenty of examples here on SO and elsewhere that allow the installer to display different dialogs depending on conditions such as a registry value or an environment variable. What I have found nowhere is an example of what I'm trying to achieve, which is skipping the UI altogether, not just one or two of the dialogs in the UI, if my registry value is set. This is a requirement because deployment of updates must be unattended.

Related

Running SQL Script file through Wix using <sql:SqlScript> element

I am new to Wix Installer. I have a requirement where I have to provide credentials for SQL Server login and run a script from a specific path.
I am not getting what's going wrong.The project is build successfully and .msi is created. After running it I get the following Error:
Error 26204. Error -2147217900: failed to execute SQL string, error detail: Incorrect syntax near '»'., SQL key: CreateUpsizingDatabase SQL string: print convert(varchar(25),GetDate(),121) + ' Executing file: SqlTest.sql'
My Sql Script File is as below:
print convert(varchar(25),GetDate(),121) + ' Executing file: SqlTest.sql'
Below is My code:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
xmlns:sql="http://schemas.microsoft.com/wix/SqlExtension">
<Product Id="*" Name="SqlTest" Language="1033" Version="1.0.0.0" Manufacturer="BLRSCCMCAS01" UpgradeCode="0931a445-07bf-4494-b130-a1f96155021f">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SqlTest" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<Binary Id="CreateUpsizingDatabase" SourceFile="C:\Temp\SqlTest.sql" />
<util:User Id="SQLUser" Name="[User]" Password="[Password]" />
<sql:SqlDatabase Id="SqlDatabase" Database="[MyDb]" Server="[Server]" User="SQLUser" />
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="SqlTest" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="SqlComponent" Guid="15CCE46E-8EA5-42CA-80C5-AC3DB30A9716">
<sql:SqlScript Id="CreateDatabases" SqlDb="SqlDatabase" ExecuteOnInstall="yes" BinaryKey="CreateUpsizingDatabase" />
<CreateFolder/>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
It looks like you have a UTF8 BOM () in there. Try saving the file as "Unicode (UTF8 Without signature)" using the advanced save options in visual studio.
I got the same error, UTF8 with or without signature both failed.
I think the chars in our script string cause the problem (in my case, I included some chinese chars).
I tried to re-generated sql script from sql server, and save this file in ANSI format. It works!
And i did some query, the chinese chars are correct in sql server.
an article you might want to refer: http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Error-executing-sql-scripts-with-WIX-td1488703.html

DNN manifest problems - modules not working after install

Having trouble creating a manifest for a couple of modules. The module controls live in:
DesktopModules/Org/ItemManagement
Each module does related but different things, and so should be draggable onto a page as a standalone module.
After looking around, I think I need to create multiple package definitions in the manifest, so I have done that. I have then uploaded the controls and the manifest to the above folder, and installed using Host->Extensions->Create New Module->From Manifest
It seemed to installed okay, appears in the extension list, and appears in the module bar to add to a page; however, when I drag to a location on the page, the page errors on the call to /DesktopModules/internalservices/API/controlbar/AddModule with "The requested resource does not support http method 'GET'.".
If I put each control in a separate folder and install using Host->Extensions->Create New Module->From Control everything works fine, however this is not ideal as all controls will eventually share resources liek CSS, scripts etc., and ideally I want them to just get them from the ModulePath, just so everything is in one place.
Is there anything obviously wrong in my manifest?
<?xml version="1.0" encoding="UTF-8"?>
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="Org_My_Items" type="Module" version="01.00.00">
<friendlyName>My Items</friendlyName>
<description>
My Items grid
</description>
<owner>
<name>Org</name>
<organization>Org</organization>
<email>noreply#example.com</email>
</owner>
<components>
<component type="Module" version="01.00.00">
<desktopModule>
<moduleName>My Items</moduleName>
<foldername>Org</foldername>
<moduleDefinitions>
<moduleDefinition>
<friendlyName>My Items</friendlyName>
<moduleControls>
<moduleControl>
<controlSrc>DesktopModules/Org/ItemManagement/MyItems.ascx</controlSrc>
<controlTitle>My Items</controlTitle>
<controlKey>MyItems</controlKey>
<controlType>View</controlType>
</moduleControl>
</moduleControls>
</moduleDefinition>
</moduleDefinitions>
</desktopModule>
</component>
</components>
</package>
<package name="Org_My_Details" type="Module" version="01.00.00">
<friendlyName>My Details</friendlyName>
<description>
My Details summary display
</description>
<owner>
<name>Org</name>
<organization>Org</organization>
<email>noreply#example.com</email>
</owner>
<components>
<component type="Module" version="01.00.00">
<desktopModule>
<moduleName>My Details</moduleName>
<foldername>Org</foldername>
<moduleDefinitions>
<moduleDefinition>
<friendlyName>My Details</friendlyName>
<moduleControls>
<moduleControl>
<controlSrc>DesktopModules/Org/ItemManagement/MyDetails.ascx</controlSrc>
<controlTitle>My Details</controlTitle>
<controlKey>MyDetails</controlKey>
<controlType>View</controlType>
</moduleControl>
</moduleControls>
</moduleDefinition>
</moduleDefinitions>
</desktopModule>
</component>
</components>
</package>
</packages>
</dotnetnuke>
I have a similar package setup with my open-source DNN Social module. Compare what I have as it is working to install two desktop modules, each with their own module definition, and living in the same folder.
One thing I noticed is that you have specified a controlkey for your module controls. It is my understanding that DNN looks for one control within each moduledefinition with an empty control key <controlKey /> which denotes the default view of the module. Maybe that is an issue?

Ant: Find the path of a file in a directory

I want to find the path of a file in a directory (similar to unix 'find' command or the 'which' command, but I need it to work platform-independent) and save it as a property.
Tried to use the whichresource ant task, but it doesn't do the trick (I think it's only good for looking inside jar files).
I would prefer if it would be pure ant and not to write my own task or use a 3rd-party extension.
Notice that there might be several instances of a file by that name in the path - I want it to only return the first instance (or at least I want to be able to choose only one).
Any suggestions?
One possibility is to use the first resource selector. For example to find a file called a.jar somewhere under directory jars:
<first id="first">
<fileset dir="jars" includes="**/a.jar" />
</first>
<echo message="${toString:first}" />
If there are no matching files nothing will be echoed, otherwise you'll get the path to the first match.
Here is an example which selects the first matching file. The logic is as follows:
find all matches using a fileset.
using pathconvert, store the result in a property, separating each matching file with line separator.
use a head filter to match the first matching file.
The functionality is encapsulated in a macrodef for reusability.
<project default="test">
<target name="test">
<find dir="test" name="*" property="match.1"/>
<echo message="found: ${match.1}"/>
<find dir="test" name="*.html" property="match.2"/>
<echo message="found: ${match.2}"/>
</target>
<macrodef name="find">
<attribute name="dir"/>
<attribute name="name"/>
<attribute name="property"/>
<sequential>
<pathconvert property="#{property}.matches" pathsep="${line.separator}">
<fileset dir="#{dir}">
<include name="#{name}"/>
</fileset>
</pathconvert>
<loadresource property="#{property}">
<string value="${#{property}.matches}"/>
<filterchain>
<headfilter lines="1"/>
</filterchain>
</loadresource>
</sequential>
</macrodef>
</project>
I created a macro based on martin-clayton's answer.
sample project with macro and a property file that is read from the found file
<?xml version="1.0" encoding="utf-8"?>
<project name="test properties file read" default="info">
<macrodef name="searchfile">
<attribute name="file" />
<attribute name="path" default="custom,." />
<attribute name="name" />
<sequential>
<first id="#{name}">
<multirootfileset basedirs="#{path}" includes="#{file}" erroronmissingdir="false" />
</first>
<property name="#{name}" value="${toString:#{name}}" />
</sequential>
</macrodef>
<searchfile name="custom.properties.file" file="config.properties" />
<property file="${custom.properties.file}" />
<target name="info" >
<echo>
origin ${config.origin}
</echo>
</target>

Wix: how to create database using SqlScript

I need to create a simple database named MyDB by using Wix by using SqlString. Below is my code snippet. For the line (SQL="CREATE DATABASE MyDB"), may i know is this correct and will it create 'MyDB' database? I've set the User and Server attribute correctly. However, this allows installation but it does not create the database. Can anyone point out what is wrong or missing?
<sql:SqlDatabase Id='SqlDatabase' Database='master' User='SQLUser' Server='[SQLSERVER]'
CreateOnInstall='no' DropOnUninstall='no' ContinueOnError='yes'>
<sql:SqlString Id="InitialCreateDB" ExecuteOnInstall="no" ContinueOnError="yes"
SQL="CREATE DATABASE MyDB"/>
</sql:SqlDatabase>
Thanks in advance.
Why don't you have a script file containing SQL code to create the database.
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
xmlns:sql="http://schemas.microsoft.com/wix/SqlExtension">
<Product Name='SQL app 1.0' Id='DB501C18-86C7-4D14-AEC0-86416A69ABDE' Language='1033' Codepage='1252'
Version='1.0.0' Manufacturer='ABC Ltd.'>
<Package Id='????????-????-????-????-????????????' Keywords='Installer' Description="SQL App 1.0 Installer"
Comments='Comment.' Manufacturer='ABC Ltd.' InstallerVersion='100'
Languages='1033' Compressed='yes' SummaryCodepage='1252' />
<Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' />
<User Id="MySQLUser" Name="[SQLUSER]" Password="[SQLUSERPASSWORD]"></User>
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='INSTALLDIR' Name='TestSQL'>
<Component Id="MySqlComponent" Guid="C50999A0-02FD-42d5-9F65-7375318DD328">
<SqlDatabase Id="MySqlDatabase" Database="MyDatabase" Server="[SQLSERVER]" Instance="[SQLINSTANCE]"
CreateOnInstall="yes" DropOnUninstall="yes" User="MySQLUser" ContinueOnError="yes">
<SqlScript Id="CreateDatabase" ExecuteOnInstall="yes" BinaryKey="CreateTablesBin"></SqlScript>
</SqlDatabase>
</Component>
</Directory>
</Directory>
</Directory>
<Binary Id="CreateTablesBin" src="CreateDatabase.sql"></Binary>
<Feature Id='Complete' Level='1' Description="Full" Title="Full Installation">
<ComponentRef Id='MySqlComponent' />
</Feature>
</Product>
</Wix>
Set the CreateOnInstall value to "yes". This will than create an instance of the database.

Wix: Problem creating database with SqlFileSpec and SqlLogFileSpec Filename attribute set under c:\Program Files directory

I have a problem creating database with SqlFileSpec and SqlLogFileSpec Filename attribute set under c:\Program Files directory. I also checked that the folder (C:\Program Files\TestProject) already created. Does anyone know how to solve this?
This is the error:
Error 26201. Error -2147217900: failed to create SQL database: MyDatabase, error detail: CREATE DATABASE failed. Some file names listed could not be created. Check related errors..
<sql:SqlFileSpec Id="Mdf" Name="MyDatabase_Mdf" Filename="['INSTALLLOCATION']\MyDatabase.mdf" Size="3072KB" MaxSize="UNLIMITED" GrowthSize="1024KB"/>
<sql:SqlLogFileSpec Id="Ldf" Name="MyDatabase_log" Filename="['INSTALLLOCATION']\MyDatabase_log.ldf" Size="2048KB" MaxSize="2048GB" GrowthSize="10%"/>
...
<Property Id='INSTALLLOCATION'>C:\Program Files\TestProject</Property>
Thanks in advance.
The quotes around INSTALLLOCATION should be removed - use just [INSTALLLOCATION]. And make sure the mentioned files (mdf/ldf) are there by the time the action runs. Don't forget that the verbose log is your friend here.
Try this
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
xmlns:sql="http://schemas.microsoft.com/wix/SqlExtension">
<Product Name='SQL app 1.0' Id='DB501C18-86C7-4D14-AEC0-86416A69ABDE' Language='1033' Codepage='1252'
Version='1.0.0' Manufacturer='ABC Ltd.'>
<Package Id='????????-????-????-????-????????????' Keywords='Installer' Description="SQL App 1.0 Installer"
Comments='Comment.' Manufacturer='ABC Ltd.' InstallerVersion='100'
Languages='1033' Compressed='yes' SummaryCodepage='1252' />
<Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' />
<User Id="MySQLUser" Name="[SQLUSER]" Password="[SQLUSERPASSWORD]"></User>
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='INSTALLDIR' Name='TestSQL'>
<Component Id="MySqlComponent" Guid="C50999A0-02FD-42d5-9F65-7375318DD328">
<SqlDatabase Id="MySqlDatabase" Database="MyDatabase" Server="[SQLSERVER]" Instance="[SQLINSTANCE]"
CreateOnInstall="yes" DropOnUninstall="yes" User="MySQLUser" ContinueOnError="yes">
<SqlScript Id="CreateDatabase" ExecuteOnInstall="yes" BinaryKey="CreateTablesBin"></SqlScript>
</SqlDatabase>
</Component>
</Directory>
</Directory>
</Directory>
<Binary Id="CreateTablesBin" src="CreateDatabase.sql"></Binary>
<Feature Id='Complete' Level='1' Description="Full" Title="Full Installation">
<ComponentRef Id='MySqlComponent' />
</Feature>
</Product>
</Wix>
CreateDatabase.sql file will contain the script to execute some script, create database, etc.
I've managed to fix my issue by using ".\SQLExpress2012" instead of "[MachineName]\SQLExpress2012" or "[ipAddress]\SQLExpress2012". I can only speculate that by doing the former, you might not be using TCP/IP method of connecting and using named pipes instead.
Also you might want to check your SQL Server Configuration and verify that your server instance support these connection methods.

Resources