-
-
Notifications
You must be signed in to change notification settings - Fork 17
Using nuget packages
When setting up a project to use nuget there are several restrictions: it should work on both Windows and Linux, it should work from the command line so that CI builds will work, and it should also work when using an IDE.
Both MonoDevelop and VisualStudio in their latest versions have the ability to restore packages when loading or building a solution.
This document explains the necessary steps.
It might be convenient to just copy the build/NuGet.targets
file of Palaso. Put it next to your msbuild
project file (although this is not required) - in this document we assume those files to be in build/
.
Note that you shouldn't put
NuGet.targets
in a.nuget
subdirectory because this will cause Visual Studio to use the MSBuild-integrated approach which is no longer recommended.
The build/NuGet.targets
file contains a RestorePackages
target as well as some additional targets that
will be called automatically to download NuGet.exe
etc.
In your msbuild project file, include NuGet.targets
and add a property SolutionPath
that contains the full path and name of your
solution, e.g.
<Import Project="NuGet.targets"/>
<PropertyGroup>
<SolutionPath>$(RootDir)/$(Solution)</SolutionPath>
</PropertyGroup>
Make your Compile
target a dependency of RestorePackages
:
<Target Name="Compile" DependsOnTargets="RestorePackages">
</Target>
Use the built-in tools of Visual Studio and MonoDevelop to add or update nuget packages to your project.
You should check in the following files to source control:
$(SolutionDir)/.nuget/packages.config
build/NuGet.targets
and the packages.config
files inside of your project.
You don't want to check in NuGet.exe
(it'll get downloaded automatically at build time, having the advantage that you'll get the latest version), nor the packages
subdirectory (that contains the nuget packages that get downloaded; since these will be downloaded at build time it's no use to pollute VCS with binary packages). It might be best to exclude these files in the .gitignore
/.hgignore
file:
build/NuGet.exe
packages/
A unit test project that uses NUnit should use the NUnit
nuget package. This will add the necessary reference to nunit.framework.dll
.
The project should also include the NUnit.Runners.Net4
nuget package. This provides nunit-console
and thus makes it possible to run the unit tests without requiring a separately installed version of NUnit. This is helpful for automated builds.
NUnit can be run by using the following path:
packages/NUnit.Runners.Net4.2.6.4/tools/nunit-console.exe