Package installation

Sruti edited this page Mar 6, 2015 · 11 revisions

scriptcs integrates tightly with NuGet packages. This page describes how to install and use NuGet packages with scriptcs.

Using scriptcs -install

You can install packages directly from the scriptcs CLI. This will pull the relevant packages from NuGet, and install them in the scriptcs_packages folder.

Once the packages are installed, you can simply start using them in your script code directly (just import the namespaces - no additional bootstraping or DLL referencing is needed).

The install command will also create a scriptcs_packages.config file if you don't have one - so that you can easily redistribute your script (without having to copy the package binaries).

  • scriptcs -install {package name} will install the desired package from NuGet.

    For example:

     scriptcs -install ServiceStack
  • scriptcs -install {package name} {version} will install a specific version of the package

  • if you want to install any prerelease packages, you have to include -pre switch

    For example:

     scriptcs -install ScriptCs.Metrics -pre
  • scriptcs -install (without package name) will look for the scriptcs_packages.config file located in the current execution directory, and install all the packages specified there. You only need to specify top level packages.

For example, you might create the following scriptcs_packages.config:

<?xml version="1.0" encoding="utf-8"?>
	<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
	<package id="Nancy.Bootstrappers.Autofac" version="0.16.1" targetFramework="net40" />
	<package id="Autofac" version="" targetFramework="net40" />

And then just call:

scriptcs -install

As a result, all packages specified in the scriptcs_packages.config, including all dependencies, will be downloaded and installed in the scriptcs_packages folder.

At this point, you might ask which package feeds will scriptcs -install use?

We rely on the regular NuGet.config convention. Here's the order of precedence when locating this file:

  1. Local NuGet.config in the script folder. This is especially useful if, for a given script app, you want to pull something from private feed or if you are testing local packages from your own hard disk.

  2. Main NuGet.config from %APPDATA%\NuGet\. If you use Visual Studio, this is the same file that VS Package Manager uses, so if you have pre-configured any feeds there, scriptcs will actually pick them up.

  3. If there is no NuGet.config at your machine (i.e. you've never used nuget.exe), we'll default to official Nuget package source

Because of that, scriptcs will also use your local NuGet cache.

Generating scriptcs_packages.config

Having scriptcs_packages.config makes redistributing your script easy, as you only have to copy CSX files and scriptcs_packages.config, without worrying about moving the DLLs too. You can generate a package.config file based on the contents of your scriptcs_packages folder by calling:

scriptcs -save

This is really handy when you installed packages using nuget.exe, or copied them from another project and have no scriptcs_packages.config for your script application.

Now when you move your script to a different machine/client you can just run install again - against the scriptcs_packages.config file.