Programming C#

Florian Rappl, Department of Theoretical Physics, University of Regensburg

Programming C#

Day 8: Libraries and NuGet, work on the projects

Content

  • What are libraries?
  • Creating (CLR) libraries with C#
  • Package managers
  • The NuGet package manager
  • Overall project structure

What are libraries?

  • A library is a compiled binary
  • The only difference to an executable is that no Main() is defined
  • A library consists of types and functionality
  • Using 3rd party libraries boosts our productivity
  • There are great libraries written in C# or
  • Libraries that just wrap native libraries
  • We already use libraries if we use the .NET-Framework

Creating a library with C#

  • In Visual Studio: Start, New Project, C#, Class Library
  • Libraries are the most efficient way to re-use projects
  • Libraries are to the OS as what classes are to C#
  • They improve reusability and encapsulation
  • MSIL libraries also contain meta-data for reflection

A CLR assembly

Package managers

  • Using external libraries is quite easy
  • The hard part is maintenance and dependencies
  • We have to keep them up-to-date and we might need other libraries
  • This can get quite cruel, since where to get is not always trivial
  • A package manager offers a solution to those problems
  • Usually there is a database with libraries
  • Adding a library will result in a check for the dependencies and installation of the required libraries

NuGet

  • NuGet is an open-source package manager for the Visual Studio
  • It is so popular, that it has been integrated into the Visual Studio 2012
  • Every external library is now on NuGet
  • Easy to publish on the public NuGet feed or create own private feeds
  • Big advantage: Project bound and easy updating
  • Another advantage: Powershell integrated

NuGet flow

Overall project structure

  • Add external resources to your project(s)
  • Use NuGet for external libraries
  • Create own libraries if you want to re-use (non-UI) functionality
  • Use resource files for data, like images, sounds, texts, ...
  • Big advantage: They can be localized (German, English, ...)
  • Use DRY: Don't Repeat Yourself

All available presentations

More questions? Just mail!

MVP

Florian Rappl, MVP Visual C#