Introduction
Nlog is a very powerful logging system. We have a very good introduction from[1]. Using NuGet, we can easily integrate NLog into our .NET project. In real world software development, we need to store our project into version control system. Naturally, we will face an issue on how to manage these NLog DLLs in version control system. Here, I have shared one way to manage these NLog DLLs.
Background
I created a demo Windows Console application by the following reference [1]. Then I used Nuget to integrate NLog into this demo console application.
My project file structure looks like below:
I set up trunk, branches and tags folder and upload this project into my version control system. Currently, I use SVN server and TortoiseSVN client to manage my project. If you browse all project folders, you will see NLog DLLs are saved under this folder NLog.4.2.3:
Under this directory NLog4.2.3, we see the DLL:
A Brutal Configuration
Under my current version policy, it is not allowed to upload any DLL into code repository including NLog DLLs assembly. So I set up my TortoiseSVN client ignore list as below:
After making code changes, I decided to submit my code to SVN server through TortoiseSVN client as the following screenshot. We can see no NLog DLLs are submitted to SVN server.
Problem
After I submit my code changes to SVN server, I need to check out for new development. Then this project contains no NLog DLLs. If we compile it, it will fail. How do we get these NLog DLLs back into this project?
Browse project folder to packages folder and we will see a folder called NLog.4.2.3, but under this folder, all NLog DLLs are missing.
Quick Fix
After I check out the most recent version of my project, I browse into packages folder. Now remove the folder NLog.4.2.3 completely.
Then, open Visual Studio and load this project into it. From Tool menu, start NuGet manager as below:
From search box, type "NLog" and hit enter. We will see the following screen. On the top right corner, we will a "Restore" button coming up. Please hit this Restore button, all missing NLog DLLs will be downloaded from online and show up in this project.
After NuGet restores all missing NLog DLLs, then rebuild this project. Everything works fine.
A Cleaner Configuration
A easier and cleaner configuration is not even to upload packages folder into version control system. Automatically all NLog related DLLs will not be uploaded to version control system. The packages folder looks like the following picture:
Here are the steps to re-load all related NLog assemblies into this project:
-
After you check out the most recent version of your project, then open Visual Studio (my version is Visual Studio 2015). Load this project.
-
From tool menu, select Build=>Clean Build. You will see the build is successful. No errors.
-
Press F5 and run your application, you will see the output window in the bottom that NuGet is automatically downloading all missing NLog assemblies. Few seconds, your application starts to run. It is even cleaner.
My Understanding
The reason behind this is that there is packages.config file under the project directory. NuGet can use this configuration file to download all missing files for Nlog package.
<!--?xml version="1.0" encoding="utf-8"?-->
<packages>
<package id="NLog" targetframework="net452" version="4.2.3">
<package id="NLog.Config" targetframework="net452" version="4.2.3">
<package id="NLog.Schema" targetframework="net452" version="4.0.0">
This is my way to manage NLog DLLs.
If you have a better way, please share it with the CodeProject community.
Hope you like this article. Thank you for reading!
Reference
- How to NLog (4.2) with VisualStudio 2015
History
- 04-02-2016: Initialized this article
- 04-09-2016: Updated this article