Install components before custom actions - custom-action

My setup app should create user in sql server and restore a database. I do it as two separate projects;one to copy the database backup file to the machine, and the other one to do the actions. I'm planning to make it a single project.
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder" Name="Program Files" >
<Directory Id="INSTALLFOLDER" Name="My Produact name" >
<Directory Id="DBDIR" Name="DB PreReq" ></Directory>
</Directory>
</Directory>
</Directory>
<UI Id="DbConfigSetupUI" >
<TextStyle Id="DlgFont8" FaceName="Tahoma" Size="8" ></TextStyle>
<TextStyle Id="DlgTitleFont" FaceName="Tahoma" Size="8" Bold="yes" ></TextStyle>
<UIRef Id="Custom_WixUI_Mondo" />
<UIRef Id="WixUI_ErrorProgressText" />
<InstallUISequence >
<Custom Action="CreateUserWithSa" Before="FileCost" >NOT Installed</Custom>
<Custom Action="CreateUserWithWindows" After="CreateUserWithSa" >(SARETURN="fail") AND NOT Installed</Custom>
<Show Dialog="ConnectionStringDialog" After="CreateUserWithWindows" >(WINDOWSRETURN="fail") AND NOT Installed</Show>
<Custom Action="CreateUserWithPrompt" After="ConnectionStringDialog" >(DBLOGIN AND PASSWORD) AND NOT Installed</Custom>
<Custom Action="CreateDB" After="CreateUserWithPrompt" >(SARETURN="pass" OR WINDOWSRETURN="pass" OR PROMPTRETURN="pass") AND NOT Installed</Custom>
</InstallUISequence>
</UI>
</Fragment>
Here the files are not being copied(components are placed in a separate file), but the custom actions are being done. Since the backup file is necessary to restore. I need that to happen first. Is there a way to achieve that?

Schedule your custom action to run after InstallFinalize in the InstallExecuteSequence. You are guaranteed that your files will be installed by that point. Be warned you will need to store your property/data values if your action needs to access them.

Related

platform independent registration of IIS with ASP in wix installer

I made a wix installer which successfully enables the IIS with asp by running the command Aspnet_regiis.exe on 64 bit system. However, this command has different path in .net framework folder depending on 32 bit or 64 bit system according to this linkIIS registration with ASP
on 32 bit system
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i
and on 64 bit system
%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe -i
I need to extend my installer to cover both 32 bit and 64 bit platforms. I tried to this answer answer on platform independent by defining a preprocess variable based on the platform as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?if $(var.Platform) = x64 ?>
<?define IISRegCommand = "C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i" ?>
<?else ?>
<?define IISRegCommand = "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i" ?>
<?endif ?>
<Product Id="*" Name="IISRegistration" Language="1033" Version="1.0.0.0" Manufacturer="Eurotherm By Schneider-Electric" UpgradeCode="4bfb41e4-5701-4a47-9c4c-cdb657ab7a62">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated"/>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" Cabinet="cab1.cab" EmbedCab="yes" />
<Feature Id="ProductFeature" Title="IISRegistration" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<CustomAction Id="IISRegistration" Directory="INSTALLFOLDER"
ExeCommand="$(var.IISRegCommand)"
Return="check"/>
<InstallExecuteSequence>
<Custom Action="IISRegistration" After="InstallFiles"></Custom>
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="CommonAppDataFolder">
<Directory Id="Company" Name="Company">
<Directory Id="INSTALLFOLDER" Name="Application" />
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent" Guid="">
<File Id="File1" Name="IISRegistration.txt" Source="IISRegistration.txt"></File>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
However, when I compile it with candle.exe I get the following error:
"error CNDL0150: Undefined preprocessor variable '$(var.Platform)'"
BTW, I am using wix 3.11.
Is there any way I can resolve this?
Try to add this code to the .wixproj:
<PropertyGroup>
<DefineConstants>
$(DefineConstants);
Platform=$(Platform)
</DefineConstants>
</PropertyGroup>

