1

I am creating a batch file using wix light and candle to create an msi for a project.

I am receiving this error when i run the batch file:

light.exe : error LGHT0307 : Either 'Microsoft.Tools.WindowsInstallerXml.AssemblyDefaultWixExtensionAttribute' was not defined in the assembly or the type defined in extension 'C:\Users\User1\Documents\testProj\CustomAction\bin\Debug\CustomAction.dll' could not be loaded.

I have checked the filepath of the CustomAction.dll and verified it is correct. I have added the CustomAction.dll extension to the light command. I am running this batch file from the windows command line in administrator mode.

Batch File

----Line 1-----

"%WIX%bin\candle" *.wxs -dCustomAction.TargetDir="C:\Users\User1\Documents\testProj\CustomAction\bin\Debug\" -o obj\Debug\

----Line 2----------

"%WIX%bin\light" obj\Debug*.wixobj -ext "C:\Users\User1\Documents\testProj\CustomAction\bin\Debug\CustomAction.dll" -ext "C:\Users\User1\Documents\testProj\CustomAction\bin\Debug\CustomAction.CA.dll" -ext "C:\Program Files (x86)\WiX Toolset v3.11\bin\WixUIExtension.dll" -ext "C:\Program Files (x86)\WiX Toolset v3.11\bin" -ext WixIIsExtension -ext WixNetFxExtension -ext WixUIExtension -ext WixUtilExtension -ext "C:\Users\User1\Documents\testProj\Utils\bin\Debug\Utils.dll" -o obj\Debug\CommandLineInstaller.msi

I expect this to properly generate an msi file but i am receiving error code error LGHT0307.

I have removed CustomActino.dll and CustomAction.CA.dll from the candle command line. I have removed C:\Program Files (x86)\WiX Toolset v3.11\bin\WixUIExtension.dll and included -ext "C:\Program Files (x86)\WiX Toolset v3.11\bin" to the light command. Currently i am receiving this error " light.exe : error LGHT0144 : The extension 'C:\Program Files (x86)\WiX Toolset v3.11\bin' could not be loaded because of the following reason: Could not load file or assembly 'file:///C:\Program Files (x86)\WiX Toolset v3.11\bin' or one of its dependencies. Access is denied."

Here is the new command line: "%WIX%bin\light" obj\Debug*.wixobj -ext "C:\Program Files (x86)\WiX Toolset v3.11\bin" -ext "C:\Program Files (x86)\WiX Toolset v3.11\bin\WixUIExtension.dll" -ext "C:\Program Files (x86)\WiX Toolset v3.11\bin" -ext WixIIsExtension -ext WixNetFxExtension -ext WixUIExtension -ext WixUtilExtension -ext "C:\Users\User1\Documents\testProj\Utils\bin\Debug\Utils.dll" -o obj\Debug\CommandLineInstaller.msi

