Skip to content
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

Closed
skovsende opened this issue Apr 16, 2018 · 8 comments
Closed

Be able to override tools version #214

skovsende opened this issue Apr 16, 2018 · 8 comments
Labels
Milestone

Comments

@skovsende
Copy link
Member

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:

#load "nuget:https://www.myget.org/F/cake-contrib/api/v2?package=Cake.Recipe&prerelease"
GitVersionTool = "#tool nuget:?package=GitVersion.CommandLine&version=4.0.0-beta0012";
@devlead
Copy link
Member

devlead commented Apr 16, 2018

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.

@skovsende
Copy link
Member Author

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?

@skovsende skovsende changed the title Be able to override addin version Be able to override tools version Apr 17, 2018
@devlead
Copy link
Member

devlead commented Apr 17, 2018

Yes, seems it's not fully documented yet, but been possible for a few versions, example here:
https://github.com/cake-build/cake/blob/develop/tests/integration/Cake.Core/Scripting/DefineDirective.cake

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.

@AdmiringWorm
Copy link
Member

@devlead just curious, is it also possible to define a directive with a value?
Say for instead something like this:

#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.

@gep13
Copy link
Member

gep13 commented Jul 2, 2018

@AdmiringWorm not sure exactly what you are looking for, but would this help?

cake-build/cake#2023

@AdmiringWorm
Copy link
Member

AdmiringWorm commented Jul 3, 2018

@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.
Where you can define a value using a preprocessor directive once, and wherever you use the name of that directive in the code will be replaced with the actual value instead.

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

@skemprunner
Copy link

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)

@gep13 gep13 added this to the 2.0.0 milestone Sep 9, 2019
gep13 added a commit that referenced this issue Sep 20, 2019
gep13 added a commit that referenced this issue Sep 20, 2019
To prevent the need to update all existing recipe.cake files with new
method call.
@gep13
Copy link
Member

gep13 commented Sep 20, 2019

@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:

ToolSettings.SetToolPreprocessorDirectives(gitVersionTool: "#tool nuget:?package=GitVersion.CommandLine&version=5.0.2-beta1.59&prerelease");

To override the preprocessor directive that is used to install the tool being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants