[英]Pass arguments to Installer Class of Windows Service with WiX
I'm migrating a Windows Service from Visual Studio 2010 to VS2012 and, as this one does not support Visual Studio Setup Projects, I'm trying to recreate my Setup project using WiX. 我正在将Windows服务从Visual Studio 2010迁移到VS2012,并且由于该服务不支持Visual Studio安装项目,因此我尝试使用WiX重新创建我的安装项目。
On VS2010, I used the standard Textboxes forms from the User Interface to pass some parameters to my Installer Class that would use this information to instantiate a DbContext of Entity Framework and deploy the Database with the ObjectContext.CreateDatabase() method. 在VS2010上,我使用了用户界面中的标准“文本框”表单将一些参数传递给我的安装程序类,该参数将使用此信息来实例化Entity Framework的DbContext并使用ObjectContext.CreateDatabase()方法部署数据库。
Here is an excerpt of how I do this on my Installer Class: 这是我如何在安装程序类中执行此操作的节选:
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
string dataSource = string.IsNullOrEmpty(Context.Parameters["DataSource"]) ? "." : Context.Parameters["DataSource"];
// some more code...
}
Is it possible to specify this parameters with WiX? 是否可以使用WiX指定此参数?
I was trying to do it by passing the parameters on the "Argument" parameter of the WiX's Xml, but the installer doesn't seem to accept it (it does not accuse any errors, but acts as if I was not passing any parameter at all. 我试图通过在WiX的Xml的“ Argument”参数上传递参数来执行此操作,但是安装程序似乎不接受它(它不表示任何错误,但表现得好像我没有在处传递任何参数一样)所有。
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="NFeConnectorService"
DisplayName="NFeConnector Service"
Description="Servico de Mensageria para NFe"
Start="auto"
Account="LocalSystem"
ErrorControl="ignore"
Interactive="no"
Arguments="/InitialCatalog="NFeConnector2" " />
I've also tried with the following syntaxes without success: 我还尝试了以下语法,但未成功:
Arguments="/InitialCatalog=NFeConnector2"
Arguments="InitialCatalog=NFeConnector2"
Does anyone have any idea on how can I pass this arguments to my Installer Class? 有谁知道如何将这些参数传递给Installer类?
It's unlikely you'll get this to work. 您不太可能使它正常工作。 The issue is that Visual Studio installer classes are not called directly by Windows Installer. 问题是Windows Installer不会直接调用Visual Studio安装程序类。 There's an undocumented interface that calls a C++ Dll that then calls your assembly and installer class via reflection. 有一个未记录的接口,该接口调用C ++ Dll,然后通过反射调用您的程序集和安装程序类。 VS generates a call to this C++ Dll passing some undocumented parameters concatenated with your string. VS生成对此C ++ Dll的调用,并传递一些未记录的参数,这些参数与您的字符串连接在一起。 I don't know what you've tried, but unless you have reverse engineered these calls and inluded the C++ Dll, figured out the Dll entrypoints and parameters then it won't work. 我不知道您尝试了什么,但是除非您对这些调用进行了反向工程并包含了C ++ Dll,弄清了Dll入口点和参数,否则它将无法工作。
The short answer is don't bother. 简短的答案是不要打扰。 Installer classes are only a Visual Studio thing, which is why they don't migrate. 安装程序类只是Visual Studio的东西,这就是为什么它们不迁移的原因。 WiX has support for C# custom actions (see things like WIX - Adding a C# custom action code ) and get away from installer classes. WiX支持C#自定义操作(请参阅WIX-添加C#自定义操作代码 ),并且摆脱了安装程序类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.