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

Condition on RegValueProperty? #593

Closed
WayneHiller opened this issue Feb 23, 2019 · 4 comments
Closed

Condition on RegValueProperty? #593

WayneHiller opened this issue Feb 23, 2019 · 4 comments

Comments

@WayneHiller
Copy link

WayneHiller commented Feb 23, 2019

Is there no way to specify a condition on RegValueProperty? The reason I am asking is because I load some
values into Properties and everything works fine on the first install. If I then run the install again without uninstalling it acts like the prev install did not finish correctly. I do not get the Repair, Remove etc. If I comment out the RegValueProperty lines it all works as expected. I would like to only call RegValueProperty if Condition.NOT_Installed returns true.

I also noticed Folder entries in the XML output when writing to the Registry. That does not seem correct.

<Component Id="Registry.1" Guid="6fe30b47-2577-43ad-9095-1861b742561a" Permanent="yes" KeyPath="yes">
   <RegistryKey Root="HKLM" Key="Software\My Company\My Product">
         <RegistryValue Id="InstallDir" Type="string" KeyPath="no" Value="[INSTALLDIR]" Name="InstallDir" />
    </RegistryKey>

    <CreateFolder />
    <RemoveFolder Id="ProgramFilesFolder" On="uninstall" />
</Component>
@oleg-shilo
Copy link
Owner

OK there are a few problems here.

First one is superficial. Neither RegistryKey nor Registry value WiX elements do not have condition attribute. Thus one needs to set the condition to the parent component:

regVal.AttributesDefinition += $";Component:Condition={yourCondition}";

However the second problem is more interesting. Running the very install again must trigger change/repair sequence and addressing it by injecting some conditions probably is not the right way to solve the problem.

I had a look at the "Registry" sample in the distro and was able to trigger change/repair sequence by executing the msi again after the first installation:
image

The only change you will need to do to the sample is to ensure Mondo UI so you can access change/repair buttons on UI instead of doing it from the ControlPanel:

project.UI = WUI.WixUI_Mondo;

oleg-shilo pushed a commit that referenced this issue Feb 24, 2019
…element does not have condition (e.g. `RegistryKey`). Triggered by issue #593
@WayneHiller
Copy link
Author

WayneHiller commented Feb 24, 2019

I ended up just using a ManagedAction to read the Registry values and assign them to Session Properties. I used the Condition.NOT_Installed condition on the action.

As for the second part it seems Windows Installer will also display the Change, Repair, Remove page even when UI is set to WUI.WixUI_FeatureTree which is what I am using.

This code shows the issue I was having before switching to use a ManagedAction.

     private static void Main() {
            var fullSetup = new Feature( "App" ) {
                IsEnabled = false
            };

            var project =
                new Project( "MyProduct",
                    new Dir( @"%ProgramFiles%\My Company\My Product",
                        new File( fullSetup, @"Program.cs" ) ),
                    new RegValueProperty( "ADDLOCAL", RegistryHive.LocalMachine, @"Software\My Company\My_Product", "Features", "App" ),
                    new RegValue( fullSetup, RegistryHive.LocalMachine, @"Software\My Company\My_Product", "Features", "[ADDLOCAL]" ).SetComponentPermanent( true )
                ) {
                    GUID = new Guid( "6f330b47-2577-43ad-9095-1861ba25889b" ),
                    UI = WUI.WixUI_FeatureTree,

                    PreserveTempFiles = true
                };
            project.BuildMsi();
        }

The first time you run it, it seems to work fine. Running it a second time displays this dialog:

image

Anyway I have it working now so it is no big deal.

@oleg-shilo
Copy link
Owner

Not a problem.
But you need to remember that "Windows Installer will also display the Change, Repair, Remove" only if the UI type you specified contains this dialog. WUI.WixUI_FeatureTree does not include this dialog but WUI.WixUI_Mondo (full UI) does. This explains why you don't see the dialog.

BTW even if the UI you are using does not have this dialog the change/repair mode is still supported. This is what your very sample produces in ControlPanel:

image

As you can see you can invoke both change and repair. Though because you don't have the dialog for that moth modes will simply trigger reinstallation.

@WayneHiller
Copy link
Author

I think the Change, Repair Remove is built into the Default dialogs, it will only be displayed if you run the installation again after it has already been installed. If you comment out the RegValueProperty line in my example code it will work properly and be displayed the second time you run the install (without uninstalling first). The RegValueProperty seems to cause an issue when the install is run a second time and is already installed.

Running a second time without first uninstalling with the RegValueProperty line in the code.

image

Uninstall first. Comment out the RegValueProperty line, build and install (Note that you will need to Select the App Feature to be installed manually). Running a second time without first uninstalling with the RegValueProperty line commented out in the code.

image

image

oleg-shilo pushed a commit that referenced this issue Mar 19, 2019
* Added new XML injection extensions `WixProject.AddXml` and `WixProject.AddXmlElement`
* Issue #608: Create Shortcut on Desktop to dotnet.exe
* Issue #551: Cannot include extra .wxs as part of a bundle
* Issue #610: Warning when building two bundles in one setup
* Issue #604: Is it possible to suppress the "UAC prompt" text if UAC is not enabled?
* Issue #606:  Platform.x64 not marking some folders win64="yes"
* Issue #599: Files creating empty folders on Destination (2)
* Issue #599: Files creating empty folders on Destination
* Added `WixEntity.ComponentCondition` to assist with cases when WiX element does not have condition (e.g. `RegistryKey`). Triggered by issue #593
* Added support for attribute namespaces during XML auto serialization with `WixObject.ToXElement()`
* Issue #586: How to add bal:overridable for Variable with wix#
* Issue #591: Code signing timestamping fails if old Windows SDK is installed
* Issue #585: Question: Warning about auto-generated IDs
* Issue #580: Wrong path to the AdminToolsFolder
* Add MsuPackage Element
* Fix Condition Net462_Installed, Net47_Installed, Net471_Installed, Net472_Installed
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