SSDT - pre-build automation - setting 'buildAction' flag for stored procedure

陌路散爱 提交于 2021-01-29 08:43:18

问题


I am wondering if anyone has an example of setting a Pre-Build Event (project properties, Build events) on an SSDT project so that we can change a files 'Build Action' from 'build' to None given a project configuration.

Something like: if $configuration is x then set buildAction = 'none' on abc.sql else set buildAction = 'build'

Regards


回答1:


If you have different implementations of the same stored procedure, then you'll probably have 2 options:

  • Create conditional logic inside SP. You'll need to define variable value when publishing and in the code you'll have something like:
    IF ('$(EnvVar)' = 'PROD')
    BEGIN
       -- code needed to be executed in PROD
    END
    IF ('$(EnvVar)' = 'DEV')
    BEGIN
       -- code needed to be executed in DEV
    END
  • Create 2 (or you might need more) projects that would have that single procedure (or set of objects) with different implementations. Then add the reference to your main project with an option "The same database". Then create different publish profiles in the projects and use proper connection strings there.



回答2:


I resolved this by using a pre-build event to copy a clone of the stored procs into the correct location depending on the build setting. So I have marked the above as an answer as well.

I could have also used a .tt file to generate the stored procedure at build time.



来源:https://stackoverflow.com/questions/64343846/ssdt-pre-build-automation-setting-buildaction-flag-for-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!