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>
收到错误:
错误CS0246:类型或命名空间名称'RestSharp'不能为fou nd(您是否缺少using指令或程序集引用?)
答案 0 :(得分:6)
使用#addin
预处理程序指令从nuget加载程序集,它将获取程序包并引用其中的程序集。
#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
您在cakebuild.net了解有关预处理程序指令的更多信息。
您的示例脚本如下所示:
#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);