从C#自定义操作获取SourceDir属性 [英] Getting the SourceDir property from a C# custom action

查看:142
本文介绍了从C#自定义操作获取SourceDir属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的安装程序捆绑了一些目录,我需要在自定义操作中访问它们.我进行了一些研究,发现SourceDir可用于获取当前正在执行的目录位置.但是,我找不到如何获取此属性的任何示例?还是获取当前目录的另一种方法?

I have some directories that are bundled with my installer and I need to access them from within a custom action. I have done some research and seen that the SourceDir can be used to obtain the currently executing dir location. However I cannot find any examples of how to obtain this property? Or another way to obtain the current directory?

除了无用的Microsoft网站外,有人可以建议或指向我吗?

Can anyone advise or point me to anything other than the unhelpful Microsoft site?

推荐答案

对于C#,您会发现可以执行以下操作:

For C#, you'll find that you can do something like this:

[CustomAction]
public static ActionResult MyCustomAction(Session session)
{
    string sourceDir = session["SourceDir"];
    string path = Path.Combine(sourceDir, "yourfilename.txt");
    ...

不幸的是,在MSDN上缺少文档

The documentation on MSDN is unfortunately lacking in making this clear.

正如w4g3n3r在他的回答中提到的那样,SourceDir仅在特定时间提供给您.简而言之,您需要确保在对ResolveSource操作的调用后 后调用自定义操作,该操作只能在CostInitialize运行后才能调用.

As w4g3n3r mentions in his answer, SourceDir is only available to you at certain times. In short, you will need to make sure your custom action is called after a call to the ResolveSource action, which can only be called after CostInitialize has run.

一旦设置了SourceDir,它就可以在其余的安装过程中使用.

Once SourceDir is set, it should be available for use for the remainder of the installation process.

这篇关于从C#自定义操作获取SourceDir属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