How to use corporate library registration in a .NET custom action

I have some library code that is used from my application, and also used by a special .NET action in the Visual Studio installer project. In turn, the library code uses the Enterprise Library logging block for logging. How to get configuration information in a corporate library in the context of my user action running inside msiexec? Is it possible to reload the configuration mechanism in the code before I make any EntLib calls?

Update: I created a hack that seems to work, but relies on setting a non-public static field using reflection. It's a shame that EntLib is so closely related to the .NET ConfigurationManager.

var factory = new LogWriterFactory( new FakeConfigSource( "foo.config" ) );
var field = typeof ( Logger ).GetField( "factory", BindingFlags.Static | BindingFlags.NonPublic );
field.SetValue( null, factory );
Logger.Write( "Test" );

Update 2: Although this hacking works in a test bench, when launched in the msiexec context, the assembly loader does not find the assemblies specified in the configuration file. Fuslogvw indicates that AppBase is the windows32 system directory, which makes sense. I don’t understand why the manifest dependencies of the assembly of custom actions were found (which are located in the [TargetDir] directory along with the assembly of custom actions), but dynamically loaded assemblies called in the configuration file are not. I see no way around this.

+5
5

app.config, app.config - msiexec.config, MSI. , , XML MSI.

+1

, , LoadFrom context, .

, , AppDomain. reset , App.config .. AppDomain.CreateDomain(String, Evidence, AppDomainSetup), AppDomain, AppDomainSetup ApplicationBase, ConfigurationFile ..

+1

, , msi . ( VBScript :)

Const msiMessageTypeInfo = &H04000000
Const msiMessageTypeFatalExit = &H00000000
Const msiMessageTypeError = &H01000000
Const msiMessageTypeWarning = &H02000000
Const msiMessageTypeUser = &H03000000 

Dim rec : Set rec = Session.Installer.CreateRecord(1)
rec.StringData(1) = "Your log message."

Session.Message msiMessageTypeInfo, rec

MSDN: http://msdn.microsoft.com/en-us/library/aa371672.aspx

0

, msiexec . , . , .

string installDir = System.IO.Path.GetDirectoryName(
                System.Reflection.Assembly.GetExecutingAssembly().Location);
System.IO.File.Copy(
                System.IO.Path.Combine(installDir, "<Insert Assembly Name>.dll"),
                System.IO.Path.Combine(Environment.SystemDirectory, "<Insert Assembly Name>.dll"),
                true);

- GAC. , msi, - Orca, GAC, .

- , , .

0

This can help people who are still dealing with VS installers: you can use dynamically loaded assemblies from a custom action, you just need to help the build runtime.

How do you do this by handling the event AppDomain.AssemblyResolve. I did this according to the method of Installmy installer class, for example:

internal class MyInstaller : Installer
{
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);

        AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
        {
            // Resolve assemblies here, e.g.:
            return
                args.Name == "My.Assembly"
                ? Assembly.LoadFrom(this.Context.Parameters["TARGETDIR"] + "\\My.Assembly.dll")
                : null;
        };

        // Continue install...
    }
}

I would recommend reading the MS Docs page when implementing a handler .

0
source

All Articles