Wix Not Removing Files on Uninstall

左心房为你撑大大i 提交于 2019-11-30 08:00:37
Jony Lalwani

Try to change the GUID of the components which are not uninstalling. I tried the same and it worked for me. It may be because the GUID is already registered in the registry by some other product.

The cause is generally messed up component reference count in the registry - often it happens on dev-boxes during development. Can also often happen to Installshield packages due to their use of the SharedDllRefCount concept (legacy, non-MSI reference counting).

Some technical details: Change my component GUID in wix? Test on a clean virtual to verify the problem is real and not a dev-box issue. Changing component GUIDs can have repercussions (patching problems etc...).

Make sure that no other MSI packages are keeping your components installed.

Specifically, go into Control Panel / Programs and Features, and make sure that there isn't an "old" version of your program still installed.

I somehow got my project in the state where every single one of my components couldn't be uninstalled. I have no idea how. I wrote a program that will take a .wixproj file and change all of the component GUIDs to new GUIDs and that solved the issue (after I manually deleted the files). This is based off of user593287's answer.

The argument should be the path to your project file. An example of running this from the command line would be:

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);
                }
            }
        }        
    }
}

I made some changes to it without testing it, so good luck, it's pretty straightforward though.

Would be worth checking the following registry key to see if your files are listed. This can cause the uninstaller to ignore the components as it believes them to be shared.

HKLM\Software\Microsoft\Windows\CurrentVersion\SharedDlls

I encountered a similar problem, which appeard not to be present any more when I converted all guids into uppercase (as required in some specification for compatiblity issues). Did not test exensively whether this was really the solution to the problem. Maybe this is the same as the previous answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!