2010-02-10 28 views
2

我做了一个简单的安装类:C#安装类

[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); 

      } 
     } 
    } 
} 

在我安装项目我已经做了以下内容:

  • 添加项目输出 - 的主要输出我装配
  • 添加自定义操作上安装目录(自定义操作查看)
  • 集CustumActionData到 '/ TARGETDIR = “[TARGETDIR] \”'
  • 构建我的程序集并构建安装项目

在安装期间,不引发Exception。为什么不?看来我的班级没有被调用。我在这里做错了什么?

UPDATE

当我创建一个单独的项目,只有在它的安装程序类,这ONT添加到我的项目输出中并正确设置动作俗,我得到的例外!

现在我想知道为什么这个相同的文件没有得到我自己(的WinForms)组件调用..

+1

只是一个方面说明:你应该真的使用你的一次性资源,而不是像这样调用Dispose。 –

+1

Thnx为提示。我修改了我的代码。 – Martijn

+0

与'FileStream'相同,请' –

回答

0

你曾经通过

[runInstaller的(真)]

装饰了你的班?

+0

是的,我有,但我没有得到例外 – Martijn

+0

看到我的startpost。 – Martijn

0

我有,当我试图解决同样的问题的一些注意事项:

安装在Vista确保您 从开始的Setup.exe,而不是从 微星

即使你在XP上,也许你应该尝试从setup.exe运行。