加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 03:52:32 所属栏目:Windows 来源:网络整理
导读:我正在尝试使用MSBuild来确定SQL服务器实例是否启用了SQL身份验证.我正在尝试以下方法: Target Name="VerifySQLLoginMode" PropertyGroup SqlInstanceNameSQL08X64/SqlInstanceName SqlInstanceKey$(registry:HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicros
我正在尝试使用MSBuild来确定SQL服务器实例是否启用了SQL身份验证.我正在尝试以下方法:

<Target Name="VerifySQLLoginMode">
  <PropertyGroup>
    <SqlInstanceName>SQL08X64</SqlInstanceName>
    <SqlInstanceKey>$(registry:HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SQL ServerInstance NamesSQL@$(SqlInstanceName))</SqlInstanceKey>
    <SqlLoginMode>$(registry:HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft 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似乎不允许在$(registry:…)属性中引用属性($(SqlInstanceName)).

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

解决方法

实际上,它可能取决于使用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_MACHINESOFTWAREMicrosoftMicrosoft SQL ServerInstance NamesSQL','$(SqlInstanceName)',null,RegistryView.Registry64,RegistryView.Registry32))</SqlInstanceKey>
    <SqlLoginMode>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SQL Server$(SqlInstanceKey)MSSQLServer','LoginMode',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>

……工作正常.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读