VS 设置项目自定义操作 C#
你好 我有来自 ms 站点的以下代码,我想在代码中设置安装路径(不要问,但相信我,我需要!)
那么如何从自定义操作访问和设置安装路径?
public partial class Installer1 : System.Configuration.Install.Installer
{
public Installer1()
{
InitializeComponent();
//need code to set the installation path
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
System.Diagnostics.Process.Start("http://www.microsoft.com");
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
}
Hi
I have the following code from the ms site and I want to set the installation path from with in code (don't ask but trust me I need to!)
so how do I access and set the installation path from a custom action?
public partial class Installer1 : System.Configuration.Install.Installer
{
public Installer1()
{
InitializeComponent();
//need code to set the installation path
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
System.Diagnostics.Process.Start("http://www.microsoft.com");
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能这样做...因为自定义操作是在从 MSI 安装文件并将其设置到安装路径后发生的。否则,如何调用自定义操作?它们在可供 .NET 安装 API(installUtil 使用)使用后执行。因此,您实际上必须安装到某个路径,然后再移动它们。现在,可能有一种方法可以通过 InstallShield 或您可以使用的任何安装工具集来编写脚本,但通过 .NET 自定义操作,您有一定的限制。 (另一个此类限制是在安装实际将文件解压缩到某个位置之前,根据安装向导中的输入参数修改配置文件。)
You can't do that ... because the custom actions occur after the files have been installed from the MSI and set into the installation path. Otherwise, how could the custom actions be invoked? They are executed after they are available to the .NET installation APIs (which installUtil uses). So, you'd actually have to install to some path, then move them afterwards. Now, there's probably a way to do it via InstallShield or whatever installation toolset you may be able to get your hands on, to script it, but through .NET custom actions, you have certain limitations. (Another such limitation is modifying a configuration file based on input parameters from the installation wizard, before the installation has actually extracted the files to someplace.)
您可以这样做,
如果您想访问自定义安装程序类中的安装路径,您的第一直觉是使用 [TARGETDIR] 或 [INSTALLDIR] 作为自定义操作。
唉,这行不通,这将在执行自定义操作后填充
那么如何呢?
string applicationInstalledPath = Context.Parameters["AssemblyPath"] 将获取安装的目录。
You can do this,
If you want to access the installation path in your custom installer class, your first instinct is to use a [TARGETDIR] or [INSTALLDIR] as a custom action.
Alas, this wont work, this will be populated after the custom action is executed
So how ?
string applicationInstalledPath = Context.Parameters["AssemblyPath"] will fetch the installed directory.