New Registry syntax in MSBuild v3.5
During development of the multi-targeting feature of the next version of MSBuild, we found it convenient to expose a new method for accessing the registry from project and target files. I hadn't really thought much more about it since we implemented it, but today I needed to make a change to Microsoft.Common.targets for which this new syntax was perfect, so I thought I'd share.
So here's how it works: suppose there's some value in the registry you're interested in consuming. Using the 2.0 version of MSBuild, you may have written a task which took the names of the key and value, and output the value of the value (ha, I always think it's funny saying that). Now, with the 3.5 version of MSBuild, it's very simple. Say the key you're interested in is "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework" and the value at that key you'd like to retrieve is "InstallRoot". On my machine, this value is set to "C:\WINDOWS\Microsoft.NET\Framework\". In your project/targets file - anywhere a property reference is allowed (which is pretty much everywhere), you could obtain this value with the property
$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework@InstallRoot)
This sort of shows off the pieces of the new syntax, which can be described like this
$(Registry: <key name>[@<value name>] )
Note the value name is optional - this is because the registry supports a notion of default values. If you omit the value from the specification, MSBuild will simply retrieve the default value (if it exists).
I think this is a neat new feature which hopefully many of you will find useful. Enjoy!
[ Author: Jeffery Callahan ]