Get user input during installation using setup project and use it in installer

后端 未结 1 1670
轻奢々
轻奢々 2021-01-24 02:14

I have created an installer to install a windows service. Installer should ask user to name the service. Hence, I have created a custom UI in the installer with TextBox

相关标签:
1条回答
  • 2021-01-24 02:46

    You need to follow these steps:

    1. Create a Windows Service project. It will create a service project containing Service1.cs.
    2. Open Service1.cs and right click and choose Add Installer. It will create a ProjectInstaller.cs.
    3. Add a new Setup Project. (If you don't have project template, download and install it from here for VS2013, VS2015 or VS2017)
    4. Add primary output of the service project to the setup project.
    5. Go to User Interface window and a new Dialog using TextBoxes (A) template after Installation Folder. (Set visible property of other textboxes than Edit1 to false.)
    6. Go to Custom Actions window and add a new custom action from primary output of the service project.
    7. In the Custom Action window, go to this node go to this node Custom ActionsInstallPrimary outputfrom WindowsService1 and in Properties window, set the value of CustomActionData to /SVCNAME=[EDITA1].
    8. Open ProjectInstaller.cs in your service project and override Install to set Name or DisplayName of the service:

      public override void Install(IDictionary stateSaver)
      {
          string value = Context.Parameters["SVCNAME"];
          this.serviceInstaller1.DisplayName = value;
          base.Install(stateSaver);
      }
      

    Then build your projects and install the service.

    0 讨论(0)
提交回复
热议问题