Using MSBuild to deploy Blackfish stored procedures

by john 9/18/2007 5:44:00 AM

I've been developing some [BlackfishSQL] stored procedures. Since they are written using Delphi, the typical cycle of events is

  • Develop stored procedure
  • Compile package
  • Shutdown the [BlackfishSQL] server
  • Copy the assembly to the deploy location
  • Restart the [BlackfishSQL] server
  • Debug
  • Repeat

Its the same basic steps over and over, so I figured it was a good opportunity for a bit of automation. So I've developed an MSBuild task that is callable from the IDE. In the screen shot below can be seen a menu option named "deploy".

 

Having compiled the package containing the stored procedures, I can now select the deploy menu option.

The following actions are performed automatically for me

  • Stop the [BlackfishSQL] Server
  • Copy the assembly
  • Restart the server. 

So how did I do this ?

Starting off in my stored procedure package, the first thing I did was add a "MSBuild Targets File". This item resides in the "New Item Dialog". This can be seen in the screen shot below.

 

 The finished targets file can be seen in the next screen shot

 

Basically I developed three custom tasks in a Dephi package, referenced in the Targets file with the UsingTask xml element. I then used these references in the Target XML element. Each Target element becomes a menu option in the project manager. This can be seen in the very first screenshot.

So what does a custom task look like ?

 

In the Microsoft.Build.Utilities assembly located in the framework directory is a namespace Microsoft.Build.Utilities. Inside that namespace is a class called Task.

This class serves as a base class for your own custom tasks. For example this is the definition for my custom task TStopBlackfishSQLServiceTask.

  TStopBlackfishSQLServiceTask=class(Task)
  public
    function Execute():boolean;override;
  end;

And this is the implementation

function TStopBlackfishSQLServiceTask.Execute: boolean;
var
  mp: ManagementPath;
  wmi: ManagementObject;
begin
  mp:=ManagementPath.Create('Win32_Service.Name=''BlackfishSQL''');
  wmi:=ManagementObject.Create(mp);
  wmi.InvokeMethod('StopService',nil);
  result:=true;
end;

This task basically  stops the Blackfish server service.


I've packaged up the complete custom task project with an example targets file included.  

Once you download and have compiled you should be ready to go. The first step is to open MyTarget.Targets and modify as needed. Your most likely going to have to change the directory references to where the custom build task assembly is located and also where the stored procedure package is located.

Its assumed that you already have a project with stored procedures ready to go.

 If you take another look in the targets file I have supplied you will see this

  <ItemGroup>
        <FileToDeploy Include="c:\develop\h2\bookmarks\bookmarks.storedprocedures\bin\BookMarks.StoredProcedures.dll;c:\develop\h2\bookmarks\bookmarks.storedprocedures\bin\BookMarks.StoredProcedures.pdb"/>
  </ItemGroup>

This is where I define what files I would like the copied. 

    <TFileCopyRetry  FilesToCopy="@(FileToDeploy)" DestinationFolder="c:\develop\h2\blackfishsp" />

and the above completes the definition and indicates to copy the fies to c:\develop\h2\blackfishsp
 

As a side note, I modified  the Blackfish server service config file to load packages from this directory. The config file is BSQLServer.exe.config in the Rad Studio bin directory.

For me the bottom of this file looks like
 

          <add key="blackfishsql.assemblyPath"          value="c:\develop\h2\blackfishsp" />
  </appSettings>
</configuration>


 

The full source code can be downloaded from CodeCentral at this location.

 
Any feedback is welcome. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Delphi | Blackfish | msbuild

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author John Moshakis
I'm a software developer living in Toronto..

E-mail me Send mail

Calendar

<<  November 2017  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Authors

    Tags

    Don't show

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2017

      Sign in