Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folder not removed on uninstalling #123

Closed
JeremyAnsel opened this issue Aug 9, 2017 · 5 comments
Closed

Folder not removed on uninstalling #123

JeremyAnsel opened this issue Aug 9, 2017 · 5 comments

Comments

@JeremyAnsel
Copy link

Consider the following code:

var project = new ManagedProject("MyProduct",
    new Dir(@"%ProgramFiles%\My Company\My Product",
        new File(@"Files\File1.txt")),
    new RegValue(RegistryHive.LocalMachine, "Software\\My Company\\My Product", "MyRegKey", "1"));

project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");
project.ManagedUI = ManagedUI.Default;

project.BuildMsi();

On uninstalling, the folder %ProgramFiles%\My Company is not removed.

The generated wxs file contains:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="ProgramFilesFolder" Name="ProgramFilesFolder">
    <Directory Id="ProgramFilesFolder.My_Company" Name="My Company">
      <Directory Id="INSTALLDIR" Name="My Product">

        <Component Id="Component.File1.txt" Guid="6f330b47-2577-43ad-9095-18610a53ec84">
          <File Id="File1.txt" Source="Files\File1.txt" />
        </Component>

        <Component Id="Registry1" Guid="6f330b47-2577-43ad-9095-1861b7315623" KeyPath="yes">
          <RegistryKey Root="HKLM" Key="Software\My Company\My Product">
            <RegistryValue Id="MyRegKey" Type="string" KeyPath="no" Value="1" Name="MyRegKey" />
          </RegistryKey>
          <RemoveFolder Id="INSTALLDIR" On="uninstall" />
        </Component>

      </Directory>
    </Directory>
  </Directory>
</Directory>
@oleg-shilo
Copy link
Owner

oleg-shilo commented Aug 10, 2017

This behavior is a side effect of the KeyPath="yes" being used with the registry key element. WiX recommends to set it to "yes" (http://wixtoolset.org/documentation/manual/v3/xsd/wix/component.html). Otherwise it "can be dangerous". The explanation "why" is not very detailed. And combined with the fact that they forgot to mention such a side effect as yours makes me really question the quality of that documentation article.

Anyway, I just tested and disabling of the KeyPath auto-insertion does solve the problem:

AutoElements.DisableAutoKeyPath = true;

var project = new ManagedProject("MyProduct",...

Just in case if you wander why it's not disabled by default - it would trigger WiX/MSI problems for other scenarios (e.g. Certificates, EnvVariables and SqlDatabase samples). And... KeyPath="yes" is what recommended by WiX team.

Though I will see if any improvements are possible in that area.

@oleg-shilo
Copy link
Owner

Indeed some improvement were possible. Currently auto-injection of the KeyPass is suppressed for components containing files. But actually it needed to be expanded for registries (your case) as well.

Done. Will be available in the next release.

@JeremyAnsel
Copy link
Author

Thanks

@oleg-shilo
Copy link
Owner

Until the fix is available you can change the KeyPass attribute in the post-build event Project.WxsGenerated. Or if you are eager to try the fix you can just grab the latest binary WixSharp.dll for GitHub: https://github.com/oleg-shilo/wixsharp/tree/master/Source/src/WixSharp.Samples

@oleg-shilo
Copy link
Owner

oleg-shilo commented Jul 26, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants