Click to Rate and Give Feedback
MSDN
MSDN Library
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Studio
Registry Look-Ups

Some build tasks require the input of paths and other information that is contained in registry keys or in environment variables. A build configuration file, such as msbuild.exe.config, can read these values directly from the registry,

The $(registry:xxxx) syntax can be used anywhere in the project where property expressions are enabled. In such cases, if there is an error, an "invalid project file" error message occurs that explains the problem.

The following property definition reads a value from a registry key:

<PropertyGroup>
  <MyProperty>$(registry:HKEY_LOCAL_MACHINE\MyKey\MySubKey@ValueName)</MyProperty>
</PropertyGroup>

In this example, ValueName represents the value in the \HKEY_LOCAL_MACHINE\MyKey\MySubKey registry key. To read the default value, reference \HKEY_LOCAL_MACHINE\MyKey\MySubKey without specifying <ValueName>. For example:

<PropertyGroup>
  <MyProperty>$(registry:HKEY_LOCAL_MACHINE\MyKey\MySubKey)</MyProperty>
</PropertyGroup>
NoteNote:

If you try to read the registry key and you do not have the required user rights, an access violation may occur and you may receive an error that is similar to the following.

MSBUILD: Configuration error MSB4146: Cannot evaluate the property expression "..\WinFx\v3.5$(registry:HKEY_LOCAL_MACHINE\software\x)" found at "c:\ToolPlat\src\tools\x86\managed\v2.0\MSBuild.exe.config, line 15". The expression "$(registry:HKEY_LOCAL_MACHINE\software\x)" cannot be evaluated. Requested registry access is not allowed.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Typo corrections      CountryRobot ... Thomas Lee   |   Edit   |   Show History

There are various errors in every single example in the above text (e.g. a missing closing parenthesis, a missing "@" symbol, or a missing "registry:" prefix). The correct syntax for referencing a registry item is:

$(registry:HKEY_LOCAL_MACHINE\MyKey\MySubKey@ValueName)

-Gonz

Another typo      DanMoseley - MSFT ... Thomas Lee   |   Edit   |   Show History
"A similar error occurs if the expression is in a project rather than the config file. "
This is not true. This syntax in fact is typically used in project files.
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker