WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 520 reviews for our classroom and online training
SSRS custom assemblies using C# or VB
Part five of a six-part series of blogs

Reporting Services allows you to write functions in C# or Visual Basic, then reference these as custom assemblies. This blog shows how - and why - you might do this.

  1. Creating Custom Assemblies in Reporting Services
  2. Creating a Project, Class and Function in VB or C#
  3. Create and Deploy the Code DLL
  4. Referencing and Using Custom Assemblies in Reports
  5. Post-Build Events to Help Deployment (this blog)
  6. Debugging Custom Assemblies

Posted by Andy Brown on 03 August 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Post-Build Events to Help Deployment

Sooner or later (probably sooner) you'll get sick of copying DLL files from your class library to your report server projects, and you'll start wondering why Visual Studio can't copy the files for you automatically.  The answer is that it can, if you set up post-build events.

A post-build event is one which is triggered automatically whenever you build a project.

 Creating Post-Build Events for C# Class Libraries

If you're coding custom assemblies in C#, first display the properties of your project:

Displaying properties of project

Right-click on the Properties category of the project in Solution Explorer, and choose to open it.


Now choose to create a post-build event:

  1. Choose Build Events.
  2. Click in the post-build event command line.
  3. Click on the Edit Post-build... button.

These steps are shown below:

Post-build events

The numbered steps to follow to start creating post-build events.


Now build up the commands that you want to run:

  1. Start typing a valid command.
  2. Click on the <><> button to insert preset folder paths.
  3. Click on the folder path you want to use.

Here are the numbered steps:

Creating macros for post-build events

The steps to follow to create post-build events.

When you've finished, select OK to review your post-build event command line:

Example of command lines

These commands are given in full below.

The commands above are:

Command What it will do
copy /y "$(TargetPath)" "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies" Copy the DLL built for the project to the Visual Studio report preview folder on the author's computer.
copy /y "$(TargetPath)" "C:\Program Files\Microsoft SQL Server\MSRS10_50.SQL2008R2\Reporting Services\ReportServer\bin" Copy the DLL built for the project to the deployment folder on the author's computer. 

The /y switch means that SSRS will overwrite any files on the target folder.

Creating Post-Build Events for VB Class Libraries

The procedure for Visual Basic is nearly the same.  First display the project's properties:

VB project properties

First right click on the VB class library project, and choose to display its properties.


Choose the Compile tab:

The Compile tab

Click on this tab to go to post-build events.

You can now go to the project's post-build events:

Build Events button

Click on the button shown at the bottom right of the dialog box.


From this point, you can continue as for C# post-build events.

Things to Watch Out For

There is one thing which catches me out every time!

If you're previewing a report using a custom assembly, you won't be able to build the project (if it's using post-build events to copy the DLL over, that is) until you return to design view for the report.

This blog has 0 threads Add post