Organizing Your SDL Tridion Dependencies with Sonatype Nexus

Author, Thijs Borst

Author, Thijs Borst

by  Thijs Borst

As a Tridion developer I’m used to adding the Tridion dll’s and jar files to the source code. But this isn’t the way it should be done. There are better ways to organize those dependencies. In a purist thought, there is no place for compiled code in your source code repository.

Nexus

You already know about NuGet right, that package manager that lives inside Visual Studio? Well, you could create your own private repository using Sonatype Nexus. This repository plaform allows you to store Maven artifacts like jar file and NuGet packages like dll files. It also supports npm repositories (Javascript packages) and Ruby gems.

Nexus can also function as a repository proxy and allows you to group several repositories into one repository. So you can combine your own repositories and hosted repositories (like nuget.org or maven central). This allows you to use one repository for all of your projects. More information about Nexus and the possibilities can be found at http://www.sonatype.org/nexus. We’re going to see what Nexus can do for us Tridion developers.

Installing Nexus

So this plaform will allow us to host all those needed dll and jar files for Tridion. Which makes it easier for you to manage your dependencies. First we need to install Nexus. Download Nexus here. You can find the instructions for installing it here, it runs on either Linux, Mac or Windows.

Configuring Nexus

Creating a NuGet Repository

Now Nexus is installed we need to create a NuGet repository to host our NuGet packages. Open up nexus in your browser and log in. Open up your repositories and click Add > Hosted Repository.
Add repository

Fill in the required fields and select NuGet in the provider field.
Create a nuget repositoryNow we have a nuget repository.

Configuring Visual Studio

Now that the repository has been created, we need to add it to visual studio.
Perform the following command and replace the tokens with your own information. Be aware that the url in the repository overview is not the url you need. You need to select the repository and go to the NuGet tab.
NuGet Url

Copy the url of the repository and use that to replace the URL token in the command. The NAME token is a name of your choice, but I would suggest to use the same names on each machine in the company or project team.

"C:\Program Files (x86)\NuGet\NuGet.exe" sources Add -Name [NAME] -Source [URL] -UserName [USERNAME] -Password [PASSWORD]

Once you’ve performed the command, you’ll see something like this:
After command

After this, open visual studio. Click on TOOLS > NuGet Package Manager > Package Manager Settings and select Package Sources in the left pane. You’ll see that your NuGet Repository is added.

VS2013 NuGet Repositories

Note, that this repository is not yet configured in a group which is recommended. Also permissions have to be set. Please refer to the nexus book on how to configure this.

Creating NuGet packages from Tridion dll’s

Now we have our repositories we can start uploading packages. But first we’ll need to create those packages. I’ve create an automated process for this. Checkout the script on GitHub here. The msbuild file will create all nuget packages for you. I’ve created a folder structure under packages to put your dll’s in. If you want to create more packages just create a new folder and put the dll’s in. This will create a nuget package for that folder too. The packages are compatible with .NET 4.0 and .NET 4.5.

Open up the directory and place the Tridion dll’s in their respected folders under Packages. The packages are created using a nuspec file. This nuspec file has some information about the package. Like who is the author, copyright, etc… I’ve created a skeleton nuspec file which has basic information about the package. This can be altered to suit your needs. The copyright, the id and the description are being overwritten by the script. The nuspec reference can be found here.

To run the script and render the packages perform the following command:

"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" PackageCreator.msbuild

After this has run, the NuGet packages can be found in the build/packages folder. These packages are now ready to be uploaded into Tridion. To upload your nuget packages into the nuget repository we’re using the nexus interface. Go to repositories and find your nuget repo. Select it and go to the NuPkg Upload tab. Select browse and lookup your packages under build/packages. Add all your packages and press Upload Packages.
Upload nuget packages

To verify, open your Visual studio create a new project and select Manage NuGet Packages, when right clicking on your project. Then select your repository under online. You’ll notice that your packages are now available:

Visual Studio NuGet packages

If you want to upload updates, update the version in the nuspec skeleton and repeat the process. The package will then be uploaded being an update. Visual Studio can then see your updated package and all your projects can bring that update in too.

Maven

Maven dependencies could also be stored in here, but unfortunatly we can’t derive a version number from the jar files. Now, we could also do this with our own version numbers, or use a date as a version number.

Do you have any suggestions on how to solve it?

References

The following two tabs change content below.

Thijs Borst

Consultant / Architect at Tridion
Thijs is a Certified SDL Tridion Consultant with 9 years of experience working at Incentro and has over 15 years of experience in the online world as a developer. He has developed and designed numerous enterprise websites over the years with a high regard to quality. In his experience he has worked with a lot of different development tools and developing in various languages like java, .net, php, javascript etc. He is now advocating and introducing these tools in the Tridion community, tools like Continuous Integration, Dependency Management and Quality Management tools. In his free time he's attending to his drone fleet or catching a movie.

Latest posts by Thijs Borst (see all)

Authors

Related posts

*

Top