You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 23 Next »

 

 

Exercise outline

The goal of this exercise is to show how a new plugin can be developed using the Delta Shell Application plugin NuGet package. The Delta Shell NuGet package will be used in order to make a quick start. The screenshots included in this whole tutorial may differ, depending on which version of Visual Studio is used. Most of the figures have been created using VS 2013, and some with VS 2015.

Create a new C# project

Start Visual Studio and create a new C# project (File | New | Project...) by configuring the project wizard as shown in the following image:

 

Afterwards, a solution should be created with a structure as shown in the following image:



The default class named Class1.cs can be removed.

Add the Delta Shell application plugin package to the project using NuGet

A Visual Studio extension called NuGet will be used to add the Delta Shell application plugin package to the newly created project.

General information about NuGet can be found at http://docs.nuget.org/.

Information on how to install NuGet as a Visual Studio extension can be found at http://docs.nuget.org/docs/start-here/installing-nuget.

As of Visual Studio 2013, NuGet is installed by default. However, you have to make sure that it is updated to the latest version by checking the Extension and Updates window (click TOOLS | Extensions and Updates... | Updates | Visual Studio Gallery). If a previous version is used, installing the Delta Shell application plugin package might result in the following error:

 

The Delta Shell application plugin package is built on the TeamCity build server. We must add the build server package feed address to the package locations of NuGet. This can be done, by opening the options of Visual studio (click TOOLS | Options) and browse to the section Package Sources in the settings for the NuGet Package Manager.

 

In the Package Sources, add a new source by using the + button and add the following information :

 

It is also possible to use the packages from a local source, if you have the files on your system. In this case, the source would be the folder in the computer in which the NuGet package files can be found. For example:

NameLocal Packages
SourceD:\localNuGet

 


In order to make use of the Delta Shell Application Plugin, open the NuGet package manager (right click the solution | Manage NuGet Packages for Solution...) and search for the Delta Shell application plugin package in the source that you want to use. For example, if you select TeamCityAuth, shown in a solid line in the figure, Visual Studio will contact the build server above indicated, and will show the available packages in there:

Alternatively, if you want to use your local source, simply select the previously indicated feed source, Local packages in a dashed line in the figure above.

In other versions of Visual Studio, the interface can be slightly different, for example in VS 2015, the source of the packages can be found in a drop down menu on the NuGet Solution view (highlighted in orange):

In either case, proceed to install the Delta Shel Application plugin.

In Visual Studio 2013, you will be asked to select the project into which you want to INSTALL the NuGet package. Select Deltashell.Plugins.VolumeModel :

If asked for confirmation, respond affirmatively to complete the installation of the packages. NuGet will now either contact the server and then download the Delta Shell framework package, or retrieve it from the local folder. Then, it will run the corresponding install scripts to configure your project for use as a Delta Shell plugin. This whole process may take a while.

After installing the package your project will look something like this :

Remove PostSharp from project

In this tutorial we don't use PostSharp because it needs a license. PostSharp is mostly used for automatically adding code for property and collection changed events and event bubbling.

To remove PostSharp do the following :

  1. Remove PostSharp reference and "RequiresPostSharp.cs" from the project (see the selected items in previous image)
  2. Open the packages.config and remove the PostSharp reference "<package id="PostSharp" version="2.1.7.28" targetFramework="net40" />"
  3. Unload the project (right click on project - Unload project)
    Edit project file (right click on project - Edit DeltaShell.Plugins.VolumeModel.csproj)
    Remove (near the end of the csproj) <Import Project="..\packages\PostSharp.2.1.7.28\tools\PostSharp.targets" Condition="Exists('..\packages\PostSharp.2.1.7.28\tools\PostSharp.targets')" />
    Load project

Set startup project

Start building the project. This will copy DeltaShell to the bin folder next to your solution file (D:\VolumeModel\bin)
Now open the project properties and go to the debug page and change set the startup program to : D:\VolumeModel\bin\Debug\DeltaShell\DeltaShell.Gui.exe

Create an application plugin class

Add a class named VolumeModelApplicationPlugin to the project and add the following code describing the application part of the plugin:

using DelftTools.Shell.Core;
using Mono.Addins;

namespace DeltaShell.Plugins.VolumeModel
{
    [Extension(typeof(IPlugin))]
    public class VolumeModelApplicationPlugin : ApplicationPlugin
    {
        public override string Name
        {
            get { return "VolumeModelApplication"; }
        }
        public override string DisplayName
        {
            get { return "Volume model application"; }
        }
        public override string Description
        {
            get { return "Application plugin of the volume model application"; }
        }
        public override string Version
        {
            get { return "1.0"; }
        }
        public override string FileFormatVersion
        {
            get { return "1.0"; }
        }
    }
}

Created a GUI plugin class

Create a class named VolumeModelGuiPlugin to the project and add the following code describing Gui part of the plugin:

using DelftTools.Shell.Core;
using DelftTools.Shell.Gui;
using Mono.Addins;
namespace DeltaShell.Plugins.VolumeModel
{
    [Extension(typeof(IPlugin))]
    public class VolumeModelGuiPlugin : GuiPlugin
    {
        public override string Name
        {
            get { return "VolumeModelApplicationUI"; }
        }
        public override string DisplayName
        {
            get { return "Volume model application (UI)"; }
        }
        public override string Description
        {
            get { return "Gui plugin of the volume model application"; }
        }
        public override string Version
        {
            get { return "1.0"; }
        }
        public override string FileFormatVersion
        {
            get { return "1.0"; }
        }
    }
}

 

To get the code above to work, we need to add a reference to DelftTools.Shell.Gui in the project.

 

The dll referred to can be found in the folder packages of the project:

 

Set local copy of reference to False

Important: Once the reference has been added, set the Copy Local property of the DelftTools.Shell.Gui reference to False. The DeltaShell framework will have already copied it to the bin, so we do not need to copy the DelftTools.Shell.Gui.dll to our plugin folder.

Exercise results

Run the application and open the Plugins window (File | Plugins ). Check that both the Volume model application plugin and the Volume model application (UI) plugin are visible in the overview of loaded plugins:

  • No labels