【问题标题】:Wix Not Removing Files on UninstallWix 在卸载时不删除文件
【发布时间】:2011-11-23 21:00:09
【问题描述】:

我已经看到其他人对此问题提出的问题,但我无法让它对我有用。我正在尝试习惯 Wix,这样我们就可以迁移我们的 vdproj(我觉得我们已经向前迈出了 1 步,向后退了 4 步……使用 Wix,最基本的事情变得完全不平凡……但我确实看到了为构建安装程序提供成熟的声明性标记的价值。

我在 SharpDevelop 的 wixproj 中有以下 wxs。

安装工程。卸载什么都不做,只保留安装文件夹和 dll。有什么问题?

文件.wxs:

<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="TARGETDIR">
            <Directory Id="ProgramFilesFolder" Name="PFiles">
                <Directory Id="INSTALLDIR" Name="Client">
                    <Component Id="InteropDll" Guid="AD09F8B9-80A0-46E6-9E36-9618E2023D66" DiskId="1">
                        <File Id="Interop.dll" Name="Interop.dll" Source="..\Interop\bin\$(var.Configuration)\Interop.dll" KeyPath="yes" />
                        <RemoveFile Id="RemoveInterop.dll" Name="Interop.dll" On="uninstall" />
                    </Component>
                </Directory>
            </Directory>
        </DirectoryRef>
    </Fragment>
</Wix>

Setup.wxs:

<?xml version="1.0"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*"
        Name="Client Setup"
        Language="1033"
        Version="1.0.0.0"
        UpgradeCode="4A88A3AD-7CB6-46FB-B2FD-F4EADE0218F8"
        Manufacturer="Client Setup">
        <Package Description="#Description"
            Comments="Comments"
            InstallerVersion="200"
            Compressed="yes"/>
        <!--
            Source media for the installation. 
            Specifies a single cab file to be embedded in the installer's .msi. 
        -->
        <Media Id="1" Cabinet="contents.cab" EmbedCab="yes" CompressionLevel="high"/>

        <!-- Installation directory and files are defined in Files.wxs -->
        <Directory Id="TARGETDIR" Name="SourceDir"/>

        <Feature Id="Complete"
                 Title="Client Setup"
                 Description="Client Setup"
                 Level="1">
            <ComponentRef Id="InteropDll" />
        </Feature>

        <!-- 
            Using the Wix UI library

            WixUI_InstallDir does not allow the user to choose 
            features but adds a dialog to let the user choose a 
            directory where the product will be installed
        -->
        <Property Id="WIXUI_INSTALLDIR">INSTALLDIR</Property>

        <UI Id="WixUI_InstallDir">
            <TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
            <TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
            <TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />

            <Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
            <Property Id="WixUI_Mode" Value="InstallDir" />

            <DialogRef Id="BrowseDlg" />
            <DialogRef Id="DiskCostDlg" />
            <DialogRef Id="ErrorDlg" />
            <DialogRef Id="FatalError" />
            <DialogRef Id="FilesInUse" />
            <DialogRef Id="MsiRMFilesInUse" />
            <DialogRef Id="PrepareDlg" />
            <DialogRef Id="ProgressDlg" />
            <DialogRef Id="ResumeDlg" />
            <DialogRef Id="UserExit" />

            <Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath" Order="3">1</Publish>
            <Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4"><![CDATA[WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>

            <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>

            <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="InstallDirDlg">NOT Installed</Publish>
            <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>

            <Publish Dialog="InstallDirDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>
            <Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
            <Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="WixUIValidatePath" Order="2">NOT WIXUI_DONTVALIDATEPATH</Publish>
            <Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
            <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="4">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
            <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
            <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>

            <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="InstallDirDlg" Order="1">NOT Installed</Publish>
            <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">Installed AND NOT PATCH</Publish>
            <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">Installed AND PATCH</Publish>

            <Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>

            <Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
            <Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
            <Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>

            <Property Id="ARPNOMODIFY" Value="1" />
        </UI>

        <UIRef Id="WixUI_Common" />
    </Product>
</Wix>

【问题讨论】:

  • 配置似乎没问题。您是否尝试创建详细的卸载日志以查看会发生什么? setupanddeployment.com/debugging/msi-log 。搜索 InstallValidate 和 RemoveFiles 操作并查看它们的作用。
  • 不知道如何,但这似乎已经随机开始工作......

标签: wix windows-installer wix3.5


【解决方案1】:

尝试更改未卸载组件的 GUID。我尝试了同样的方法,它对我有用。可能是因为 GUID 已被其他产品注册到注册表中。

原因通常是注册表中的组件引用计数混乱 - 通常在开发期间发生在 dev-boxes 上。由于使用了 SharedDllRefCount concept(旧版、非 MSI 引用计数),Installshield 软件包也经常发生。

一些技术细节Change my component GUID in wix? 在干净的虚拟机上进行测试,以验证问题是真实的,而不是开发盒问题。更改组件 GUID 可能会产生影响(修补问题等...)。

【讨论】:

  • 你就是那个男人。我已经为这个问题苦苦挣扎了几个小时。该特定组件上的 GUID 为空。我添加了一个 GUID,它起作用了。
  • 是否每次进行单独构建时都必须生成新的 Guid 以确保卸载正常
  • 这个解决方案在我试过的一堆上面对我有用。谢谢!
  • 如果您使用 heat.exe/Harvest[wixtoolset.org/documentation/manual/v3/overview/heat.html] WIX 工具生成组件列表,那么您可能需要查看控制 GUID 的“-ag”和“-gg”开关组件的定义。使用 -ag 将根据文件位置自动生成 一致 guid,但是 -gg 似乎每次都会生成新的 GUID。
  • 就像 neminem 说的那样,guid 在开发过程中可能会变得一团糟,频繁的设置构建可能会以某种方式失败。更改 guid 会破坏与错误链接的链接,并且在大多数情况下都可以使用。最好还更改密钥路径的文件名,以确保在尝试修补时可以正常工作。以下是对 guid / key path 概念的快速解释,以及何时应该更改 guid 而不是:stackoverflow.com/questions/1405100/…
【解决方案2】:

不知何故,我的项目处于无法卸载每个组件的状态。我不知道怎么做。我编写了一个程序,该程序将采用 .wixproj 文件并将所有组件 GUID 更改为新的 GUID 并解决了问题(在我手动删除文件之后)。这是基于 user593287 的回答。

参数应该是项目文件的路径。从命令行运行它的一个例子是:

GuidFixer.exe MyProject.csproj

using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace GuidFixer
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string projectFileName = args[0];
            string path = Path.GetDirectoryName(projectFileName);
            List<string> files = new List<string>();

            XmlDocument projectDocument = new XmlDocument();            
            projectDocument.Load(projectFileName);
            XmlNamespaceManager manager = new XmlNamespaceManager(projectDocument.NameTable);
            manager.AddNamespace("msbld", "http://schemas.microsoft.com/developer/msbuild/2003");

            // Finds all of the files included in the project.
            XmlNodeList nodes = projectDocument.SelectNodes("/msbld:Project/msbld:ItemGroup/msbld:Compile", manager);
            foreach (XmlNode node in nodes)
            {
                string fileName = Path.Combine(path, node.Attributes["Include"].Value);
                files.Add(fileName);
            }

            foreach (string fileName in files)
            {
                // Lets only do .wxs files
                if (!Path.GetExtension(fileName).Equals(".wxs", StringComparison.CurrentCulture))
                {
                    continue;
                }

                // This will only update files that aren't readonly, make sure
                // you check out your files from source control before running.
                FileAttributes attributes = File.GetAttributes(fileName);
                if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    continue;
                }

                bool modified = false;

                XmlDocument doc = new XmlDocument();
                doc.PreserveWhitespace = true; // space inside tags are still lost
                doc.Load(fileName);

                foreach (XmlNode node in doc.GetElementsByTagName("Component"))
                {
                    Guid guid = Guid.NewGuid();
                    string value = guid.ToString("B").ToUpper();

                    node.Attributes["Guid"].Value = value;
                    modified = true;
                }

                // Only update files that were modified, to preserve formatting.
                if (modified)
                {
                    doc.Save(fileName);
                }
            }
        }        
    }
}

