WiX 安装程序 msi 未安装使用 Visual Studio 2017 创建的 Winform 应用程序 [英] WiX installer msi not installing the Winform app created with Visual Studio 2017

查看:31
本文介绍了WiX 安装程序 msi 未安装使用 Visual Studio 2017 创建的 Winform 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了进行简单的测试,我为一个简单的 Winform 应用程序创建了一个 Wix 安装程序应用程序,如下所示.但是当我运行用安装程序创建的 msi 时,它只运行一秒钟,然后退出而不安装 Winform 应用程序.问题:这里可能有什么问题?我的 Product.wxs 文件中似乎缺少某些内容.注意:我使用的是 VS2017

For a simple test I created a Wix installer app for a simple Winform app as follows. But when I run the msi created with the installer it runs for just one second and exits without installing the Winform app. Question: What could be the issue here? It seems something is missing in my Product.wxs file. Note: I'm using VS2017

产生问题的步骤

  1. 此处
  2. 安装了Wix Toolset Visual Studio 2017 Extension/a> 并按照他们的说明从 此处WiX 3.11 RC2莉>
  3. 创建了一个默认的 Winform 项目 [只有一个表单,没有添加任何内容]
  4. 在同一解决方案中使用 Toolsetv3Setup Project 模板创建了一个 Wix 安装项目
  5. 在 WiX 安装项目中添加了对 Winform 项目的引用
  6. 构建整个解决方案.
  7. 右键单击安装项目并重新构建它,在其 ..binDebug 文件夹中创建了一个 .msi 文件
  8. 双击第 6 步中的 .msi 文件.文件运行一秒钟,出现 Windows 10 安装对话框(任何安装都会出现,询问您是否要安装此程序).我点击了Yes.安装程序再次运行一秒钟然后退出.但未安装 Winform 应用.
  1. Installed Wix Toolset Visual Studio 2017 Extension from here and followed their instructions to install WiX 3.11 RC2 from here
  2. Created a default Winform project [just one single form nothing added to it]
  3. Created a Wix Setup project by using Toolsetv3Setup Project template in the same solution
  4. In WiX Setup project Added a reference to Winform project
  5. Built the entire solution.
  6. Right clicked the Setup project and re-built it that created an .msi file in its ..binDebug folder
  7. Double clicked the .msi file from step 6. File ran for one second, windows 10 installation dialog appeared (as it appears for any installation asking you if you want to install this program). I clicked Yes. Installer ran for one second again then exited. But the Winform app was not installed.

默认的 Product.wxs 文件 [我这里没有添加任何东西,只是给 Manufacturer 属性添加了一个值]

Default Product.wxs file [I did not add anything here except for adding a value to Manufacturer attribute]

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="SetupProject1" Language="1033" Version="1.0.0.0" Manufacturer="WiX_test_4_Winfrm" UpgradeCode="e69fe67b-5c28-4764-8196-a6613b840eff">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

        <Feature Id="ProductFeature" Title="SetupProject1" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="SetupProject1" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
            <!-- <Component Id="ProductComponent"> -->
                <!-- TODO: Insert files, registry keys, and other resources here. -->
            <!-- </Component> -->
        </ComponentGroup>
    </Fragment>
</Wix>

推荐答案

WiX 资源:先提供几个链接:

WiX Resources: A couple of links first:

Hello WiX C# 自定义操作.


你好 WiX"(请使用透明铝材)

我认为您需要的是 你好世界"来自 CodeProject 的 WiX.现在已经很老了,但仍然很好地向您展示了编译工作 MSI 的基本知识.


"Hello WiX" (transparent aluminum please)

I think what you need is the "Hello World" of WiX from CodeProject. This is quite old now, but still good at showing you the very basics of getting a working MSI compiled.

更新:下面我添加了有关如何从新的 WiX 3 Visual Studio 项目编译 MSI 的分步说明.

UPDATE: Below I have added a step-by-step description of how to compile an MSI from a fresh WiX 3 Visual Studio project.

这是回溯的另一个答案,其中包含有关 WiX 真正含义的一些上下文信息:MSI 与 nuget 包:哪个更适合持续交付?.您将找到指向hello world"的链接.这里也是,还有其他几个链接.

Here is another answer from way back with some context information for what WiX really is: MSI vs nuget packages: which are is better for continuous delivery?. You will find the link to "hello world" here as well, but also several other links.

总结:检查第一个链接以获取hello world";的 WiX.然后用几个测试组件更新你的源代码并重新编译.您应该获得 Orca(SDK 工具)才能查看已编译的 MSI 文件.由于您已安装 Visual Studio,请尝试搜索 Orca-x86_en-us.msi 并安装它(这是 Microsoft 自己的官方 MSI 查看器和编辑器).然后在开始菜单中找到 Orca.从技术上讲,Orca 是作为 Windows SDK(不是 Visual Studio)的一部分安装的,但 Windows SDK 与 Visual Studio 安装捆绑在一起.编译 MSI 文件后,只需右键单击它并选择 Edit with Orca.

