问题
Let's say, for example, my application supports Epson printers and Canon printers.
I would like to have an option during installation, maybe radio buttons or, better, checkboxes (to have an option to choose both) that would say 'Install Epson drivers' and 'Install Canon drivers'.
Then, based on user selection, the setup package would install either only Epson drivers, or only Canon drivers, or both.
I guess what I want can also be described as having several prerequisites, but make them optional.
Any suggestions on where to begin?
回答1:
Looks like what I need cannot be done from VS Setup and Deployment, as I'm trying to run an msi from msi, which is not permitted. So as a workaround I had to create a small 'wrapper' Windows Forms application with a few checkboxes and a function like this
private void InstallComponent(string filePath)
{
System.Diagnostics.Process installerProcess;
installerProcess = System.Diagnostics.Process.Start(filePath);
while (installerProcess.HasExited == false)
{
//indicate progress to user
Application.DoEvents();
System.Threading.Thread.Sleep(250);
}
}
and the 'Install' button that would do something along the lines of
private void buttonInstall_Click(object sender, EventArgs e)
{
if (checkBoxCanonDrivers.Checked)
{
InstallComponent("CanonSetup.exe");
}
if (checkBoxEpsonDrivers.Checked)
{
InstallComponent("EpsonSetup.exe");
}
// ............
InstallComponent("MyMainApplicationSetup.exe");
}
Now off to make this app flexible, like reading setup file locations from an XML file etc, but that is outside the scope of the question ...
回答2:
I think you can do this in a Visual Studio deployment project, at least for simple cases (up to 4 checkboxes, I think, but I may be wrong). See this MSDN article: Checkboxes User Interface Dialog Box; it explains how to present a dialog box with checkboxes during installation and include or exclude files based on checkbox selection.
来源:https://stackoverflow.com/questions/576457/visual-studio-setup-and-deployment-create-package-with-optional-components