问题
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
回答1:
Custom Action DLLs: I think you might need to take out the
CustomAction.dll
entry in thelight.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 dllCustomAction.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):
Links:
- Please see this similar, but slightly different issue
回答2:
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 toC:\
on most systems (to list environment variables open acmd.exe
and typeset
and pressEnter
). 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
来源:https://stackoverflow.com/questions/58141164/light-exe-error-lght0307-microsoft-tools-windowsinstallerxml-assemblydefaultwix