简体   繁体   中英

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?)

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM