Cake – Data at the root level is invalid

Couple of weeks ago I mentioned that in my current project we use Cake as a build mechanism. Recently we wanted to add simple functionality to our build script, which would allow us to modify one of the App.config‘s properties. According to the documentation it should be a straightforward tasks, as all the heavy lifting can be done via XmlPeek and XmlPoke aliases.
Our initial script looked as follows

And what was surprising for us, it didn’t work.
dataattherootlevel
We got a bit weird error “Data at the root level is invalid. Line 1, position 1”. The exception suggested that there was something wrong with our App.config file. However if you look at the picture presented above, you will see that we were able to successfully read the file and retrieve value of Version with XmlPeek method. After a bit of digging it turned out that XmlPoke and XmlPokeString are not able to work with relative paths and we have to use absolute one in order to make it work. Fortunately there is an easy way to do that, namely MakeAbsolute method. Out script after modifications looks that way

And now everything works fine
after

Source code for this post can be found here

Cake – Data at the root level is invalid