Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Install 2 windows services in same installer #552

Closed
Torchok19081986 opened this issue Dec 13, 2018 · 8 comments
Closed

Question: Install 2 windows services in same installer #552

Torchok19081986 opened this issue Dec 13, 2018 · 8 comments

Comments

@Torchok19081986
Copy link

Hallo, how to you ServiceInstaller for install 2 different windows services or use installutil.exe twice ?
Is there some posibility ?

@Xaddan
Copy link
Contributor

Xaddan commented Dec 26, 2018

new File("Svr1.exe",
  new ServiceInstaller
  {
    Name = "Svr1",
    DisplayName = "Svr1",
    Description = "Svr1",
    StartOn = SvcEvent.Install_Wait,
    DependsOn = ServicesName,
    StopOn = SvcEvent.InstallUninstall_Wait,
    RemoveOn = SvcEvent.Uninstall_Wait,
    DelayedAutoStart = true,
    StartType = SvcStartType.auto,
    FirstFailureActionType = FailureActionType.restart,
    SecondFailureActionType = FailureActionType.restart,
    ThirdFailureActionType = FailureActionType.restart,
    RestartServiceDelayInSeconds = 10,
    ResetPeriodInDays = 1,
    RebootMessage = "Failure actions do not specify reboot",
  }),
new File("Svr2.exe",
  new ServiceInstaller
  {
    Name = "Svr2",
    DisplayName = "Svr2",
    Description = "Svr2",
    StartOn = SvcEvent.Install_Wait,
    DependsOn = ServicesName,
    StopOn = SvcEvent.InstallUninstall_Wait,
    RemoveOn = SvcEvent.Uninstall_Wait,
    DelayedAutoStart = true,
    StartType = SvcStartType.auto,
    FirstFailureActionType = FailureActionType.restart,
    SecondFailureActionType = FailureActionType.restart,
    ThirdFailureActionType = FailureActionType.restart,
    RestartServiceDelayInSeconds = 10,
    ResetPeriodInDays = 1,
    RebootMessage = "Failure actions do not specify reboot",
  }),

@grahamcarson
Copy link

This doesn't work. You end up with the Component element for both services having a ServiceControl element with an Id of StartSvr2. This generates an error when Wix tries to interpret the wxs file and no msi is created.

There are 2 factors to this:
SvcEvent.Install_Wait is a static instance so all ServiceInstallers have a reference to the same instance.
The setter for the StartOn property modifies the Name and Id of the passed in SvcEvent. This means that the SvcEvent that all ServiceInstallers share ends up with the Name and Id of the last service it was passed to.

The same thing happens with StopOn and RemoveOn.

The solution I have used is to create new instances of SvcEvent for each ServiceInstaller. As SvcEvent has a private constructor and one of the properties that needs setting is protected this requires some rather nasty reflection.

I don't think that the setter of OnStart should be modifying the object passed into it.

@Xaddan
Copy link
Contributor

Xaddan commented Jan 18, 2019

Oleg, you did not upload commits 556bc4e and 6007f95 from the wix-3.11 branch to the master branch.

@oleg-shilo
Copy link
Owner

It is a very interesting one.

SvcEvent.Install_Wait is a static instance so all ServiceInstallers have a reference to the same instance.

Actually it is not the same instance. These are the static properties the return a fresh new instance of the class on every access:

image

I still don't see a good reason for keeping constructor private but it is a different story.

Please share your Reflection based solution so I can see what can be done to solve this problem.

@oleg-shilo
Copy link
Owner

oleg-shilo commented Jan 18, 2019

@Xaddan thank you, looking into it

@oleg-shilo
Copy link
Owner

Yep 556bc4e was not merged. Now fixed.
But 6007f95 was in. That's the test screenshot above shows theSame as false.

Anyway 556bc4e is a vital one. Will aim for a release over weekend.

@grahamcarson
Copy link

I am using v1.9.3.0 of WxisSharp. In this version SvcEvent.InstallUninstall_Wait is a public field rather than a public property. This means that all the ServiceInstallers will have the same instance.
v1.9.3.0 is the latest available on nuget, do I need a later version ?

oleg-shilo pushed a commit that referenced this issue Jan 18, 2019
- Issue #552: Question: Install 2 windows services in same installer
@oleg-shilo
Copy link
Owner

Done. Will be available in the very next release

oleg-shilo pushed a commit that referenced this issue Jan 19, 2019
* VS project templates - added packages.config files
* Added Condition-s for .NET Frameworks 4.7.1 and 4.7.2
* Issue #569: Updating WixSharp leads to malfuncion of SetEvVar
* Added support for `UI.Error` WiX element
* Issue #552: Question: Install 2 windows services in same installer
* Issue #541: Installing 2 Services in the same installer results in …
* Samples update
* Issue #560: Semantic difference between UninstallCondition and IsUninstalling
* Issue #564: Correct variable name of SequentialGuid initialization.
* Issue #562: Typo in Compiler.cs comments
* Issue #561: Typo in WixProject.cs
* Added missing namespace in custom dialog template, fixed comment.
* Added explicit `WixEntity.ComponentId` property
* Issue #551: Cannot include extra .wxs as part of a bundle
* Issue #542: ServiceInstaller.StartOn/StopOn/RemoveOn - Documentation bug
* Issue #544: Failed while processing WebSites; added support for `IISVirtualDir.AttributesDefinition`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants