2012-07-10 200 views
4

我正在嘗試使用MSBuild來確定SQL服務器實例是否啓用了SQL身份驗證。我想以下幾點:在MSBuild中使用註冊表屬性時引用屬性?

<Target Name="VerifySQLLoginMode"> 
    <PropertyGroup> 
    <SqlInstanceName>SQL08X64</SqlInstanceName> 
    <SqlInstanceKey>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\[email protected]$(SqlInstanceName))</SqlInstanceKey> 
    <SqlLoginMode>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\$(SqlInstanceKey)\[email protected])</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> 

不幸的是,的MSBuild似乎並沒有讓裏面$(registry:...)性引用屬性($(SqlInstanceName))。

或者有什麼方法可以使這項工作?

回答

5

其實,它可能是使用32位MSBuild。使用MSBuild 4.0 property functions給我這個:

<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> 

...它工作正常。