Kei*_*thS 15 .net c# installer custom-action
首先,是的,我知道VS Setup Projects是邪恶的.这就是我必须要做的事情.我还看到了几个相关的问题,但是他们要么没有得到答复,要么他们的情况与我的情况不符,足以让他们找到工作的答案(或者他们对VS Setup Projects和WiX的奇迹有所了解).
我有一个应用程序的安装项目.它可以很好地复制文件,但我需要在复制文件后执行两个自定义操作.我创建了一个安装程序类,并将其设置为安装项目中的自定义操作,并且它的框架(没有工作,只显示一个对话框,所以我可以附加调试器并环顾四周)工作得很好.然后,我发现我需要将参数从MSI传递到我的自定义操作,以便我可以通过安装程序类的Context属性访问它们.
这是安装程序类的当前代码(某些名称已被更改以保护无辜者).它基本上什么都不做,只是在正确的时间显示一个对话框(在复制文件之后但在提交安装之前):
namespace MyApp.Install.CustomSetup
{
[RunInstaller(true)]
public partial class MyAppCustomInstallActions : System.Configuration.Install.Installer
{
public MyAppCustomInstallActions()
{
InitializeComponent();
}
protected override void OnAfterInstall(IDictionary savedState)
{
try
{
base.OnAfterInstall(savedState);
if (MessageBox.Show(
"Custom Action OnAfterInstall successfully integrated. You can attach a debugger if desired. Do you wish to perform the custom actions?",
"DEBUG", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
SetEditablePermissionOnFolder(savedState);
SetApplicationSettingsFromWizard(savedState);
}
catch (Exception ex)
{
Context.LogMessage(ex.ToString());
throw;
}
}
private void SetApplicationSettingsFromWizard(IDictionary savedState)
{
//TODO: Implement
}
private void SetEditablePermissionOnViewerFolder(IDictionary savedState)
{
//TODO: Implement
}
}
}
Run Code Online (Sandbox Code Playgroud)
计划是让自定义操作正常工作,然后取出对话框就行了.
以下是CustomActionData的字符串,用于安装项目的自定义操作的Install操作:
/phonenumber=[phonenumber] /thirdpartyinstallpath1="[thirdpartyinstallpath1]\" /thirdpartyinstallpath2="[thirdpartyinstallpath2]\" /thirdpartyinstallpath3="[thirdpartyinstallpath3]\"
Run Code Online (Sandbox Code Playgroud)
如果我不使用这个参数字符串,它没关系,但我没有参数.如果我确实指定了此字符串,则安装程序会在我自己的对话框出现之前失败,并出现两个错误:"Exception occurred while initializing the installation: Could not load file or assembly 'file:///C:\Windows\SysWOW64\Files' or one of its dependencies. The system cannot find the file specified"和"Error 1001. Could not find file C:\Program Files (x86)\MyCompany\MyApp\MyApp.Install.CustomSetup.InstallState".
我究竟做错了什么?我做错了吗?有没有一个解决方案不需要我使用一些不同的框架重新创建安装程序?
编辑:我发现删除除电话号码参数以外的所有内容,并将[PHONENUMBER]放在引号中,允许传递该参数.但是,我无法传递任何目录路径; 我尝试了[INSTALLDIR]确切地说几个博客和演练如何做到这一点,没有骰子.
我发现问题是参数字符串的格式.因为各种参数虽然是文件路径,但是包含文件名而不是以反斜杠结尾,所以我不需要使用尾部反斜杠来结束这些值字符串.因为无论如何,结尾引号被视为字符串的一部分,这使得解析器使用下一个开头引号作为前一个值的结尾,破坏了整个参数字符串.因此,无法正确编写InstallState,并且在自定义安装逻辑尝试使用它时失败.