Cake: How to turn relative Directory into an absolute path?

Created on 26 May 2015  路  5Comments  路  Source: cake-build/cake

I'm trying to set the OutDir property on the MSBuild task for my solution so that every project is built to a single directory (currently migrating from UpperCut that does this).

However I can't work out how to turn the relative path when creating a Directory object into an absolute path. Am I missing something obvious? There seems to be a MakeAbsolute method on DirectoryPath but that requires an ICakeEnvironment that I can't work out how to get either.

var buildResultDir = Directory("./build-output") + Directory("v" + semVersion) + Directory("bin";

MSBuild("./src/app.sln", settings =>
        settings.SetConfiguration(configuration)
            .WithProperty("OutDir", buildResultDir.Path)
            .UseToolVersion(MSBuildToolVersion.Default)
            .SetNodeReuse(false));

Most helpful comment

Hi @coxp ,

Version 0.4.2 is now released, in the DSL you can now write:

var file = MakeAbsolute(File("./path")) 
var dir = MakeAbsolute(Directory("./path")) 

Thanks for your feedback and interest in Cake :+1:

All 5 comments

There may be a more concise way, but this seems to work:

var buildResultDirRelative = Directory("./build-output") + Directory("v" + semVersion) + Directory("bin");
var buildResultDir = System.IO.Path.GetFullPath(buildResultDirRelative.ToString());

Hello,

You can get the current ICakeEnvironment instance via the script context.

Like this:

path = path.MakeAbsolute(Context.Environment)

There is a PR waiting that adds an alias method (MakeAbsolute) for this, but it won't be available until the next release.

Best regards
Patrik

Hi @coxp ,

Version 0.4.2 is now released, in the DSL you can now write:

var file = MakeAbsolute(File("./path")) 
var dir = MakeAbsolute(Directory("./path")) 

Thanks for your feedback and interest in Cake :+1:

Works great. Thanks :+1:

Excellent:+1:

Was this page helpful?
0 / 5 - 0 ratings