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:

Blackfish | Delphi | msbuild

MSBuild Sidekick

by john 3/26/2007 4:39:00 AM

There is quite a bit to learn when it comes to [MSBuild], the new build engine inside [Delphi2007]

So I've been hunting around for a msbuild editor and I came across [MSBuildSideKick]. This is a really nice gui based editor for editing msbuild files.

Currently to open [Delphi2007]  project files you have to tweak a file that gets installed by [Delphi2007] in one of the dotnet directories, on my system its C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

The file in question is Borland.Common.Targets. If you plan on modifying it, make sure you keep a backup of the file in question .

 

Inside the file is this piece of xml
 

    <!--
    ========================================================================
                             Load Options File
        Load a standard options file the user can define.  This allows
        users to store common paths and compiler options in a single
        msbuild project to simplify the building of large projects with
        many msbuild files.
    ========================================================================
    -->

    <Import Project="$(GlobalOptionFile)" Condition=" Exists('$(GlobalOptionFile)') "/>

 

You need to remove the xml comments so that you just have


    <Import Project="$(GlobalOptionFile)" Condition=" Exists('$(GlobalOptionFile)') "/>

 
So following on from this blog post  , here is the Delphi Project File buildthis.dproj in [msbuildsidekick]

MSBuild Sidekick 

I contacted the [msbuildsidekick] developers and they acknowledged that there was a bug with how imports where handled and they expect to release a patch soon. 

Currently rated 5.0 by 1 people

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

Tags:

CodeGear | msbuild | Delphi

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

<<  June 2021  >>
MoTuWeThFrSaSu
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

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 2021

      Sign in