Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Use Nuget Packages in Cake Build Tool

build.cake:

var target = Argument("target", "Default");

Task("Default")
  .Does(() => {
     var client = new RestSharp.RestClient("www.test.com");
    Information("Hello World!");
});

RunTarget(target);

packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="Cake" version="0.21.1" />
    <package id="RestSharp" version="105.2.3" />
</packages>

Error Received:

error CS0246: The type or namespace name 'RestSharp' could not be fou nd (are you missing a using directive or an assembly reference?)

like image 739
Chazt3n Avatar asked Mar 09 '23 14:03

Chazt3n


1 Answers

Use the #addin preprocessor directive to load assemblies from nuget, it'll fetch the package and reference the assemblies within it.

#addin nuget:?package=Cake.Foo
#addin nuget:?package=Cake.Foo&version=1.2.3
#addin nuget:?package=Cake.Foo&prerelease
#addin nuget:https://myget.org/f/Cake/?package=Cake.Foo&prerelease

You read more about the preprocessor directives at cakebuild.net.

Your example script would look something like this:

#addin nuget:?package=RestSharp&version=105.2.3

var target = Argument("target", "Default");

Task("Default")
  .Does(() => {
     var client = new RestSharp.RestClient("http://www.test.com");
    Information("Hello World!");
});

RunTarget(target);
like image 163
devlead Avatar answered Mar 16 '23 07:03

devlead