[英]Getting Application path during the installation
我正在部署應用程序,並且在安裝過程中用戶選擇將應用程序安裝到哪里之后,我想獲得該路徑; 我已經在執行自定義操作,但是我不知道如何獲取將要安裝的應用程序路徑!
它是Windows窗體,我正在使用Visual Studio 2010“ C#”進行開發。
我正在使用默認的部署工具...
任何的想法?
提前致謝...
您的自定義操作所在的類應繼承自System.Configuration.Installer.Installer。 它上面有一個稱為Context的參數,該參數有一個Parameters字典。 該詞典包含許多有關安裝的有用變量,您可以添加一些變量。
在“自定義操作”窗格中將自定義安裝程序添加到安裝項目后。 選擇安裝操作,然后將CustomActionData屬性設置為:
/targetdir="[TARGETDIR]\"
然后,您可以像這樣訪問路徑:
[RunInstaller(true)]
public partial class CustomInstaller : System.Configuration.Install.Installer
{
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
string path = this.Context.Parameters["targetdir"];
// Do something with path.
}
}
我知道這是VB,但這對我有用。
Private Sub DBInstaller_AfterInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.AfterInstall
MessageBox.Show(Context.Parameters("assemblypath"))
End Sub
很抱歉將答案發布為舊帖子,但我的答案可能會幫助其他人。
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rkApp.GetValue("MyApp") == null)
{
rkApp.SetValue("MyApp", this.Context.Parameters["assemblypath"]);
}
else
{
if (rkApp.GetValue("MyApp").ToString() != this.Context.Parameters["assemblypath"])
{
rkApp.SetValue("MyApp", this.Context.Parameters["assemblypath"]);
}
}
}
public override void Uninstall(System.Collections.IDictionary savedState)
{
base.Uninstall(savedState);
rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rkApp.GetValue("MyApp") != null)
{
rkApp.DeleteValue("MyApp", false);
}
}
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.