4

我正在尝试使用 MSBuild 来确定 SQL 服务器实例是否启用了 SQL 身份验证。我正在尝试以下操作:

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

不幸的是,MSBuild 似乎不允许$(SqlInstanceName)在属性中引用属性 () $(registry:...)

或者有什么方法可以使这项工作?

4

1 回答 1

5

实际上,它可能归结为使用 32 位 MSBuild。使用 MSBuild 4.0属性函数给了我这个:

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

...效果很好。

于 2012-07-10T17:12:10.163 回答