10

Although I can find (on the web) a lot of information about the PreDeploy and PostDeploy Build Action for SQL scripts in a Visual Studio 2012 Database project and I understand that None does not compile or include the script when deploying, please can any one definitively advise or direct me to an article that does definitively define the subtleties of Build and Compile?

My rough assumption is both of these will compile against the schema, but only Build will be deployed. Is this correct?

What I would like is the correct setting to validate my seeding scripts against the current schema (and cause a build error on invalid schema structure) but to NOT deploy with a database publish or show up in a schema compare session.

Dib
  • 2,001
  • 2
  • 29
  • 45
  • BTW, the nice detailed answer in [this](http://stackoverflow.com/questions/145752/what-are-the-various-build-action-settings-in-visual-studio-project-properties) post is not in the context of the database project. – Dib Aug 11 '16 at 16:10
  • Well, "Build" in the context of a post-deploy/pre-deploy script will only let you have one. The rest are "includes" to that script. You don't want to try setting those files to "build" because the compiler will try to build them as tables/views/other objects. I have not tried to set them to Compile before so no idea what that would do. I usually leave them as "None" and check them carefully when writing them. You can write some try/catch logic around them to help catch errors. They won't deploy w/ a DB publish unless you include them. – Peter Schott Sep 13 '16 at 18:01

2 Answers2

4

In a database project, "Build" is used for sql files and "Compile" is used for C# or VB (i.e. SQL CLR) files. When building a database project, the output is a dacpac file containing the processed "Build" sql files and a .NET assembly (dll) file containing the processed "Compile" C# or VB files.

Files marked as "None" are simply ignored.

Steven Green
  • 3,387
  • 14
  • 17
0

I just found this out the hard way, but apparently a typo such as "Built" (instead of "Build") acts the same way as "None". I haven't confirmed, but presumably any word that doesn't match a valid value will be treated the same way as "None" and the build will just skip it.

Side Note: I think I'd probably prefer the build to fail on an unknown value, but it should be easy enough to script a gated-checkin to detect it too.

TTT
  • 22,611
  • 8
  • 63
  • 69