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

Rog*_*mbe 4 msbuild

我正在尝试使用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>
Run Code Online (Sandbox Code Playgroud)

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

或者有一些方法可以使这项工作?

Rog*_*mbe 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>
Run Code Online (Sandbox Code Playgroud)

......工作正常.