Take Advantage of Kentico’s NuGet Feed and Build Your Own Apps
With the release of Kentico 9, we introduced a set of NuGet packages which play an important role in our newly available support for MVC. One of these packages stands out from the others. This package is Kentico.Libraries, and in this article, we'll talk about how you can use it to build your own apps. Using the Kentico API has never been easier.
Kentico.Libraries is a NuGet package containing the full set of Kentico DLLs (CMS.*.dll), giving you every DLL you might need during implementation. These assemblies allow you to:
- Work with Kentico objects in a strongly-typed manner (using *Info classes).
- Avoid writing SQL queries to perform CRUD operations directly on Kentico database.
- Retrieve data via ObjectQuery and DocumentQuery.
- Take advantage of tons of helper classes and managers.
When manipulating objects, it's also safer to use the API instead of querying the database directly. The API does a lot more than one would think it does. Consider what’s involved in moving a page; it's not just about changing the page’s parent id reference (NodeParentID). The API also automatically changes the NodeAliasPath of the page and all of its child pages. Besides that, it creates page aliases to keep the old URLs working. When using the API, you get all this functionality free of charge.
Installing the Package
To install the package, use the NuGet package manager and search for "Kentico.Libraries" on the "nuget.org" feed. Or, just run "Install-Package Kentico.Libraries" from your package manager console.
Initializing the Kentico API
To successfully use the API you must:
1) Set the connection string, either in app.config:
<add name="CMSConnectionString" connectionString="Data Source=.\SQLExpress;Initial Catalog=k90;Integrated Security=True;User ID=;Password=;Connect Timeout=60" />
Or in the code:
CMS.DataEngine.ConnectionHelper.ConnectionString = @"Data Source=.\SQLExpress;Initial Catalog=k90;Integrated Security=True;User ID=;Password=;Connect Timeout=60";
2) Perform initialization by calling:
3) Optionally, for APIs that work with file-system, you can point the API to Kentico's web application root:
CMS.Base.SystemContext.WebApplicationPhysicalPath = @"c:\inetpub\wwwroot\kentico9\cms";
Details on the process can be found in the documentation.
In our GitHub Samples repository, you'll find the code for two very simple apps demonstrating various ways to use the API.
With every new hotfix, there is a new version of Kentico.Libraries. It's not necessary to update your app with each new package or to keep the NuGet package version in sync with your Kentico instance. However, if there was a bug in our assemblies; you can simply update the package to a higher version, and your solution should still compile because Kentico's public-facing API never changes as the result of a hotfix.
Kentico builds the package against .NET 4.5 (net45 moniker), which means you can use it with the majority of project types including WinForms, WPF, ASP.NET web apps, and others targeting the full framework from versions 4.5 through 4.6.1.
Though the NuGet package doesn't bring any new functionality, we believe it deserves attention. It can make some CI or developer tasks much more convenient (for example: using it when implementing incoming synchronization via the integration bus). The package presents a whole new way for the community to integrate with Kentico.
Go ahead, fork the repo and have fun with it!