-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Be able to override tools version #214
Comments
This would only work for tools and not addins, but looks like it's tools you want to change, so probably just an typo. Another way could be to have compiler directives in cake recipe. #if (!CustomGitVersionTool)
private const string GitVersionTool = "#tool nuget:?package=GitVersion.CommandLine&version=3.6.2";
#endif Then you could just #define CustomGitVersionTool
private const string GitVersionTool = "#tool nuget:?package=GitVersion.CommandLine&version=3.6.2"; In your script and it's still const an semantics kept the same. |
Yes, indeed I mean tools :) The #define solution is a little more noisy, but I think it's a fine solution to be able to keep it as consts. Can you do compiler directives in cake today? |
Yes, seems it's not fully documented yet, but been possible for a few versions, example here: Would also be nice if Cake.Recipe defined a few defines so one could know in a script if running in Recipe or not. Advantage with constants is that it's easier to debug as they're immutable during whole script execution, and give good compile time checks. One could of course make them get\set, but in that case preferably via the ToolSettings.SetToolSettings method only. |
@devlead just curious, is it also possible to define a directive with a value? #define GitVersionToolVersion "3.6.2"
private const string GitVersionTool = "#tool nuget:?package=GitVersion.Commandline&version=" + GitVersionToolVersion; or even #define GitVersionToolVersion "3.6.2"
#define GitVersionSource ""
private const string GitVersionTool = "#tool nuget:" + GitVersionSource + "?package=GitVersion.Commandline&version=" + GitVersionToolVersion; I know this isn't supported in C# itself, and probably would require some custom logic. |
@AdmiringWorm not sure exactly what you are looking for, but would this help? |
@gep13 while that could most likely be used, it's not exactly what I mean. Think preprocessor defines like those available in the C and C++ languages. for instance (with C#, of course it doesn't work): Before preprocessor #define MyValue "Hey"
#define MyValue2 " Mate"
static void Main()
{
System.Console.WriteLine(MyValue + MyValue2);
} After processing static void Main()
{
System.Console.WriteLine("Hey" + " Mate");
} |
cake-build/cake#2023 has been resolved, which means there is the option is using an environment variable in tools.cake: private const string GitVersionTool = "#tool nuget:?package=GitVersion.CommandLine&version=%GitVersion.CommandLine.Version%"; In toolsettings.cake have an extra optional parameter passed into SetToolSettings like gitVersionToolVersion and then call System.Environment.SetEnvironmentVariable("GitVersion.CommandLine.Version", gitVersionToolVersion ?? "3.6.5"); GitVersion should be the only option worth configuring, since there is are differences between v3 and v4 (current) |
To prevent the need to update all existing recipe.cake files with new method call.
@skovsende this should now be available in the latest version of Cake.Recipe from the MyGet feed. In your setup/recipe.cake file, you can now do somethign like the following:
To override the preprocessor directive that is used to install the tool being used. |
I have a need to override the version of GitVersion defined in tools.cake. Right now the variable GitVersionTool is defined as a const, so I can't change it. A simple solution would be to make the variable non-const so I could start my setup.cake with:
The text was updated successfully, but these errors were encountered: