Setup project with custom form

11,208

Solution 1

You can create custom forms but the declaration needs to be done inside MSI. You can show a custom dialog via a custom action but that will not help you much since msi does this:

  1. Load custom action dll
  2. If it is managed the CLR is started and your maanged code executed
  3. When the custom action is left the dll is unloaded and the clr is shut down

This is done every time a custom action is called. This is one of the main reasons why custom actions are normally written in C++.

To be more flexible you should use the WIX toolkit which allows .NET integration as good as it can be with MSI. MSI itself knows nothing about .NET and is a world of its own. MSI itself defines dialogs and controls inside the msi via tables like the Dialog and Control table. You could create a dialog and store your state in a msi property between each several msi actions which need to happen e.g. to calculate the disc space for the selected features and so on. But I doubt that this solution will be performant and I fear that starting and shutting down the CLR so often inside one process will expose you to CLR bugs that no one has encountered before.

To set the target location you only need to call the MSI method MsiSetTargetPath which you can PInvoke very easy.

To disable the normal UI you can override it completely or partially vis MsiSetExternalUI but I have not tried to disable only specific dialogs. If you want to hide specific dialogs you should check the msi tables of your current MSI to check if you can set a msi property to make the dialog think it has already been shown.

Yours, Alois Kraus

Solution 2

As far as I know the setup projects made by Visual Studio are very limited unless you use custom actions. These Custom Actions can take a lot of time to create and debug so it might be wiser to use a more mature/featured tools such as Installshield

EDIT As for showing windows using winforms: that is ok but: a nice setup allows a silent/scripted install, make sure you allow this. Another thing to look out for is machines not having .NET and thus not being able to show the Forms... IMHO that is a no-no unless you are sure .NET (correct version) is present.

EDIT 2 In response to some comments: There are some scenarios that can't be implemented with VISUAL STUDIO Setup and Deployment projects. I am not saying that Windows Installer is bad. E.g., Try to make a custom installer to decide where an application will be installed and skipping the standard window that the project generates. I am not saying that custom actions are limited but they are IMHO not easy either.

Also, when you want use custom WinForms instead of Installer forms you have to make sure that the bootstrap of the .NET framework is done BEFORE showing any (WinForm) windows. It might be possible but if you want such customisation you might be better of with a more flexible tool.

Share:
11,208
Rauland
Author by

Rauland

Updated on June 09, 2022

Comments

  • Rauland
    Rauland almost 2 years

    I’m currently working on a Visual Studio 2010 setup Project and would like to know if the following is possible:

    1) Run the setup project in a way that the default forms don’t show, instead I’d show my own custom form that subscribes to setup project events. This way I'd show install messages and increase my own progress bar.

    2) If 1 is possible, I would need a way to specify the default location.

    3) I have a separate library project, where I have a custom install class (inherits from “System.Configuration.Install.Installer”) from within the install handler I’d like to be able to show custom windows forms, and control choices made by the user. I guess this is possible by adding a reference to system.windows.forms, but would this be the correct way to go about this? If I couldn't hide the default install form, these custom forms would appear over the default install one and I think it would look too great.

    Suggestions, links etc appreciated Thanks!

    *UPDATE 1 *

    Could I launch an .msi from c# code but also passing in a value.?

    Just what this guy does here: link

    But passing in a value... then from my custom install class I take actions depending on this value.

    UPDATE 2

    Seems like I can: link code project

    UPDATE 3

    I'm considering in doing the following, I'll start testing with a winforms app.

    1) Launch winforms application.
    2) Make a few webService calls, display data, user makes selection.
    3) As per link in update 1, launch process(silent mode) and per update 2, pass in selected values.
    4) Use some cross process events mechanism (WCF) so that my custom install class can notify my form of the different steps its running and update progress bar and messages.

  • Emond
    Emond about 13 years
    Added info about using winforms
  • Rauland
    Rauland about 13 years
    @Erno Thanks,.. So if I use silent install, would my custom forms show? Could I control somehow, before install, if the correct .net version is present or not?
  • Emond
    Emond about 13 years
    that depends on how you create the setup. Setups have several sequences (install, deinstall, commit, ...) and also a silent/admin install. Do not use your forms in the silent install. You would have to add some bootstrapping to detect .NET: support.microsoft.com/kb/324733
  • Rauland
    Rauland about 13 years
    Thanks. (please excuse my little knowledge) You mention/recommend that I should use WIX. A quick look on wikipedia says: " The Windows Installer XML (WiX, pronounced "wicks"), is a free software toolset that builds Windows Installer (MSI) packages from an XML document", by reading this I feel that I'm back where I started. The VS2010 setup project generates .msi. Would WIX allow me to fully customize my .msi as I would like it? (Custom forms that may make webService calls, list options, take actions based on these options, copy files, log files, create database, perform rollbacks etc)
  • John Saunders
    John Saunders about 13 years
    @Erno: -1: custom actions are very easy to create in .NET. What makes you say they are difficult?
  • Grant Thomas
    Grant Thomas about 13 years
    Nothing immature/limited about Windows Installer/custom actions. And you can specify prerequisites of the application being installed and how to package them (download or local) - this will do the detection for you and install the required framework, if required.
  • Emond
    Emond about 13 years
    @John Saunders and Mr. Disappointment: Please see my second edit in the answer.
  • Grant Thomas
    Grant Thomas about 13 years
    @Emo: Re your second edit - still poppycock! Omitting default windows and implementing custom forms is no problem; bootstrapping .NET it simple and it is always installed as a prerequisite.
  • Emond
    Emond about 13 years
    @Mr. Dissapointment: I would love to see an example that shows I am wrong and I'll gladly accept it because I have been fighting with the Visual Studio Setup projects and resolved to switch to WIX.
  • Grant Thomas
    Grant Thomas about 13 years
    @Emo: I removed the part about a commercial product - but to be honest, I might put the time in to set up a personal example (when the kids aren't running the show as they are this morning!)
  • Emond
    Emond about 13 years
    @Mr. Disappointment: that would be great. All custom WinForm windows, bootstrapping the correct version of .NET and working on a machine that doesn't have .NET installed...
  • John Saunders
    John Saunders about 13 years
    @ebb: how does this address you statement that custom actions are difficult?
  • Alois Kraus
    Alois Kraus about 13 years
    Yes you have full freedom to do anything what MSI allows you. But the WIX dialogs are also based on the msi Dialog and Control tables. But you have the advantage to declare them in XML instead of the msi tables which is easier to do. But it does (at least to my knowledge) not help you to replace the msi dialogs with a .Net based Windows Form.
  • Emond
    Emond about 13 years
    First: I never said difficult, just that some scenarios are easier with other tools and debugging installers is in my experience not easy.