later to define install dir

Aug 9, 2015 at 9:53 PM

I need to define installation directory depending on parent web site location + web application name.

I tried to use:

var project = new ManagedProject("MyProduct",
            new Dir("UNDEFINED",
and then set INSTALLDIR in custom action:
new ManagedAction(@"SetInstallDir", Return.check, When.Before, Step.InstallFiles, Condition.NOT_Installed)

and "SetInstallDir" function assign INSTALLDIR into a path which depends on 2 other properties... but unfortunately it creates "UNDEFINED" directory on current disc.

I also see that InstallDir has correct value in one helping message boxes goes from project template...

How to set it?

Also, actually I need to use physical path of parent web site to which I install application, may be it's some standard way to use it?
Aug 10, 2015 at 8:38 AM
This may help: sample "<WixSharp>\Wix# Samples\InstallDir" shows how to overwrite the default installdir. In the sample it is set from the Install_CustomDirectory.cmd batch file but you can do the same from your custom action.

But the easiest way is to modify the InstallDir dialog to implement your "path generation" instead of going with the custom action.
Aug 10, 2015 at 10:25 AM
ohh, in my case install dir depends on what site user is selected and actually installdir = physical folder of parent web sire + service name
(service name is also selected by user during installation)
Aug 10, 2015 at 1:00 PM
If you use managed custom action then you just assign assign the installdir new value:
session["INSTALLDIR"] = <physical folder of parent web sire> + <service name>;
But you decided not to use .NET so you will need to do this in raw MSI/WiX.
Aug 10, 2015 at 1:16 PM
It's misunderstanding. I used .net, but for some reason it doesn't work. (see the first post).
Aug 10, 2015 at 1:36 PM
It's hard for me to comment on your code as the only thing that I know about it is that "it doesn't work".

The following is a complete code that does work. You probably will be able to adjust it to your requirements:
//css_dir ..\..\..\;
//css_ref Wix_bin\SDK\Microsoft.Deployment.WindowsInstaller.dll;
//css_ref WixSharp.UI.dll;
//css_ref System.Core.dll;
//css_ref System.Xml.dll;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using WixSharp;
using WixSharp.Forms;
using WixSharp.UI.Forms;

public class Script
    static public void Main()
        var project =
            new ManagedProject("ManagedSetup",
                new Dir(@"%ProgramFiles%\My Company\My Product",
                    new File(@"..\Files\bin\MyApp.exe"),
                    new Dir("Docs",
                        new File("readme.txt"))));

        project.ManagedUI = ManagedUI.Empty;
        project.Load += project_Load;
        project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");


    static void project_Load(SetupEventArgs e)
            if (string.IsNullOrEmpty(e.Session["INSTALLDIR"])) //installdir is not set yet
                string installDirProperty = e.Session.Property("WixSharp_UI_INSTALLDIR");
                string defaultinstallDir = e.Session.GetDirectoryPath(installDirProperty);

                e.Session["INSTALLDIR"]= System.IO.Path.Combine(defaultinstallDir, Environment.UserName);
        catch { }
        MessageBox.Show(e.ToString(), "Load");
Aug 12, 2015 at 4:22 PM
I made something similar:
static void Main()
            var serviceName = "Pdf";
            var pdfIisSite = new WebSite(serviceName)
                InstallWebSite = false,
                Description = "[IISWEBSITE_NAME]",
                AttributesDefinition = "Directory=INSTALLDIR; SiteId=*"
                Addresses = new[]
                    new WebSite.WebAddress
                        Attributes = new Attributes()
                            {"Port", "8080"},
            var project = new ManagedProject("MyProductName",
                new Dir(@"%ProgramFiles%\MyCompany\MyProduct\Pdf",
                    new Files(@"_PublishedWebsites\WebProject\*.*"),
                    new File(System.IO.Path.GetFullPath("License.rtf"),
                        new IISVirtualDir()
                            AppName = "[PDFSERVICE_NAME]",
                            Name = "VirtualDirForScPdf",
                            Alias = "[PDFSERVICE_NAME]",
                            WebDirProperties = new WebDirProperties(serviceName)
                                AttributesDefinition = "AnonymousAccess=yes; WindowsAuthentication=no"
                            WebSite = pdfIisSite,
                            WebAppPool = new WebAppPool("[PDFWEB_APPPOOL]")
                                Attributes = new Attributes()
                                    {"ManagedRuntimeVersion", "v4.0"},
                                    {"ManagedPipelineMode", "Integrated"}
                        new Property("IISWEBSITE_NAME", "SomeName"),
                        new Property("PDFSERVICE_NAME", "Pdf"),
                        new Property("PDFWEB_APPPOOL", "Pdfcustom"),
                        new Property("PDFAUTHENTICATION", "empty"),
                        new SetPropertyAction("MSIUSEREALADMINDETECTION", "1")
            project.GUID = new Guid("be4f117e-cfba-40ad-a345-fbf4daa531d4");
            //custom set of standard UI dialogs
            project.ManagedUI = new ManagedUI();
            project.Load += Msi_Load;
            project.BeforeInstall += Msi_BeforeInstall;
            project.AfterInstall += Msi_AfterInstall;

static void Msi_Load(SetupEventArgs e)
            var selectedSite = e.Session["IISWEBSITE_NAME"];
            var serviceName = e.Session["PDFSERVICE_NAME"];
            var iisManager = new ServerManager();
            var sites = iisManager.Sites;
            var site = sites.SingleOrDefault(s => s.Name == selectedSite);
            if (site != null)
                e.Session["INSTALLDIR"] =
                    Path.Combine(site.Applications[0].VirtualDirectories[0].PhysicalPath, serviceName);
            MessageBox.Show("install dir set to : " + e.Session["INSTALLDIR"]);
            if (!e.IsUninstalling)
                MessageBox.Show(e.ToString(), "Load");
But installation fails with 2 errors:

Error: Could not access network location %SystemDrive%\inetpub\wwwroot\pdf.
Error: Could not access network location %SystemDrive%\inetpub\wwwroot\pdf.

I also ran msi installer from cmd which run under Administrator.
Aug 13, 2015 at 1:33 AM
Unfortunately your code is incomplete so I cannot compile it.

Anyway, just after inspecting your code I can say that I don't see anything obviously wrong with it. At least from Wix# point of view. However the error details you provided indicate that there is somewhere a routine that uses %SystemDrive% expandable environment variable. It is not user (your) code. At least not that part that you shared. It's not Wix# as it never uses this variable. So it might be WiX or that missing part of your code.

The easiest way to investigate it is to inspect the *.wxs file and see if %SystemDrive% was in fact injected there. This file is automatically be placed in the wix folder of your project. Though if you are not using Visual Studio to compile msi then you will need to prevent clearing this temporary file with project.PreserveTempFiles = true;.