Registry Properties

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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.

Reading Registry Values

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>

Note

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.

See Also

Concepts

Standard and Custom Toolset Configurations

MSBuild Advanced Concepts