My team has gone years (before I joined) of not adopting sql server database projects. Primarily because there are items that have circular references therefor can't build. I realize the recommended approach is to factor out or fix the circular references.
However to prove we can use them without having to fix all that technical debt, I'd like to hook my sql server project's build process to remove the items from the Build
item group. I'm very familiar with msbuild but so far nothing seems to be changing that file being included in the build and failing it.
Setting the file(s) to None
instead of Build
works fine, until we try to do a schema compare. Where it either sets them back to build, or adds them again with a new file name ending in _1.sql
<Target Name="CustomSqlHook" BeforeTargets="CheckRequiredProperties;BeforeBuild;All;_SetupSqlBuildInputs;SqlBuild;SqlStaticCodeAnalysis;ResolveArtifactReferences;Build">
<Message Text="Build Before: @(Build)" Importance="high" />
<Message Importance="High" Text="custom sql hooked" />
<Message Importance="High" Text="build items are @(Build->Count())" />
<ItemGroup>
<Build Remove="project\Views\uvw_survey_history.sql" />
</ItemGroup>
<Message Text="-------------------------" />
<Message Text="Build After: @(Build)" Importance="high" />
<Message Importance="High" Text="build items are @(Build->Count())" />
</Target>
which shows the count of included items in the build group as going from 2978 to 2977. However the build still fails on the same file.