locked
Registry access via MSBuild custom tasks RRS feed

  • Question

  • I have an MSBuild custom task which finds a program's installed location via its registry key. It uses this as the registry key value:
    HKEY_LOCAL_MACHINE\Software\Cenqua\Clover.Net\.NET_20

    and calls Registry.GetValue() to extract the InstallDir. This works fine when the task is run from MSBuild. The problem is when writing unit tests to exercise this same code, something different happens.

    The registry value is actually:
    HKEY_LOCAL_MACHINE\Software\Wow6432Node\Cenqua\Clover.Net\.NET_20

    So, when I run the unit test looking for the non-Wow6432Node version, it doesn't find it and returns null for the InstallDir.
    Why do different things happen when I run the same code from MSBuild -vs- running it from a VS unit test project?
    Friday, September 21, 2007 3:53 PM

Answers

  • Figured this out over the weekend. The difference between MSBuild calling the task code and my unit tests calling the task code was the bit-ness of their executables. MSBuild (I assume) is 32 bit, thus translating any xxx/Wow6432Node/yyy registry keys into xxx/yyy.

    The version of NUnit I was using was 64 bit - needing the full registry key including the Wow6432Node bit. All I had to do was run the same tests using the x86 version of NUnit and they passed fine.
    Monday, September 24, 2007 9:00 AM