2

When I choose "Publish..." from a Visual Studio database project, it looks like, among other things, it runs the project's scripts on the database, but only the ones that have Build Action set to "Build". In other words, Build Action "None" scripts don't get run on the database as part of a Publish.

I have a database project but I do not have all the database's items in that project. Can I still keep scripts (for example, for stored procedures) in my project and run them on the database? How? If I set them to "Build", I get build errors, because the items they depend on are not in the project. If I set them to "None", they don't run on the database at all. Is there a way to make them run on the database without needing their dependent items? If not, what is the best way to do this?

4
  • Can you give us a little more background on why the whole database isn't in the project? Is this a third party DB? Trying to understand so we can provide the best guidance on how you might proceed. Commented May 1, 2014 at 14:57
  • Because others will update the database objects outside of this project, and because the database is quite big and my team that will use version control is only responsible for a part of it. Commented May 1, 2014 at 15:52
  • You might be able to get away with this if you pull a copy of the current DB into a dacpac then add it as a DB reference. That should give you all of the dependencies you need for the objects you're maintaining. I can't say how it would publish from there, though. That would be something to test. You can also edit that dacpac and re-sign it to remove extra objects if you want to go that route. Commented May 2, 2014 at 20:09
  • 1
    FYI Scripts with Build Action=None are not supposed to be run during publish, only when Build Action is PreDeploy or PostDeploy. The best approach is to fix the build errors by resolving those dependencies. Commented May 6, 2014 at 13:45

2 Answers 2

1

You could try setting the build action to none on the script, and then running the script from a post-deployment script.

There can only be one post-deployment script in each database project. You can add it by adding a new item and searching for post-deployment. Within the script, you use the command syntax to execute scripts.

http://www.mssqltips.com/sqlservertutorial/3006/working-with-pre-and-post-deployment-scripts/

Sign up to request clarification or add additional context in comments.

Comments

0

It seems like there is no way to do what I am looking for; that Database projects were meant to have all the dependencies resolved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.