在MSBuild中使用注册表属性时引用中的属性?

在MSBuild中使用注册表属性时引用中的属性?,msbuild,Msbuild,我正在尝试使用MSBuild确定SQL server实例是否启用了SQL身份验证。我正在尝试以下方法: <Target Name="VerifySQLLoginMode"> <PropertyGroup> <SqlInstanceName>SQL08X64</SqlInstanceName> <SqlInstanceKey>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsof

我正在尝试使用MSBuild确定SQL server实例是否启用了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>

SQL08X64
$(注册表:HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL@$(SqlInstanceName))
$(注册表:HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\$(SqlInstanceKey)\MSSQLServer@LoginMode)
不幸的是,MSBuild似乎不允许在
$(注册表:…)
属性中引用属性(
$(SqlInstanceName)


或者有什么方法可以让它工作吗?

事实上,这可能取决于使用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>

SQL08X64
$([MSBuild]::GetRegistryValueFromView('HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL','$(SqlInstanceName'),null,RegistryView.Registry64,RegistryView.Registry32))
$([MSBuild]::GetRegistryValueFromView('HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\$(SqlInstanceKey)\MSSQLServer','LoginMode',null,RegistryView.Registry64,RegistryView.Registry32))
…效果很好