I’m attempting to use MSBuild to figure out whether a SQL server instance has SQL authentication enabled. I’m trying 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 doesn’t seem to allow referencing properties ($(SqlInstanceName)) inside $(registry:...) properties.
Or is there some way to make this work?
Actually, it’s probably down to using the 32-bit MSBuild. Using the MSBuild 4.0 property functions gives me this:
…which works fine.