Hi! One of the main selling points of cake is that you write c#. A natural question then (since c# api:s work well with intellisense) is how do you get intellisense support for cake files?
There's no out of the box intellisense for any environment yet, but I know that @RichiCoder1 is working on Omnisharp integration, so maybe there will be intellisense support in Atom and VS Code in the future.
Is there a way to write build.cake.cs files?
You are free to name the file whatever you want - build.cake is the de-facto standard.
@vktr problem then is that you have a file that you call .cs, without having a proper .cs file. My question is, if it's possible to write cake files using plain old c#?
You get syntax highlighting and variable completion in Sublime & Atom
@wallymathieu Cake scripts are a superset of C#, that's why we have our own extension.
So no then.
Not sure what you're asking to be honest.
The main reason why I thought cake would be exciting to use cake instead of rake, fake, grunt gulp or whatever else is that it would enable c# programmers to write build scripts using c# (and would get off my back for bringing in other languages). If I'm writing things in c# I want to have the tooling support. Ruby for instance is script first, so it's not annoying to write without tooling. I had hoped that it would be possible to use cake (since it looks like the more popular alternative for c#-build scripts) to write small build scripts that are possible for c#-mostly developers to consume.
So, it's possible my expectations are wrong since the goals of this project are to provide a DSL in c# syntax?
Ok, currently not possible, but we're not against intellisense, might come with Atom / Code when omnisharp supports loading cake assemblies.
@wallymathieu No it's not possible at the moment since Cake is a scripting tool it hasn't been the focus of our efforts. We're thinking about future tooling support but that's not our primary (or even secondary) goal at the moment, but more of a future "nice to have".
Thanks for the help!
I was playing around with the idea of having a base class for cake scripts (something like this).
with this I would just need to create a new class that implements the CakeFile class and I would get intellisense.
I was thinking of writing some code using roslyn that will convert this code to a real cake file.
for example - https://github.com/Meir017/Playground/blob/master/build.cake.cs
does this make any sense?
@Meir017 Great idea but something like that would be a massive breaking change and not really the way we want to go with Cake. It does look like what we've done in Cake.Frosting, so you could use your idea today if you wanted to 馃槃
here is a small POC I did - intellisense-generator which allowes me to use the cake syntax (except for the cake keywards addin, tool & load).
Converting the class to a real cake file was really easy using roslyn.
This is released now in beta channel, soon in stable. https://github.com/OmniSharp/omnisharp-vscode/issues/1684#event-1316871214
I really 鉂わ笍 what @Meir017 did in his https://github.com/Meir017/Playground repo!
@patriksvensson , actually I don't exactly understand when you say Cake is a superset of C#: it seems to me it is in fact an internal DSL; every commands is a legit C# method, with the single exception of the #tool directive.
Yet, the current Cake implementation requires those legit commands to be hosted outside an ordinary method's class, which fatally prevents the possibility to use most of the tooling support of Visual Studio.
@Meir017's repo allows to copy/paste a Cake script, more or less in its original format (with the exception of #tool), into an Execute() method; it would be perfect if only it allows to just run that Execute() method, instead of converting its body to a Cake script.
Cake.Frosting seems promising as well (just gave it a star!), but it's unfortunate that it uses a different DSL (methods attributes rather than the ordinary Cake's method Task, IsDependentOn and the like.
@patriksvensson, wouldn't be possible to put a class and a method around the cake script, so that it could be seen as legit C# code by Visual Studio?
@arialdomartini It's a super set of C#. We for example have cake-aliases which are not valid C# (but valid Cake script) and of course also the pre-processor directives you mention.
Cake got intellisense support in Visual Studio Code (see https://cakebuild.net/blog/2017/11/intellisense-vscode). We do not have any plans on supporting the scenario with wrapping the Cake script in a class and a method.
@arialdomartini a bit dated but below blog post explains some of the internals of Cake, it goes through some utilising Cake from "regular" .NET Code, but that's just PoC and as @patriksvensson not an intended / supported scenario.
https://hackernoon.com/dispelling-the-magic-6dc0fdfe476c
Cake utilises the C# scripting API which provides some deviations from "regular" C# i.e. global methods and removes the need for classes / namespaces. Beyond the global methods Cake DSL adds, we also add some extra preprocessor directives #tool is one, but we add a few others like i.e. #addin, and we also extend some available in Roslyn scripting with features like fetching scripts from NuGet and so on.
You can read about all preprocessor directives at
https://cakebuild.net/docs/fundamentals/preprocessor-directives
Concept of aliases (global methods and properties) is documented at
https://cakebuild.net/docs/fundamentals/aliases
Beyond Cake's own documentation and blog, there's a couple of videos/blogs/presentations listed at
https://cakebuild.net/docs/resources/
You might be interested in https://nuke.build it's similar to cake but it uses a simple c# project with less "magic"
I just got asked about Nuke in my repo that uses Cake (See https://github.com/Dotnet-Boxed/Templates/issues/360) and ended up here. To be honest I've been pretty happy with Cake so far.
It would be nice to get intellisense in Visual Studio as well as VS Code, so I don't have to switch IDE but that's not a big issue for me. One idea could be to allow the use of the .cs file extension and move any #tool like directives into C# comments but just a suggestion while I'm passing by.
Most helpful comment
This is released now in beta channel, soon in stable. https://github.com/OmniSharp/omnisharp-vscode/issues/1684#event-1316871214