I try to find the best way to load addins and tasks in case of breaking changes.
Background
I have created an addin and several tasks based on Cake 0.25.0. The addin as well as the tasks are packaged within a NuGet package. Now I would like to update the used Cake version to 0.32.1 but that is not so easy as I try to explain below.
These NuGet packages that I created are used in multiple repositories and I provide from time to time hotfixes. To be able to automatically load the latest version of the addin/tasks there is no version defined in the pre-processor directive. Means like this:
#load nuget:My.Tasks
#addin nuget:My.AddIn
My Dilemma
I need to make sure that older releases can still use the preprocessor directives as mentioned above. Now I am searching for an approach to achieve this target. I thought renaming the original package id's would help and everyone who would like to use the upgraded version of my packages have to change the preprocessor directive in their build.cake.
But I am quite sure there must be a smarter way and I hope you can help me.
Next idea I had is to use #define preprocessor directives. So I created a new NuGet package containing only one Cake script named bootstrapper.cake as follows:
#if (V20)
#load nuget:My.Tasks
#addin nuget:My.AddIn
#else
#load nuget:My.Tasks&version=1.0.55
#addin nuget:My.AddIn&version=1.0.55
#end
This does not work as expected. Unfortunately both versions of the respective packages are loaded into the addins respectively tools directory and I am getting errors like "error CS0111: Type 'Submission#0' already defines a member called" and others.
Is there a way to achieve my goal? The idea to use #define was quite nice from my perspective. Maybe it is somehow possible or does anyone know a better way?
Personally I think the best would be, if Cakebuild would support wildcards in the preprocessor directives like
#load nuget:My.Tasks&version=1.0.*
Best Regards
Mr. T
Ifdef won't currently work with preprocessor directives, as they're handled by the C# compiler after preprocessor directives have been executed.
What you can do is to use an environment variable, preprocessor directives support environment variables substitution.
As an example:
Setting variable
RECIPE_VERSION="&version=0.3.0-unstable0400"
Could be used like this
#load nuget:?package=Cake.Receipe%RECIPE_VERSION%
Without the environment variable set, it'll omit the version.