Two Approaches to Addressing Circular References in SSDT

  • hakim.ali

    SSCarpal Tunnel

    Points: 4236

    Comments posted to this topic are about the item Two Approaches to Addressing Circular References in SSDT

    Hakim Ali
    www.sqlzen.com

  • justin.goldberg

    SSC Journeyman

    Points: 78

    We have a similar situation but scaled to around 6 databases with circular references to each other. This occured due to bad practices over the years and we're cleaning this up over time. We reference dacpacs instead of database projects because we want to deploy each DB independently. 

    We worked around this a different way. You cant build your project to extract a dacpac file due to the circular references however you can extract the dacpac from the prod/target database itself. Once you have this you can reference the dacpac and build your project. Lets say you have DatabaseA reference DatabaseB. You extract DatabaseB initially and DatabaseA can now reference the DatabaseB's dacpac. You can now build DatabaseA. DatabaseB can now reference DatabaseA's dacpac. For each change you can update the dacpac after the build is successful so you no longer need to extract the dacpac files. Once you get the train moving this works out ok, its just the initial extraction thats required.

    To reference the dacpac from DatabaseB we create a Nuget package from the build and in the DatabaseA project we download the latest Nuget package in a prebuild step to a known subfolder and reference the relative location..

  • hakim.ali

    SSCarpal Tunnel

    Points: 4236

    justin.goldberg - Monday, June 12, 2017 7:06 PM

    ...You cant build your project to extract a dacpac file due to the circular references...

    Thanks for the comments. You can actually do this. Look in the \bin\Debug folder of your projects, the dacpac files are already there. You can use these, and get around the circular dependency issue by checking the box to 'Suppress errors caused by unresolved references in the referenced project'.

    Hakim Ali
    www.sqlzen.com

  • justin.goldberg

    SSC Journeyman

    Points: 78

    hakim.ali - Tuesday, June 13, 2017 8:10 AM

    justin.goldberg - Monday, June 12, 2017 7:06 PM

    ...You cant build your project to extract a dacpac file due to the circular references...

    Thanks for the comments. You can actually do this. Look in the \bin\Debug folder of your projects, the dacpac files are already there. You can use these, and get around the circular dependency issue by checking the box to 'Suppress errors caused by unresolved references in the referenced project'.

    Good point however I wouldnt want this on indefinitely otherwise having automated builds wouldnt catch any issues.

  • hakim.ali

    SSCarpal Tunnel

    Points: 4236

    justin.goldberg - Wednesday, June 14, 2017 5:43 PM

    Good point however I wouldnt want this on indefinitely otherwise having automated builds wouldnt catch any issues.

    It would, actually. Let me explain. In your build project, say you have references to a dacpac. Let's call these level 1 references. The project you took the dacpac from, and hence the dacpac, also has references to other projects/dacpacs. Let's call these level 2 references. Checking that box only suppresses level 2 references, not level 1. So your build project would still get validated against all its level 1 references. Make sense?

    Hakim Ali
    www.sqlzen.com

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply