Deploy your resource automatically from Visual Studio

In most of my JavaScript client extensibility demos, I develop the whole content of my resource ZIP files inside Visual Studio. When I press F6, magically my NAV gets updated with the latest version of JavaScript that I just wrote. So, how do I do that?

Here’s the cookbook.

There are three things you need to have for this to work. First is NAV, or better yet C/AL based. Another one is about PowerShell. And the last one, of course, is about Visual Studio.

Let’s go to the NAV end first.

I have a codeunit which registers my controls. Something like this:


This local RegisterControl functions receives all information about control add-ins it needs to register, then it creates (or updates) the Client Add-in record. It also imports the file if you provide a path to one.

So far, so good.

Obviously, what I need to do from Visual Studio when I build my solutions is to invoke this codeunit. How can Visual Studio do that? Simply, through PowerShell. So, let’s take a look at the PowerShell scrip(let) that does that. It’s simpler than you would expect:


Yes, it has some hardcoding inside, I could have done it better, but for the sake of the example, it’s good enough.

Now, the last part, the Visual Studio.

In my Visual Studio project properties, I have defined post-build event command lines that do the following:

  1. Execute VsDevCmd.bat batch file that references the paths to important command-prompt utilities of Visual Studio and .NET
  2. Delete the file from my project directory
  3. Call 7z.exe (from 7-Zip product) to zip the content of my Resource directory into the file
  4. Copy the into a temporary location
  5. Execute the PowerShell script to register the control add-ins and import the resources
  6. Clean up any temporary files
  7. Print the public key token from my output assembly

An example of one of those post-build scripts is this:


Depending on your installation, it might not just work, maybe you’d need to fix some paths. Also, you must include this PowerShell script, as well as 7z.exe in your project. I typically have a folder called Build Tools where I put all the necessary dependencies for the build process.

And that’s all.

Now, this is not the best way, of course, to do this. A much better way would be to develop build tasks, and create a Visual Studio plugin that handles all this, but just call me too lazy to do that. This simple script gets the job done for me, and if it does the same for you, all the better.

Good luck, and let me know what you think of it. It’s okay to say “this sucks”

8 thoughts on “Deploy your resource automatically from Visual Studio”

  1. Personally I never liked code outside C/AL due to deployment issues. Automating deploy process changes my mind. If your ZIP file would be stored in web repository, then deploy could be realized automatically through upgrade process calling RegisterControl.

    Thank you for sharing your work with us.

    1. Aleksander – welcome! 🙂 With control add-ins you don’t have a choice but to have code outside C/AL. However, with JavaScript, the code is at least in the database, so it is upgraded automatically. My demo here is just an example, one of possibilities. A little earlier, in my TechDays demo, you can see how to deploy new versions automatically from a web repository, as well. I’m glad you find this post useful.

Leave a Reply