3

This might be a very easy to answer question but I'm losing time here trying to research silly little things so I thought I'd just pose the question here.

I have a solution in VS2013 with two projects. The main project (Startup project) is a C# Winforms project which targets a DB and the second project a SQL project which has the schema for said DB.

So I can make changes and build the SQL project. I can take snapshots and eveything works swimmingly. What I can't do is to Run the project (which should publish it into the (localdb) debug project. If I click on run, it runs the default startup project.

Of course I can temporarily set the SQL project as the default startup project, then run, then set the main project to the default startup project again.

Surely there must be a way in which I can build the SQL project and get it to publish to the debug DB all at once, or at least in easier steps as described above?

In fact, what I would ultimately like is if there was one hotkey that will build both projects, publish the SQL project to the debug DB and run the main project.

2 Answers 2

6

Never mind, I've figured it out. Go to PROJECT -> Project Dependencies...

Select the WinForms project in the "Projects:" combo box and tick the Database project in the "Depends on:" checklist box.

The WinForms project is now dependent on the Database project and if you Run the application, VS will first build the DB project, then publish it to the debug DB, then build the WinForms project and then run it. Or so it seems.

enter image description here

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

Comments

2

There are two sides to running the db deploy on each build, the on the one hand you want the db to be up to date but on the second it is quite slow and gets really irritating really quite quickly!

What you could do is to have your c# app as the startup app so pressing F5 starts it but also map a keyboard shortcut to "Build.SSDTPublishSelection", I map CTRL+6 as it is near F5 and I hadn't used that combination of shortcuts (at least not in the last 15 years!) - This only publishes the selected project so you do need to select it first in object explorer (I have that covered with another series of shortcuts which sets the focus to solution explorer and syncing with the current document - I know keyboard heaven, who needs vim and emacs ha ha)

This was you make sure the project is selected CTRL+6, publish then F5 and you should get what you want.

One additional thing is that if you haven't already, look at the add-ins that let you publish stored procs directly without going through the publish cycle, so you can make incremental changes, then when you are ready do a full publish and run all your tests (Dave Ballantyne published one: http://dataidol.com/davebally/2014/03/01/ssdt-fast-deploy/ and I have one: https://github.com/GoEddie/SSDTExtension/tree/master/download/0.4.2)

Hope it helps!

Ed Elliott

6 Comments

Thanks, this seems like a good idea but it doesn't quite work - unless there's something obvious which I'm missing. When I call Build.SSDTPublishSelection through a mapped keyboard shortcut, it brings up the "Publish Database" dialog box in which I first have to specify the Target database connection (which is empty by default) and the Database name (which is correct by default at least). I can save the profile and then load it the next time but that is even more hassle than setting the SQL project as the active project and hitting F5.
So you want to have your cake and eat it? ha ha - there are 10 external tools you can map in visual studio (Tools-->External Tools), if you map this to sqlpackage.exe and use the appropriate args (/Action:Publish etc etc), you can publish using the command Tools.ExternalCommandXX (XX is number of the command), you can use msbuild variables to get to your build directory etc so can use for multiple projects. This way you can do a publish and then start debugging, but the publish does take a little while - is that any better?
I'm sure a publish would take a while but I would think the requirement is fairly straight forward. I can't imagine how it can only be achieved through 3rd party tools. Have a look at the answer I just posted to my own question. It seems that is is possible the way I had in mind after all - unless I'm overlooking something.
If you are happy to do a compare and publish every time you run your app to debug it then cool, personally I make more app changes than db changes so it gets annoying pretty quickly (sqlpackage isn't 3rd party it is part of ssdt)
Cool whether you use F5 in VS, sqlpackage or the schema compare they all use the DacFx under the hood and do basically the same thing
|

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.