开发者

C# Install class isn't executed

I've made an simple installation class:

[RunInstaller(true)]
public class MyCustumAction : Installer
{
    public override void Install(System.Collections.IDictionary stateSaver)
    {
        base.Install(stateSaver);
        string value = Context.Parameters["targetdir"];

        throw new Exception("Contact?? " + value);

        WriteLog(value);
    }

    private void WriteLog(string message)
    {
        using(FileStream f = File.Create(@"C:\ik ben nieuw.txt"))
        {
            using (StreamWriter w = new StreamWriter(f))
            {
                w.WriteLine("Dag van installatie: " + DateTime.Now.ToString());
                w.WriteLine(message);

            }
        }
    }
}

In my Setup project I've done the following:

  • Add project output - primary output of my assembly
  • Add a Custom Action on the Install directory (Custom Actions view)
  • Set CustumActionData to '/targetdir="[TARGETDIR]\"'
  • Build my assembly and build the setup project

During the installation, the Exception is not thrown. Why not? It seems that my class isn't invoked. What am I doing wrong here?

UPDATE

When I create a seperate project with only the install开发者_如何学运维er class in it and add this ont to my project ouput and set the custum action properly, I do get the exception!

Now I am wondering why this same file doesn't get invoked in my own (winforms) assembly..


You need to decorate your class with the RunInstaller attribute. This provides more detail.

http://msdn.microsoft.com/en-us/library/system.componentmodel.runinstallerattribute.aspx


Have you decorated your class with

[RunInstaller(true)]

?


I have some notes from when I was trying to solve this same problem:

to install on Vista ensure you initiate from the Setup.exe, not from the Msi

Even if you are on XP perhaps you should try running from the setup.exe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