Deploy WCF Webservice with WiX Toolset - Steps

I am building a WCF service project and now i want to add a Wix based setup project also into the solution (VS.NET 2013). I am using the Wix toolset for the first time. I am using the latest version of Wix toolset Ver 3.10.
Please help me out in laying down the steps required in filling up the .wxs file.
Here is the xml content from ImportService.wxs:-
<?xml version="1.0" encoding="UTF-8"?><Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="$(var.outputName)" Language="1033" Version="1.0.0.0" Manufacturer="Client" UpgradeCode="80d51001-e699-47b8-9221-fc6633fddf15">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Platform="x64" />
<MajorUpgrade DowngradeErrorMessage="A newer version of Import Service is already installed." />
<Media Id="1" Cabinet="Cab1.cab" EmbedCab="yes"/>
<MediaTemplate />
<Feature Id="ProductFeature" Title="$(var.outputName)" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="Client" Name="Client" >
<Directory Id="INSTALLFOLDER" Name="$(var.outputName)" />
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!--<Component Id="ProductComponent" Guid="93A6A063-F63D-455A-BD63-A21D32D15CE5" Win64="yes">
</Component>-->
</ComponentGroup>
</Fragment>
Please suggest how to add the WCF .svc & other files into the ComponentGroup area in the wix file.
You can publich service using IIS.
<!-- Use DISM to setup IIS (see also http://support.microsoft.com/kb/2736284) -->
<!-- Build path to dism.exe (full path is important, just calling dism.exe without path will fail) -->
<CustomAction Id="InstallIISSetProperty" Property="InstallIIS" Execute="immediate"
Value=""[System64Folder]dism.exe" /Online /Enable-Feature /All /FeatureName:IIS-WebServerRole /FeatureName:IIS-ASPNET45 /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-NetFxExtensibility45 /FeatureName:NetFx4Extended-ASPNET45" />
<!-- Call dism.exe quietly (without showing command prompt).
(see also http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html) -->
<CustomAction Id="InstallIIS" BinaryKey="WixCA" DllEntry="CAQuietExec64"
Execute="deferred" HideTarget="no" Return="ignore" Impersonate="no"/>
...
<InstallExecuteSequence>
<Custom Action="InstallIISSetProperty" After="CostFinalize">
<![CDATA[NOT Installed]]>
</Custom>
<Custom Action="InstallIIS" Before="WriteRegistryValues">
<![CDATA[NOT Installed]]>
</Custom>
</InstallExecuteSequence>

WIX 3.6 IIS 7 installer causing 'Site 1 has no root application defined, so the site will be ignored.' error on uninstall

I am using Wix 3.6 to install a Web application to IIS 7 and the install works correctly but when uninstalling the application either with Add/Remove Programs or with MSIExec I get the following error in IIS.
There was an error while performing this operation.
Details:
The application '/' does not exist.
The error in System log is as follows.
Site 1 has no root application defined, so the site will be ignored.
The log file on uninstall when using MSIExec and the /qb option shows just this one error and it doesnt seem like it could cause this type of problem where the Default Web Site directory in IIS becomes corrupt but perhaps it can.
Action start 7:04:40: ExitDialog. DEBUG: Error 2726: Action not
found: ExitDialog The installer has encountered an unexpected error
installing this package. This may indicate a problem with this
package. The error code is 2726. The arguments are: ExitDialog, ,
Action ended 7:04:40: ExitDialog. Return value 0. Action ended
7:04:40: INSTALL. Return value 1.
Here is the relevant portion of the wix file. If anyone has any ideas that can point me in the right direction they will be greatly appreciated. Thanks in advance.
<Product
Name="$(var.WebName)"
Id="*"
UpgradeCode="GUID"
Manufacturer="MyCo"
Version="$(var.ProductVersion)"
Language="1033">
<Package Id='*'
InstallScope="perMachine"
Manufacturer="MyCo"
InstallerVersion="200"
Languages="1033"
Compressed="yes"/>
<MajorUpgrade Schedule="afterInstallValidate"
DowngradeErrorMessage='A later version of this application is already installed. Setup will now exit'></MajorUpgrade>
<Media Id="1" Cabinet="MyProduct.cab" EmbedCab="yes" />
<Property Id="IISROOT">
<RegistrySearch Id="WEBROOT" Root="HKLM" Key="Software\Microsoft\InetStp" Name="PathWWWRoot" Type="raw" />
</Property>
<Property Id="WIXUI_INSTALLDIR" Value="FILEINSTALLDIR" Secure="yes" >
<RegistrySearch Id="WIXUI_INSTALLDIR" Type="raw" Root="HKLM" Key="SOFTWARE\MyCo" Name="InstallDir" />
</Property>
<Property Id="WIXUI_VIRTUALDIR" Secure="yes" Value="VIRTUALDIR" >
<RegistrySearch Id="WIXUI_VIRTUALDIR" Type="raw" Root="HKLM" Key="SOFTWARE\MyCo" Name="WixUiVirtualDir" />
</Property>
<Property Id="VIRTUALDIR" Secure="yes" Hidden="no" >
<RegistrySearch Id="VIRTUALDIR" Type="raw" Root="HKLM" Key="SOFTWARE\MyCo" Name="VirtualDir" />
</Property>
<CustomAction Id="FILEINSTALLDIR" Property="FILEINSTALLDIR" Value="[IISROOT]\[VIRTUALDIR]" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="IISROOT" Name=".">
<Directory Id="FILEINSTALLDIR" Name="AppDirectory">
<Component Id="MyCo_AppComponent" Guid="GUID">
<File Source=...
</Component>
</Directory>
</Directory>
</Directory>
<iis:WebSite Id="DefaultWebSite" Description="Default Web Site" SiteId="*">
<iis:WebAddress Id="AllUnassigned" Port="1" />
</iis:WebSite>
<DirectoryRef Id="FILEINSTALLDIR">
<Component Id="MyCoSiteComponent" Guid="GUID" KeyPath="yes">
<iis:WebVirtualDir Id='AppComponentVirtDir' Alias='[VIRTUALDIR]' Directory='FILEINSTALLDIR'
WebSite='DefaultWebSite'>
<iis:WebDirProperties Id="AppComponentVirtDirProperties"
AnonymousAccess="no" BasicAuthentication="no"
WindowsAuthentication="yes" />
<iis:WebApplication Id='MyAppName' Name='[VIRTUALDIR]' Isolation='medium' />
</iis:WebVirtualDir>
</Component>
</DirectoryRef>
I figured out what I was doing wrong, there was a registry setting that was named differently in the lookup then it was in the removal, since I didn't include that in the original code I will include the bad code example below. Note the Registry path is different 1) MyCo 2) MyCompany (this is for demonstration purposes but you get my drift). This caused the Default Web Site to become corrupt and had to be replaced. So in short make sure the Registry key names you make are named correctly! :) This was a painful one.
Where I set the value from the Registry:
<Property Id="WIXUI_VIRTUALDIR" Secure="yes" Value="VIRTUALDIR" >
<RegistrySearch Id="WIXUI_VIRTUALDIR" Type="raw" Root="HKLM" Key="SOFTWARE\MyCo" Name="WixUiVirtualDir" />
</Property>
Where I remove the Registry setting:
<DirectoryRef Id="FILEINSTALLDIR">
<Component Id="RegistryEntries" Guid="GUID">
<RegistryKey Root="HKLM"
Key="SOFTWARE\MyCompany"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="string" Name="WixUiVirtualDir" Value="[VIRTUALDIR]" />
</RegistryKey>
</Component>
</DirectoryRef>

How to debug FileSource attribute of Directory in WiX?

I have got a setup project in WiX in Visual Studio 2010 and in .wxs file I've got:
<Directory Id="SOLVERSLOCATION" Name="Solvers" FileSource="$(var.Main.TargetDir)Solvers">
<Component Id="CmpntSolvers" Guid="13C2AB0B-1AC1-4075-AC75-2716FE37F24A">
<CreateFolder/>
</Component>
</Directory>
<Directory Id="PLUGINSLOCATION" Name="Plugins" FileSource="$(var.Main.TargetDir)Plugins">
<Component Id="CmpntPlugins" Guid="6B6BDF54-2A49-444E-8214-C856530D3BEB">
<CreateFolder/>
</Component>
</Directory>
...
<Feature ... >
<ComponentRef Id="CmpntSolvers" />
<ComponentRef Id="CmpntPlugins" />
</Feature ... >
The problem is that whereas content of PLUGINSLOCATION is added allright to the installator the content of SOLVERSLOCATION is not added at all. I'm at loss what's the reason. The only difference in folders is that PLUGINSLOCATION contains only dll files and in SOLVERSLOCATION are dll files, exe file and ini file.
What may be the problem?
Thank you!
EDIT: There's no problem in paths. I've tried absolute paths too and there was no change.
There isn't many documentation about the FileSource attribute, but perhaps the next link helps you.
Bob Arnson’s blog: Choosing-your-payloads
Check for the "Overriding implicit payload directories" sutitle, it talks about the FileSource attribute and the way it's expected to work. But I suggest you readeing the entire post.
Hope it helps.

WiX - Permissions for ASP.NET Temp Folder

I'm trying to set the permissions of the temp ASP.NET files folder as follows:
<PropertyRef Id="NETFRAMEWORK20INSTALLROOTDIR"/>
<DirectoryRef Id="NETFRAMEWORK20INSTALLROOTDIR">
<Directory Id="TempASPNETFolder" Name="Temporary ASP.NET Files">
<Component Id="PermissionsTempAspnet" Guid="{C107EC7F-FC97-41b6-B418-EA4532949362}">
<CreateFolder>
<util:PermissionEx GenericAll="yes" User="[WIX_ACCOUNT_NETWORKSERVICE]" />
</CreateFolder>
</Component>
</Directory>
</DirectoryRef>
I've included the netfx and util extensions. When I compile I get the following error:
error LGHT0094: Unresolved reference to symbol 'Directory:NETFRAMEWORK20INSTALLROOTDIR'
What am I missing here?
Update: Not know much about WiX, I tried this. It compiles and links. Not sure it actually works.
<DirectoryRef Id="TARGETDIR">
<Directory Id="NetFramework20InstallDir" Name="[NETFRAMEWORK20INSTALLROOTDIR]">
<Directory Id="TempASPNETFolder" Name="Temporary ASP.NET Files">
<Component Id="PermissionsTempAspnet" Guid="{C107EC7F-FC97-41b6-B418-EA4532949362}">
<CreateFolder>
<util:PermissionEx GenericAll="yes" User="[WIX_ACCOUNT_NETWORKSERVICE]" />
</CreateFolder>
</Component>
</Directory>
</Directory>
</DirectoryRef>
Your second solution will create a directory named "[NETWORKFRAMEWORK20INSTALLROOTDIR]" on the largest drive on you machine. I don't think that is what you want. :)
The solution is to use "NETFRAMEWORK20INSTALLROOTDIR" as the Directory/#Id. This makes sense only after you realize that Directories can be treated like Properties. Not necessarily intuitive but that's what the Windows Installer does nonetheless. So, I'd just change your first example to something like:
<PropertyRef Id="NETFRAMEWORK20INSTALLROOTDIR"/>
<DirectoryRef Id="TARGETDIR">
<Directory Id="NETFRAMEWORK20INSTALLROOTDIR" Name="This will be ignored because the DirectorySearch used by the PropertyRef above will overwrite it.">
<Directory Id="TempASPNETFolder" Name="Temporary ASP.NET Files">
Hopefully, that points you in the right direction. Note, I would use a shorter Directory/#Name than my example above. ;)

Resources