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

FR: Access to 32/64bit registry keys in Custom Actions (using .NET3.5) #701

Closed
GilesBathgate opened this issue Aug 11, 2019 · 9 comments
Closed

Comments

@GilesBathgate
Copy link
Contributor

GilesBathgate commented Aug 11, 2019

.NET 3.5 is the recommended CLR for wixsharp setup projects, however support for accessing both the 64bit and 32bit windows registry was not added until .NET version 4.0

Fortunately, backwards compatible access can be achieved using the following from StackOverflow:
https://stackoverflow.com/questions/26217199/what-are-some-alternatives-to-registrykey-openbasekey-in-net-3-5

I've tidied up the code and provided example use here:
https://gist.github.com/GilesBathgate/326de8355ebc829061de5840e39b043b

It would be really handy to have this available as a feature in WixSharp to save having to implement this manually in custom actions.

@GilesBathgate
Copy link
Contributor Author

@oleg-shilo What are the limitations regarding using .NET >= 4 I understand that the project templates add a ValidateAssemblyCompatibility call, but it seems removing this call and setting the project to .NET4.7 the installer still works...

@oleg-shilo
Copy link
Owner

Hi Giles,

The recommendation for using .NET3.5 is truly superficial. It's not based on any application field evidence. It is rather reflection of early stage of Wix# when .NET3.5 was still dominant and targeting the older CLR version was simply a safer choice in terms of probability of any compatibility issues.

I do not longer believe that v3.5 is a good recommendation choice and after your this very prompt will change the recommendation to .NET4.

And... the very current implementation of the ValidateAssemblyCompatibility actually already reflects the new recommendation:

public static void ValidateAssemblyCompatibility(Reflection.Assembly assembly)
{
    //this validation is no longer critical as Wix# MAnagedSetup now fully supports .NET4.0
    //if (!assembly.ImageRuntimeVersion.StartsWith("v2."))
    //    try
    //    {
    //        var msg = string.Format("Warning: assembly '{0}' is compiled for {1} runtime, which may not be compatible with the CLR version hosted by MSI. "+
    //                                "The incompatibility is particularly possible for the Embedded UI scenarios. " +
    //                                "The safest way to solve the problem is to compile the assembly for v3.5 Target Framework.",
    //                                assembly.GetName().Name, assembly.ImageRuntimeVersion);
    //        Debug.WriteLine(msg);
    //        Console.WriteLine(msg);
    //    }
    //    catch { }
}

@oleg-shilo
Copy link
Owner

I have just removed the ValidateAssemblyCompatibility calls completely.

Do you still think upgrading the recomendation to v4.0 automatically resolves registry 32/64bit roaming challenge?

@GilesBathgate
Copy link
Contributor Author

Yes using NET4 makes this FR redundant.

@oleg-shilo
Copy link
Owner

All done now.

@GilesBathgate
Copy link
Contributor Author

I am having difficulty Debugging using System.Diagnostics.Debugger.Launch() with .NET4. Do you experience this, is there a workaround?

@oleg-shilo
Copy link
Owner

No not really. I will be debugging your #704 so will tell you if I have the same problem.

@oleg-shilo
Copy link
Owner

Just wanted to check with you. Your work around for #704, why did you opt for messageRecord[2] while the original solution was doing messageRecord[1]:

. . .
string message = null;

bool simple = true;
if (simple)
{
    for (int i = messageRecord.FieldCount - 1; i > 0; i--)
    {
        message = messageRecord[i].ToString();
    }
}

Don't get me wrong, I do realize that the original solution looks quite questionable. That's why I need to debug it.

@oleg-shilo
Copy link
Owner

OK, when I started debugging I remembered a few tricks...

  • First, your debugger will need to be elevated.
  • Second, place in your code Debug.Assert(false);.
  • Resist temptation to click 'Retry' in the assertion box 😄
  • Use debugger "Attach to process". Select msiexec that has an assertion text as a title.
  • You are done

image

Any other way my debugger fails to load the correct debug symbols.

oleg-shilo pushed a commit that referenced this issue Aug 17, 2019
Release v1.11.1
* Issue #704: Question: Localized progress action messages.
* Issue #696: ComponentCondition on CloseApplication doesn't appear to be working
* Removed `ValidateAssemblyCompatibility`as no longer needed since .NET4.0 is arguably a better choice for the recommended runtime
* Issue #604: Is it possible to suppress the "UAC prompt" text if UAC is not enabled?
* Issue #701: FR: Access to 32/64bit registry keys in Custom Actions (using .NET3.5)
* WixSharpVSIX (VS Templates): Release v1.8.3
  - Migrated to .NET4.0 as target runtime
  - ManagedUI progress message localization improvements triggered by #704
* Added a `Property.Secure`:
  ```C#
  new Property("Gritting", "Hello World!"){ Secure = true })
  ```
* More granular conditions for feature install/uninstall:
  ```C#
  var condition = feature.ShallInstall() && feature.IsInstalled();
  ```
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