Support for DifxApp/Driver Install

May 20, 2015 at 5:56 PM
Hi,

I went through the documentation and couldn't find any sample for installing a driver package. Is there support for driver installs (difx:driver XML tag), and if yes, can you show me an example of installing a driver package?

http://wixtoolset.org/documentation/manual/v3/xsd/difxapp/driver.html

Regards,
Mridul.
May 21, 2015 at 6:17 AM
There is no direct support for driver installation. So you have to inject it:
    project.WixExtensions.Add("WixDifxAppExtension.dll");
    project.WixNamespaces.Add("xmlns:difx=\"http://schemas.microsoft.com/wix/DifxAppExtension\"");
    project.Compiler.WixSourceGenerated += Compiler_WixSourceGenerated;
    project.Compiler.PreserveTempFiles = true;
        
    project.BuildMsi();
}
    
static void Compiler_WixSourceGenerated(System.Xml.Linq.XDocument document)
{
    XNamespace n = "http://schemas.microsoft.com/wix/DifxAppExtension";
    document.Descendants("File")
            .Single(e=>e.HasAttribute("Source", a=>a.EndsWith("MyDriver.sys"))) 
            .Parent
            .Add(new XElement(n + "Driver")
                        .AddAttributes("AddRemovePrograms=no; Legacy=no; PlugAndPlayPrompt=no; Sequence=1"));


Though you may need some further XML adjustments. I am not good at DifxAppExtension at all.
May 21, 2015 at 3:04 PM
Thank you for the reply. This is really useful information.

Out of curiosity, are there any plans to support DifxAppExtension natively in Wix#?

Regards,
Mridul.
May 22, 2015 at 12:15 AM
Honestly, until now I didn't have any plans for this. Tough I don't mind to include it particularly because extending the current solution seems to be straight forward.

Let's do this, test the approach I shred with you and when you are happy with the result send me your wxs file (or its simplified version) and I will incorporate the approach as a feature.

Cheers,
Oleg
Sep 24, 2015 at 8:12 AM
Edited Sep 24, 2015 at 8:14 AM
Добрый день Олег.
Скажите, пожалуйста, когда будет поддержка драйверов? Или помогите мне решить проблему.
Сделал установку драйвера как по коду выше:
project.WixExtensions.Add("WixDifxAppExtension.dll");
project.WixNamespaces.Add("difx=\"http://schemas.microsoft.com/wix/DifxAppExtension\"");
project.WixSourceGenerated += InstallSIA3Driver;
project.PreserveTempFiles = true;

return project.BuildMsm();

        private static void InstallSIA3Driver(XDocument document)
        {
                XNamespace difx = "http://schemas.microsoft.com/wix/DifxAppExtension";
                
                document
                    .FindAll("File")
                    .Single(e => e.HasAttribute("Source", a => a.EndsWith("usbser.sys")))
                    .Parent
                    .Add(new XElement(difx + "Driver")
                    .AddAttributes("AddRemovePrograms=no; DeleteFiles=no; Legacy=yes; PlugAndPlayPrompt=no; Sequence=1"));            
        }
Но при компиляции возникает ошибка:
Unresolved reference to symbol 'CustomAction:MsiProcessDrivers' in section 'Module:SIS3MergeModule'.

в wxs все нормально прописывается:
<Component Id="Component.usbser.sys" Guid="a19b5f60-0e64-402c-b898-4e7008035c4f">
  <File Id="usbser.sys" Source="...\usbser.sys" />

  <difx:Driver AddRemovePrograms="no" DeleteFiles="no" Legacy="yes" PlugAndPlayPrompt="no" Sequence="1" />
</Component>
Заранее спасибо.
Sep 24, 2015 at 8:56 AM
Sorry my Russian typing is rusty...

The Driver element is fairly simple and support for it seems to be straight forward. Thus I can add it very quickly. As long as I know what WXS and compilers invocation needs to be produced. And currently it isn't obvious.

I quickly generated the wxs very similar to yours and got the same error. Indeed wxs seems OK. Though I quick googling reviled that it is a common error when something is wrong with light.exe arguments or WiX bin content. It's hard for me to comment on this as I am no expert on WiX Driver and I guess you probably have a better background in this matter. Though you can help me with this.

If you execute the script below it will produce the wxs and the batch file for building msm. The batch file can be tweaked manually so you can try to find the right way of referencing DifxAppExtension.dll from light.exe. If you are successful then please share you findings and I can update Wix# with your solution to support Driver element so the feature is available in the next release (in a few days or so).
class Script
{
    static void Main()
    {
        var project = new Project("MyProduct",
                          new Dir(@"%ProgramFiles%\USBServ",
                              new File("usbser.sys")));

        project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");

        project.WixExtensions.Add("WixDifxAppExtension.dll");
        project.WixNamespaces.Add("difx=\"http://schemas.microsoft.com/wix/DifxAppExtension\"");
        project.WixSourceGenerated += InstallSIA3Driver;

        project.BuildMsmCmd();
    }

    static void InstallSIA3Driver(XDocument document)
    {
        XNamespace difx = "http://schemas.microsoft.com/wix/DifxAppExtension";

        document
            .FindAll("File")
            .Single(e => e.HasAttribute("Source", a => a.EndsWith("usbser.sys")))
            .Parent
            .Add(new XElement(difx + "Driver")
                     .AddAttributes(@"AddRemovePrograms=no;
                                      DeleteFiles=no; 
                                      Legacy=yes; 
                                      PlugAndPlayPrompt=no; 
                                      Sequence=1"));
    }
}
Sep 25, 2015 at 2:21 AM
OK, I found the solution.

Apparently light.exe has an unusual command-line convention for the WiX extensions dlls. Yes we all know that you need to pass the extension with the command line param -ext. However in case of WixDifxAppExtension.dll it isn't enough and difxapp_x64.wixlib needs to be passed as well. Wixlib is a collection of wixobjs. This is a bit unintuitive but it is what it is.

You can adjust your code as below and it will compile:
project.LightOptions += "\"" + System.IO.Path.Combine(Compiler.WixLocation, "difxapp_x64.wixlib") + "\" ";
project.BuildMsm();
The next release will have a new feature: support for WixLib files thus the you will be able to add libs as below:
project.LibFiles.Add(io.Path.Combine(Compiler.WixLocation, "difxapp_x64.wixlib"));
Saying that I will see if I can squeeze native support for Driver element in the next release.
Sep 25, 2015 at 6:56 AM
Спасибо большое, ты меня выручил.