Visual Studio Control Add-in Project Template

If part of your daily job includes creating control add-ins for Microsoft Dynamics NAV, then you know that creating control add-ins that target all clients requires quite a lot manual work. There are a lot of small steps that you must do every time.

To avoid all that work that adds no value, only frustration, here’s a Visual Studio project template that you can use to automate the process of creating a new control add-in.

First, download the project template by clicking here.

Then, to install it on your machine, take the ZIP file you downloaded, and put it to:

Documents\Visual Studio 20xx\Templates\ProjectTemplates

Just place the ZIP there, no need to unpack anything.

To use it, (re)start Visual Studio, and then in your New Project window, select Templates > Visual C#, then scroll to the bottom and select this little guy:

image

Then set the name of the project, click OK, and you have your new shiny control add-in project structure in place.

To make full use of it:

  • Choose a strong name file to sign the project with. The PowerShell script that runs after building will remind you of this if you forget.
  • Edit the IControlAddIn.cs file to change the value of the ControlAddInExport attribute.

At this stage, you can already press F6 to build it, and it will immediately find its way into Control Add-ins page in NAV, together with the resource file.

After first build, PowerShell script will create the Resource subfolder and create a default resource file structure and a manifest file in there. The files are present inside the project folder, but are not part of the project. It’s a good idea to make them a part of the project, so do this:

  • In Solution Explorer, click the Show All Files icon
  • Right click the Resources folder
  • Click Include in Project

image

And that’s all. Inside your Resource Folder you’ll have a subfolder for every control add-in of interface type that you add to this project, and there you’ll find the Manifest file, subfolder for each resource type, jQuery 2.1.4, and the IControlAddIn.js script that should contain your JavaScript code.

Have fun creating your new control add-ins, and let me know if you find this little tool useful.

Vjeko

Vjeko has been writing code for living since 1995, and he has shared his knowledge and experience in presentations, articles, blogs, and elsewhere since 2002. Hopelessly curious, passionate about technology, avid language learner no matter human or computer.

