Sql server MSBuild有条件地从SSDT项目中排除存储过程

Sql server MSBuild有条件地从SSDT项目中排除存储过程,sql-server,msbuild,sql-server-data-tools,Sql Server,Msbuild,Sql Server Data Tools,我正在用SSDT在visualstudio中构建一个sqlserver数据库项目。我有一个存储过程,我只想保留它用于调试构建。当我在解决方案资源管理器中排除存储过程时,我看了一下Visual Studio是如何更新项目文件的,它似乎只是将其从名为ItemGroup的生成中删除。所以我想我可以将这个不安全的存储过程移动到一个带有自定义属性的条件后面 我将这些块添加到我的.sqlproj文件中。它应该只在调试版本中包含DangerProc.sql <PropertyGroup> &l

我正在用SSDT在visualstudio中构建一个sqlserver数据库项目。我有一个存储过程,我只想保留它用于调试构建。当我在解决方案资源管理器中排除存储过程时,我看了一下Visual Studio是如何更新项目文件的,它似乎只是将其从名为
ItemGroup
的生成中删除。所以我想我可以将这个不安全的存储过程移动到一个带有自定义属性的条件后面

我将这些块添加到我的
.sqlproj
文件中。它应该只在调试版本中包含
DangerProc.sql

<PropertyGroup>
  <IncludeDangerousProc Condition=" '$(Configuration)' == 'Debug' ">true</IncludeDangerousProc>
</PropertyGroup>

<!-- I removed the dangerous script from the main condition-free Build ItemGroup, and put it behind a conditional -->
<ItemGroup Condition=" '$(IncludeDangerousProc)' == 'true' ">
  <Build Include="DangerProc.sql" />
</ItemGroup>

<!-- Show my variables in the VS build output window -->
<Target Name="Show properties" AfterTargets="Build">
  <Message Importance="High" Text="Configuration: $(Configuration)" />
  <Message Importance="High" Text="IncludeDangerousProc: $(IncludeDangerousProc)" />
  <Exec Command="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command &quot;&amp;{ '@(Build)'.Split(';').Contains('DangerProc.sql') }&quot;">
    <Output TaskParameter="ConsoleOutput" PropertyName="BuildItemGroupContainsDangerProc" EchoOff="true" ConsoleToMSBuild="true"  />
  </Exec>

  <Message Importance="High" Text="Build Contains dangerous script: $(BuildItemGroupContainsDangerProc)" />
</Target>
.sqlproj
中,这足以将其从发布中删除。在我的
model.xml
中,某个地方似乎忽略了条件并包含了
DangerProc.sql


有人知道为什么会发生这种情况,或者我是否有其他方法可以做到这一点吗?

阅读我答案中的第二个选项
<Build Include="DangerProc.sql" />