我在没有测试的情况下对其进行了一些更改,祝你好运,不过它非常简单。

【讨论】:

  • 很有帮助。我将为未来的用户注意,虽然它不会将 *.wxs 作为文件参数处理,但如果您明确拼出文件名,它确实可以工作。 (使用 *.wxs 导致“路径中的非法字符” System.IO.Path 异常。)
【解决方案3】:

确保没有其他 MSI 软件包在安装您的组件。

具体来说,进入控制面板/程序和功能,并确保没有安装“旧”版本的程序。

【讨论】:

    【解决方案4】:

    值得检查以下注册表项以查看您的文件是否已列出。这可能会导致卸载程序忽略组件,因为它认为它们是共享的。

    HKLM\Software\Microsoft\Windows\CurrentVersion\SharedDlls
    

    【讨论】:

      【解决方案5】:

      我遇到了一个类似的问题,当我将所有 guid 转换为大写时,它似乎不再存在(如某些规范中的兼容性问题所要求的那样)。没有仔细测试这是否真的是问题的解决方案。也许这和之前的答案是一样的。

      【讨论】:

        猜你喜欢
        • 2010-09-16
        • 2011-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-16
        • 1970-01-01
        • 2015-10-10
        • 2011-03-18
        相关资源
        最近更新 更多