Property reference when using registry properties in MSBuild?

I am trying to use MSBuild to find out if an instance of SQL Server is enabled using SQL Authentication. I am trying to do the following:

<Target Name="VerifySQLLoginMode"> <PropertyGroup> <SqlInstanceName>SQL08X64</SqlInstanceName> <SqlInstanceKey>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\ SQL@ $(SqlInstanceName))</SqlInstanceKey> <SqlLoginMode>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\$(SqlInstanceKey)\ MSSQLServer@LoginMode )</SqlLoginMode> </PropertyGroup> <Message Text="SqlInstanceName = $(SqlInstanceName)" /> <Message Text="SqlInstanceKey = $(SqlInstanceKey)" /> <Message Text="SqlLoginMode = $(SqlLoginMode)" /> <Error Condition="'$(SqlLoginMode)' != '2'" Text="Error: SQL Authentication is disabled. Please enable it." /> </Target> 

Unfortunately, MSBuild does not seem to allow you to refer to properties ( $(SqlInstanceName) ) inside the $(registry:...) properties.

Or is there a way to make this work?

+4
source share
1 answer

Actually, perhaps this is due to the use of 32-bit MSBuild. Using MSBuild 4.0's property functions gives me the following:

 <Target Name="VerifySQLLoginMode"> <!-- Note that this can't deal with the default instance. --> <PropertyGroup> <SqlInstanceName>SQL08X64</SqlInstanceName> <SqlInstanceKey>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL', '$(SqlInstanceName)', null, RegistryView.Registry64, RegistryView.Registry32))</SqlInstanceKey> <SqlLoginMode>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\$(SqlInstanceKey)\MSSQLServer', 'LoginMode', null, RegistryView.Registry64, RegistryView.Registry32))</SqlLoginMode> </PropertyGroup> <Message Text="SqlInstanceName: $(SqlInstanceName)" /> <Message Text="SqlInstanceKey: $(SqlInstanceKey)" /> <Message Text="SqlLoginMode: $(SqlLoginMode)" /> <Error Condition="'$(SqlLoginMode)' != '2'" Text="Error: SQL Authentication is disabled. Please enable it." /> </Target> 

... which works great.

+5
source

All Articles