Atrax0331
  • 11
  • 3
  • [Please check if the fix in section two here works for you](https://stackoverflow.com/a/51777376/129130). Essentially: remove the project reference to **`Wix.dll`**. On second read that is probably something else, leaving this in still. – Stein Åsmul Sep 28 '19 at 00:32

2 Answers2

0

Custom Action DLLs: I think you might need to take out the CustomAction.dll entry in the light.exe command line. Maybe take out all entries and add back one entry at a time. See sample command lines below.

  • CustomAction.dll - Managed Code assembly dll
  • CustomAction.CA.dll - Win32 wrapper dll for managed code dll:CustomAction.dll

MakeSfxCA.exe: The latter one is what you should include in your MSI. The DTF (Deployment Tools Foundation) tool MakeSfxCA.exe creates this .CA version of your managed DLL. It contains all the necessary config files for your managed dll to run. You can open CustomAction.CA.dll with 7Zip or another, capable compression program to see the content.

Batch Build: Minimal command line to build WiX project (if you use a default WiX GUI) - and how-to make a simple WiX project in Visual Studio:

 candle.exe product.wxs -ext WixUIExtension
 light.exe -out Test.msi product.wixobj -ext WixUIExtension

Votive: I suppose you could try to build the WiX project in Visual Studio to see what command lines are used for candle.exe and light.exe in the built output window. That should give you a clue what might not be necessary (I suppose that might be what you already did):

Output


Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • I have removed the CustomAction.dll and CustomAction.dll from the light.exe command line. Now i am getting an errr LGHT 0144 The extension 'C:\Program Files (x86)\WiX Toolset v3.11\bin' could not be loaded because of the following reason: Could not load file or assembly 'file:///C:\Program Files (x86)\WiX Toolset v3.11\bin' or one of its dependencies. Access is denied. I have also tried to run the candle and light command lines visual studios creates and based my candle and light command lines off of it. – Atrax0331 Sep 30 '19 at 17:49
  • Maybe update question with new command line? I take it you haven't added ``"C:\Program Files (x86)\WiX Toolset v3.11\bin\`` to the path? You could temporarily try that. And then remove ``-ext "C:\Program Files (x86)\WiX Toolset v3.11\bin\WixUIExtension.dll"``. – Stein Åsmul Sep 30 '19 at 18:04
  • Most people use MSBuild - I believe - to build via the command line like that. [There is a section on using MSBuild in the WiX help material](https://wixtoolset.org/documentation/manual/v3/msbuild/). Hold on a second and I will create a better sample using regular batch files though. – Stein Åsmul Sep 30 '19 at 18:57
0

MSBuild: Most people use MSBuild - I believe - to build via the command line like that. There is a section on using MSBuild in the WiX help material.


Custom Action DLL: I include custom action DLLs from within the WiX source file. Here is a sample with hard coded paths in the WiX source file for how you can include your custom action dll:

The construct: $(env.SystemRoot) - in the WiX source below - gets the environment variable %SystemRoot% - which resolves to C:\ on most systems (to list environment variables open a cmd.exe and type set and press Enter). The below source should hence compile on all systems without modifications:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="SimpleCustomAction" Language="1033" Version="1.0.0.0"
           Manufacturer="-" UpgradeCode="">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />    
    <Feature Id="ProductFeature" Title="SimpleCustomAction" Level="1" />

<!-- START: Custom action entries -->
    
    <!-- Hard coded SourceFile path to compiled C# dll Win32 wrapper (MakeSfxCA.exe) -->
    <Binary Id="CustomActions" SourceFile="C:\CustomAction1.CA.dll" /> 

    <!-- BinaryKey => Use Binary element Id from above entry-->
    <!-- DllEntry => Exported method name inside dll (C# method name) -->
    <CustomAction Id="SimpleCustomAction" BinaryKey="CustomActions" DllEntry="CustomAction1"/>
    
    <!-- Run custom action -->
    <InstallExecuteSequence>
      <Custom Action="SimpleCustomAction" After="CostFinalize" />
    </InstallExecuteSequence>
    
<!-- END: Custom action entries -->    

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="SimpleCustomAction">
          <Component Feature="ProductFeature">
            <File Source="$(env.SystemRoot)\notepad.exe" />
          </Component>
        </Directory>
      </Directory>
    </Directory>

  </Product>
</Wix>

Batch Build: This should suffice, no need to specify anything in the candle.exe and light.exe commands to build the MSI. Here are some sample commands:

"%WIX%bin\candle.exe" product.wxs -ext WixUIExtension >> Build.log
"%WIX%bin\light.exe" -out Test.msi product.wixobj -ext WixUIExtension >> Build.log
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Thanks for the new suggestion. However it appears as though my prodct.wxs does have a hard coded path to the custom.ca.dll and runs the custom action. NOT Installed – Atrax0331 Sep 30 '19 at 21:21
  • This is just a sample of a WiX project that should compile with that batch file. Maybe try to compile that first to see if you can get a "heartbeat" as I call it. Then take it from there? – Stein Åsmul Sep 30 '19 at 21:26