Monday 14 July 2014

Setup a k2 Custom SmartControl Project

This post describes how to set up a k2 Custom Control Project, one that will deploy the control to the GAC on a build event, it doesn't go into making the actual control or setting up a k2 server, which to me is magic. here's a quick outline

  1. create a class library project 3.5
  2. make sure it has the AssemblyInformation.cs file exposed
  3. Add post build events to copy dll to k2 runtime/design timefolders and register it in GAC
  4. Sign the assembly
  5. add references to k2 dll's

Ok to get started open Visual studio and create a new Class Library Project, give it a name like CustomControls, this project is going to contain all of your custom controls. Also make sure to change the FrameWork to 3.5

with that complete right click on the project and select the properties menu item

this will bring up the project properties window, here click on the Assembly information button

this will bring up the assembly info window, it may have blank values or they may already be filled in for you either way hit ok

this will expose the AssemblyInfo.cs file under the Properties folder in your solution explorer, there's a chance it was already visible and the previous steps where unnecessary.

either way now you have the file, next go back into the project properties this time select the build events tab and add the following command to the post build command line.

xcopy "$(TargetDir)$(TargetName).*" "C:\Program Files (x86)\K2 blackpearl\K2 SmartForms Designer\bin\" /y /r 
xcopy "$(TargetDir)$(TargetName).*" "C:\Program Files (x86)\K2 blackpearl\K2 SmartForms Runtime\bin\" /y /r 
"C:\Program Files (x86)\K2 blackpearl\Bin\controlutil.exe" register -assembly:"C:\Program Files (x86)\K2 blackpearl\K2 SmartForms Designer\bin\$(TargetName).dll"


This will copy the Complied files to both the designer and runtime folder of k2 then register the dll in the GAC

next go to the signing tab and sign the assembly.

now you are done in the project properties. in your solution explorer you can delete the auto generated class1.cs file, then add the following k2 references 

  • SourceCode.Forms.Controls.Web.dll
  • SourceCode.Forms.Controls.Web.SDK.dll
  • SourceCode.Forms.Controls.Web.Shared.dll
  • SourceCode.Forms.Web.Controls.dll
they are both located in [Program files (x86)]\K2 blackpearl\K2 SmartForms Designer\bin

and you should end up with 


Now your ready to add a smart control. which we'll do in the next post