Currently there's no support for conditionals when it comes to script loading the 0.23.0 will add if def support but pre processor directives are processed as same level/priority so won't help for your specific problem.
What you could do though is create a small bootstrapper cake script that pulls in the pieces needed for your specific scenarios.
Example using CakeExecuteExpression
var visualStudioVersion = Argument("VisualStudioVersion", "2017");
var statements = new List<string>();
var currentDir = MakeAbsolute(Directory("./"));
statements.Add("#load \"{0}/common.cake\"");
switch(visualStudioVersion)
{
case "2013":
statements.Add("#load \"{0}/vs2013.cake\"");
break;
case "2017":
statements.Add("#load \"{0}/vs2017.cake\"");
break;
default:
throw new Exception(string.Format("Unknown VisualStudioVersion: {0}", visualStudioVersion));
}
var expression = string.Format(
string.Join(
"\r\n",
statements
),
currentDir
);
CakeExecuteExpression(
expression
);
For above if argument VisualStudioVersion is set to 2017 or no argument specified then it'll load
If argument VisualStudioVersion is set to 2013 then it'll load
Example using CakeExecuteScript
Perhaps less complex is to just provide to different entry points i.e. have a build.cake
file call either vs2013.cake
or vs2017.cake
depending on argument.
common.cake
Information("This will execute regardless version!") ;
vs2013.cake
#load "common.cake"
Information("Hello VS2013!");
vs2017.cake
#load "common.cake"
Information("Hello VS2017!");
build.cake
var visualStudioVersion = Argument("VisualStudioVersion", "2017");
switch(visualStudioVersion)
{
case "2013":
CakeExecuteScript("vs2013.cake");
break;
case "2017":
CakeExecuteScript("vs2017.cake");
break;
default:
throw new Exception(string.Format("Unknown VisualStudioVersion: {0}", visualStudioVersion));
}
2017 output
cake .\executescript.cake
Will output
This will execute regardless version!
Hello VS2017!
2013 output
cake .\executescript.cake --VisualStudioVersion=2013
will output
This will execute regardless version!
Hello VS2013!