简体   繁体   English

使用WiX将参数传递给Windows Service的安装程序类

[英]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=&quot;NFeConnector2&quot; " />

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.

相关问题 保存 Windows 服务的属性(Wix 安装程序) - Save properties of windows service (Wix Installer) 如何将数据从安装程序 class 传递到 windows 服务的 OnStart() 方法 - How to pass data from an installer class to the OnStart() method of a windows service Wix是用于以编程方式创建此Windows Service安装程序的正确技术吗? - Is Wix it the correct technology to use for programmatically creating this Windows Service installer? 基于 Wix 安装程序的 TopShelf Windows 服务无法启动 - Wix installer based TopShelf windows service fails to start WIX 服务安装程序覆盖服务安装程序设置 - WIX service installer overrides service Installer settings 如何将参数传递给Windows服务 - How to pass in arguments to Windows service Windows Service无法在安装WiX / IsWix上启动。 验证您是否具有足够的特权。 InstallShield转Wix安装程序 - Windows Service fails to start on install WiX/IsWix. Verify that you have sufficient privileges. InstallShield to Wix installer SQL 来自.Net 5 Windows 服务的登录问题,但不是来自通过 Wix 安装程序安装的控制台 - SQL Login issue from .Net 5 Windows service but not from console installed via Wix installer 从WiX安装程序传递标志到合并模块? - Pass flag to merge module from WiX installer? Wix安装程序-服务无法启动-缺少参考? - Wix installer - service not starting - missing references?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM