我做了一个简单的安装类: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)组件调用..
只是一个方面说明:你应该真的使用你的一次性资源,而不是像这样调用Dispose。 –
Thnx为提示。我修改了我的代码。 – Martijn
与'FileStream'相同,请' –