util:EventSource

Oct 21, 2016 at 10:54 AM
Hi,

is there a way to register an event source in WixSharp?

I need something like this:

<Util:EventSource
xmlns:Util="http://schemas.microsoft.com/wix/UtilExtension"
Name="ROOT Builder"
Log="Application"
EventMessageFile="%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll"
/>
Coordinator
Oct 22, 2016 at 4:41 AM
Hi there,

No there is no direct equivalent for this. Though you can still embed this functionality into your setup. You can add it directly into your setup definition as a raw XML fragment, WixFragment or external WiX extension. Have a look at InjectXML sample. Below is an inaccurate code snippet just from the top of my head:
project.IncludeWixExtension(WixExtension.Util)
       .AddWixFragment("Wix/Product", XElement.Parse(@"
                       <Util:EventSource xmlns:Util=""http://schemas.microsoft.com/wix/UtilExtension"" 
                           Name=""ROOT Builder"" 
                           Log=""Application"" 
                           EventMessageFile=""%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll""
                       />"));
Though Element business logic seems very straight forward and useful so please log it as a feature request.
Coordinator
Oct 22, 2016 at 5:12 AM
Edited Oct 22, 2016 at 5:22 AM
My bad... While my post above is absolutely correct I completely forgot another, much better approach. You can use a IGenericEntity interface that dramatically simplifies adding support for simple elements (as EventSource).

Define a new class for non supported element:
public class EventSource : WixEntity, IGenericEntity
{
    [Xml]
    new public string Name;
    [Xml]
    public string Log;
    [Xml]
    public string EventMessageFile;

    public void Process(ProcessingContext context)
    {
        var util = WixExtension.Util;

        context.Project.IncludeWixExtension(util);
        context.XParent
               .FindSingle("Component")
               .Add(this.ToXElement(util.ToXName("EventSource")));
    }
}
And now your element is fully supported:
var project =
    new Project("MyProduct",
        new Dir(@"%ProgramFiles%\My Company\My Product",
            new EventSource
            {
                Name = "ROOT Builder",
                Log = "Application",
                EventMessageFile = @"%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll"
            },
            new File...
You can read more about this technique here: https://wixsharp.codeplex.com/wikipage?title=WixSharp%20extensions

If you end up adding the rest of missing element attributes/properties you can share your class with me and I can include it to the product so others can benefit fro EventSource support too.

Cheers,
Oleg
Oct 22, 2016 at 5:17 AM
Thx Oleg
for your very good support.
Always appreciated!

Regards
Martin