This Post Has 23 Comments

  1. Oliver Kunz

    Hi Vjeko,

    I’m trying to use the VS-Template but there is an error shown on compiling the solution: while executing the PostBuild.ps1 the following error (translated) shows up:
    “Error on calling method, because [System.Management.ManagementClass] contains no method with name “new”.
    In C:\…AddIn\_build\PostBuild.ps1:39 Zeichen:18″
    which is the line:
    “foreach ($mo in [System.Management.ManagementClass]::new(“Win32_Service”).GetInstances())”

    I’ve Nav2013 installed and OS is Win7Prof

    Thanks for the really great session on NavTechDays!!

    Oliver

    1. Vjeko

      Thanks, Oliver! I can only suspect that you don’t have the right version of .NET installed here. I have developed this under Windows 10, with no special additional software installed. I don’t know how much of it will run under Windows 7. Can you try this under Windows 10?

      1. Oliver Kunz

        That’s logical. I’ll try it. Seems that W10 has added the method, because even in .NET 4.6 the new-method is missing.
        Thanks for your quick answer.

    2. Konrad Milewski

      Had the same problem, I think its Powershell version issue. Changing the fallowing lines worked for me:

      foreach ($mo in [System.Management.ManagementClass]::new(“Win32_Service”).GetInstances())
      {

      to

      $mc = New-Object System.Management.ManagementClass “Win32_Service”
      foreach ($mo in $mc.GetInstances())
      {

      and

      Import-Module -FullyQualifiedName $path

      to

      Import-Module -Name $path

      and

      $zip = [Ionic.Zip.ZipFile]::new()

      to

      $zip = New-Object Ionic.Zip.ZipFile;

      1. Oliver Kunz

        This nearly works The method Set-NAVAddIn is still unknown. The other errors are gone. Thanks.

        1. Vjeko

          Do you have NAV 2016?

          1. Oliver Kunz

            I already figured out that this command is part of 2016 only. We have 2013 active, so the script cannot be run errorfree. Beginning of next year we will get 2016 – so i wait with it until then 🙂

  2. John

    I can’t seem to get the scroll bars to show on the addin page. My html just continues down below the border of the page. If I mark the text it scrolls down, but no scroll bars appear.

    Do you have a solution to that? I have tried several suggestions from other blogs, but I can’t seem to get it to show.

    1. Krisje

      Hi John,

      I’m facing the same issue, did you found a fix for it ?

      Ps, tx for the template Vjeko, It’s an awesome tool !!!

      1. John

        I think this is how I got around it:

        function _stretchContainer() {
        var $iframe = $(window.frameElement);
        if ($iframe) {
        if ($iframe.length === 0) {
        alert(‘iFrame not found’);
        return;
        }
        }
        else {
        return;
        }

        var $scrollContainer = $iframe.closest(‘.ms-nav-scrollable’);
        if ($scrollContainer) {
        if ($scrollContainer.length !== 0) {
        var $addinContainer = $iframe.closest(‘.spa-container’);
        if ($addinContainer) {
        if ($addinContainer.length !== 0) {
        var containerHeight = $addinContainer[0].getBoundingClientRect().height;
        if (Microsoft.Dynamics.NAV.GetEnvironment().Platform == 1) {
        containerHeight = containerHeight – 150;
        }
        else {
        containerHeight = containerHeight – 350;
        }

        $iframe.css(‘height’, containerHeight + ‘px’);
        $iframe.css(‘max-height’, containerHeight + ‘px’);
        }
        }
        return;
        }
        }
        };

        $(window).bind(“resize”, function () {
        _stretchContainer();
        });

        1. Antonio

          On Nav2016 CU6 :

          var $scrollContainer = $iframe.closest(‘.ms-nav-scrollable’);

          has lenght equal zero. So your function cannot work. Can you tell me your enviroment?

          1. Vjeko

            It may depend on the type of page you are using. What’s your page type? Also, it may depend on how you are loading the page – this works when loading pages directly through ?page=PageIdNumber query string parameter.

  3. Ben

    Hey Vjeko,
    first of all: Thank you, this is really helpful.
    But i think the Line 45

    has to be
    $path = $path.Substring(0, $path.IndexOf(“$”)-3)
    because in my case the device Letter “C” was cut

    this line solved a lot of failures.
    Thanks Ben

  4. Vijay

    I am getting below error while loading the project. i am using VS 2010.

    This project is incompatible with the current version of Visual Studio.

  5. isil

    I got this error while compiling:

    “set nst=DynamicsNAV90
    powershell -ExecutionPolicy unrestricted -command “&’C:\KasaControlsAddin\KasaControlsAddin\_build\PostBuild.ps1′ -DllFile ‘C:\KasaControlsAddin\KasaControlsAddin\bin\Debug\KasaControlsAddin.dll’ -ServerInstance ‘%nst%’ -ProjectPath ‘C:\KasaControlsAddin\KasaControlsAddin\KasaControlsAddin.csproj’ -SolutionDir ‘C:\KasaControlsAddin\’ -Configuration ‘Debug'””

    1. Vjeko

      You need to change the execution policy of your scripting environment. Google can help 😉

    2. Vjeko

      Which error did you get?

      1. josete

        I got the same error:

        Error The command “set nst=DynamicsNAV90
        powershell -ExecutionPolicy unrestricted -command “&’c:\users\jose.albertino\documents\visual studio 2015\Projects\Add-in Matrix\Add-in Matrix\_build\PostBuild.ps1′ -DllFile ‘c:\users\jose.albertino\documents\visual studio 2015\Projects\Add-in Matrix\Add-in Matrix\bin\Debug\Add-in Matrix.dll’ -ServerInstance ‘%nst%’ -ProjectPath ‘c:\users\jose.albertino\documents\visual studio 2015\Projects\Add-in Matrix\Add-in Matrix\Add-in Matrix.csproj’ -SolutionDir ‘c:\users\jose.albertino\documents\visual studio 2015\Projects\Add-in Matrix\’ -Configuration ‘Debug'”” exited with code 1. Add-in Matrix

        Could you help me?

        Thanks!

        1. josete

          I fixed. I run through Powershell the line post-build in order to see the error.I forgot to sign the assembly.

        2. Vjeko

          You must run VS as Administrator. This is the most common cause of this error. If you do run it as Administrator and still get this, then you’ll have to troubleshoot yourself. Simply take the command it generated and try to run it from the Developer Command Prompt.

  6. Jaspreet

    Hi Vjeko,
    Inspiring blogs

    I have a question about a navtech video of yours. Addin blackbelt https://www.youtube.com/watch?v=UCNdJJzI2kw

    I wanted to follow along. Did you provide access to the source code of demos in there ?

Leave a Reply