Error with Custom Action in Visual Studio 2008
I'm very new in C# world though I'm trying to modify an installer using custom action. What I'm trying to do is to run a batch script after installation finishes. I'm using the following Installer class:
namespace PostInstall
{
[RunInstaller(true)]
public partial class Installer1 : Installer
{
public Installer1()
{
InitializeComponent();
System.Diagnostics.Process.Start("PostInstall.bat");
}
}
}
A project named PostInstall contains a *.cs file with the code above. The project is created following this link's section "To create the custom action". In the setup project, I've added the primary output of PostInstall project in Install & Commit node as described in the link.
Yet at the end of the installation the following error is received:
Error 1001. Unable to create an instance PostInstall.Installer1 installer type -> Exception has been thrown by the target of an invocation. -> The system can't find the file specified.
I verified that PostInstall.bat
exists in the installation direc开发者_开发百科tory. Why the error is occurring and how to resolve it?
I think the installation directory is not automatically the directory in which the installer is run, so you cannot assume that Process.Start("PostInstall.bat")
will find the batch file.
This DevCity article is a very good introduction to this topic, and tells you how to get the installation directory passed to your custom action objects so that you can create the full pathname for your batch file.
Have you thought about what will happen while your batch file is running? Do you want to wait until it is finished before proceeding to the next stage of your installation?
Ideally the custom actions should be written in native code, if it's not possible in your case try to run the .msi as Administrator
精彩评论