Cake: using static Directive doesn't compile

Created on 2 Oct 2017  路  10Comments  路  Source: cake-build/cake

Currently a script with using static directive like below

using static System.Math;

Information(Round(1.1));

will fail with

- Error: Error occurred when compiling build script: error CS0246: 
- The type or namespace name 'static' could not be found (are you missing a using directive or an assembly reference?)
- (3,13): error CS0103: The name 'Round' does not exist in the current context

As we've unified around Roslyn this can now and should be supported by Cake, I'll submit a pull request shortly with a proposed fix.

Bug

All 10 comments

@devlead could you create another issue to track documentation for this?

@gep13 added cake-build/website#417

@devlead thank you, I think that this is a good habit to get into when adding new functionality. Even if it doesn't get done straight away, putting the issue up means that it hopefully won't get forgotten about.

I'm unable to build cake script with using static System.Math; using version 0.26.1. Still same "The type or namespace name 'static' could not be found"

@sm-g I have just tested this on my Mac, using Cake 0.26.1, and I can confirm that it is working as expected.

Can you confirm what Operating System you are using?

@gep13 windows 10 x64 home
Version 0.26.1+Branch.main.Sha.b26790017b2befa7b35799eb9a0c1cba322b0c90

@sm-g I have just tested on the same, and everything looks to be working fine.

Can I get you to test something for me? Can you use the following build.cake?

using static System.Math;

Task("Default")
    .Does(() =>
{
    Information(typeof(ICakeContext).Assembly.GetName().Version.ToString());
    Information(Round(1.1));
});
RunTarget("Default");

The output should be

Preparing to run build script...
Running build script...

========================================
Default
========================================
0.26.1.0
1

Task                          Duration
--------------------------------------------------
Default                       00:00:00.0184578
--------------------------------------------------

@gep13 I do not know what happened, now everything works...

@sm-g if I had to guess, I suspect you were running an older version of Cake. The only thing I added to the above was to output the currently executing Cake version number.

Was this page helpful?
0 / 5 - 0 ratings