In summary: check the first link to get the "hello world" of WiX. Then update your source with a couple of test components and recompile. You should get hold of Orca (SDK tool) to be able to view the compiled MSI files. Since you have Visual Studio installed, try searching for Orca-x86_en-us.msi and install it (this is Microsoft's own, official MSI viewer and editor). Then find Orca in the start menu. Technically Orca is installed as part of Windows SDK (not Visual Studio), but Windows SDK is bundled with the Visual Studio install. Once you have a compiled MSI file, just right click it and select Edit with Orca.

在这样的文件真正有意义之前,需要一些经验.本质上,它是存储在 COM 结构化存储文件 (OLE) 中的原始 MS SQL 数据库.本质上是文件中的文件系统,其中包含针对不同内容(例如文件和数据表等)的流.只需将其视为具有正常参照完整性的数据库,并首先关注 FileComponent 等核心表.

Some experience will be needed before such a file really makes sense. In essence it is a primitive MS SQL database stored in a COM structured storage file (OLE). Essentially a file system in a file with streams for different content (such as files, and datatables, etc...). Just think of it as a database with normal referential integrity and focus on the core tables such as File and Component at first.

让我尝试逐步描述您可以在新制作的 WiX 3 项目中执行的操作,以使其使用默认 WiX GUI 进行编译.您可以看到这些更改合并"了.在答案的最后一部分中包含一个完整的示例,但请逐步阅读此内容以使其有意义.

Let me try a step-by-step description of what you can do in a freshly made WiX 3 project to make it compile with a default WiX GUI. You can see these changes "merged" into a complete sample in the last section of the answer, but do read this step-by-step so it makes sense.

  1. 创建一个新的 WiX3 项目.你知道怎么做,我不会在细节上浪费时间.

  1. Create a new WiX3 project. You know how to do that, I won't waste time with the details.

Manufacturer 属性设置为您的公司名称.现在将您选择的新名称设置为 Name 属性.在此示例中,它设置为 MinimalTester - 请使用其他内容.

Set the Manufacturer attribute to your company name. Now set a new name of your choosing to the Name attribute. In this sample it is set to MinimalTester - use something else please.

更改为 在 MSI 中使用嵌入的 cab 文件.这样只创建了 MSI,没有额外的外部 CAB 文件.

Change <MediaTemplate /> to <MediaTemplate EmbedCab="yes" /> to use embedded cab files in the MSI. This way only the MSI is created and there is no additional, external CAB file.

在 MediaTemplate 元素之后直接添加:<UIRef Id="WixUI_Mondo";/>.这将向您的 MSI 添加默认 WiX 对话框集,因此它具有更通用所需的基础知识.您现在可以运行修复和修改,并按照大多数 MSI 文件从 Installshield 或 Advanced Installer 或其他专业工具提供的方式获得原始安装向导.至关重要的是:您的管理安装将有一个对话框,您可以在其中指定文件应该被解压到哪里.

Directly after the MediaTemplate element, add this: <UIRef Id="WixUI_Mondo" />. This will add a default WiX dialog set to your MSI so it has the basics of what is needed to be more generically useful. You can now run repair, and modify and you get a wizard for the original install along the lines of what most MSI files provide from Installshield or Advanced Installer or other professional tools. And crucially: your administrative installation will have a dialog where you can specify where files should be extracted to.

我们会将我们自己的许可协议添加到 WiX 设置中(否则您会得到一个含糊不清的默认协议).直接跟随 添加这个元素: .现在创建文件 TestLicenseAgreement.rtf 并将其放在与主 WiX 源文件相同的文件夹中(快速方法:在 Visual Studio 中,右键单击项目并在文件资源管理器中打开文件夹",现在创建右键单击 RTF 文件 => 新建 => RTF 文件.也许打开 RTF 并输入一些测试文本).进一步自定义对话框(位图等).

We will add our own License Agreement to the WiX setup (or else you will get an mumbling default one). Directly following <UIRef Id="WixUI_Mondo" /> add this element: <WixVariable Id="WixUILicenseRtf" Value="TestLicenseAgreement.rtf" />. Now create the file TestLicenseAgreement.rtf and place it in the same folder as your main WiX source file (quick way: in Visual Studio, right click project and "Open Folder in File Explorer", now create the RTF file with right click => New => RTF file . And maybe open the RTF and enter some test text). Further customization of the dialogs (bitmaps and more).

WiX 对话框集定义在一个 dll 中,我们需要引用它.在你的 Visual Studio WiX 项目中:Right click References =>添加参考... =>导航到 C:Program Files (x86)WiX Toolset v3.11in.双击WixUIExtension.dll,最后点击OK.

The WiX dialog set is defined in a dll, we need to reference it. In your Visual Studio WiX project: Right click References => Add Reference... => Navigate to C:Program Files (x86)WiX Toolset v3.11in. Double click WixUIExtension.dll and finally click OK.

现在在 WiX 中添加可能的绝对最小组件,并将绝对路径指定为源.这是为了确保您可以编译 MSI.之后,您可以使路径相对或变量(现在只需将其直接添加到 INSTALLFOLDER 目录元素下):

Now add the absolute minimal component possible in WiX with an absolute path specified as source. This is to be sure you can compile the MSI. Afterwards you can make the path relative or a variable (just add this directly under the INSTALLFOLDER directory element for now):

  <Component Feature="ProductFeature">
    <File Source="C:UserssomeoneSourceControlMyProjectCoreApp.exe" />
  </Component>

  1. 最后右键单击解决方案中的 WiX 项目并选择 Build.您可以通过右键单击 WiX 项目并单击 在文件资源管理器中打开文件夹 来快速测试运行 MSI.现在双击 bin,然后双击 Debug(或者如果你切换到发布版本,则发布 - 不确定两种配置之间的默认差异"是什么).您应该会在对话框序列的第二个对话框中看到您自己的许可协议.
  1. Finally right click the WiX project in your solution and select Build. And you can quickly test run the MSI by right clicking the WiX project and clicking Open Folder in File Explorer. Now double click on bin and then Debug (or Release if you switched to a release build - not sure what "default differences" are between the two configurations). You should see your own license agreement in the second dialog in the dialog sequence.

后来的 WiX 版本为几乎总是设置为模板值"的属性提供了很好的默认值.或者两个属性本质上是多余的.只需将它们从源代码中删除,让 WiX 编译器使用默认值添加它们即可.少大惊小怪.

The later WiX versions have great defaults for attributes that are almost always set to "template values" or where two attributes essentially are redundant. Just leave them out of your source and let the WiX compiler add them with default values. Much less fuss.

例如:上述元素缺少Component Id.在编译期间,它默认为它包含的 File 元素的 Id.File element Id 反过来也缺失,默认为由 Source 属性(这是一个强制属性)指定的文件名.

As an example: The above element lacks a Component Id. During compilation it defaults to the Id of the File element it contains. The File element Id in turn, is also missing and will default to the file name specified by the Source attribute (which is a mandatory attribute).

也许看一下这个答案以获得更长的描述和一个具体的例子:WIX 中的 guid 语法? 看看消除某些属性的所有冗余和重复后,您的 WiX 源文件有多简单?更少的文字,更少的错误.

Maybe look at this answer for a longer description and a concrete example towards the bottom: Syntax for guids in WIX? See how simple your WiX source files can be once you eliminate all the redundancy and duplication of certain attributes? Less text, less bugs.

在下面的示例中,组件已移动到默认的 ComponentGroup - 因此无需指定它属于哪个功能(与上面不同).

In the below sample the component has been moved into the default ComponentGroup - hence there is no need to specify what feature it belongs to (unlike above).

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <!--CHANGE 0: Set Manufacturer attribute to something, you must also specify a full GUID for UpgradeCode -->
  <Product Id="*" Name="MinimalTester" Language="1033" Version="1.0.0.0" Manufacturer="My Company" UpgradeCode="PUT-GUID-HERE">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    
    <!--Standard: <MediaTemplate />-->
    <!--CHANGE #1: Enable embedded cab files, so there is only one file generated, the MSI file -->
    <MediaTemplate EmbedCab="yes" /> 
    
    <!--CHANGE #2: Add the following elements to link one of the default WiX GUI sequences and show the specified license agreement. The RTF file must be created and placed next to your WiX source file -->
    <UIRef Id="WixUI_Mondo" /> 
    <WixVariable Id="WixUILicenseRtf" Value="TestLicenseAgreement.rtf" />        

    <!--CHANGE #3: Add WiX dll reference. In Visual Studio WiX project: Right click References => Add Reference... => Navigate to C:Program Files (x86)WiX Toolset v3.11in. Double click WixUIExtension.dll. Click OK -->

    <Feature Id="ProductFeature" Title="MinimalTester" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="MinimalTester" />
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      
      <!--CHANGE #4: Remove TODO elements, add the most basic component possible as illustrated below -->
      <Component>
        <File Source="C:UserssomeoneSourceControlMyProjectCoreApp.exe" />
      </Component>

    </ComponentGroup>
  </Fragment>
</Wix>

尝试编译和测试安装.应该安装到正常系统上的 C:Program Files (x86)MinimalTester.

Try to compile and test install. Should install to C:Program Files (x86)MinimalTester on a normal system.

也许可以在此处查看 WiX 教程的更多链接:WIX 安装程序未正确显示 WixUI 对话框的自定义图像.

Maybe see further links for WiX tutorials here: WIX Installer not displaying the custom image of WixUI Dialog correctly.

这篇关于WiX 安装程序 msi 未安装使用 Visual Studio 2017 创建的 Winform 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