Build/Test Issues

$(MSBuildThisFileDirectory) is not supported?

Started by Leonid on 14,446 views

We are using $(MSBuildThisFileDirectory) like in this example from MSDN:

http://msdn.microsoft.com/en-us/library/dd633440.aspx

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), EnlistmentInfo.props))\EnlistmentInfo.props" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), EnlistmentInfo.props))' != '' " />


It's used to walk up the directory tree to find the marker file, and allows you to keep your project files at an arbitrarily depth.

But NCrunch build will give an error such as:
The expression "[MSBuild]::GetDirectoryNameOfFileAbove('', EnlistmentInfo.props)" cannot be evaluated. The path is not of a legal form.

I changed $(MSBuildThisFileDirectory) to $(MSBuildProjectDirectory) and it worked (after I also added the actual file and the directory to AdditionalFilesToCopy).

This seems like a straightforward bug - maybe because this property is newish (it was not documented for VS2010).

Note MSBuildProjectDirectory will not work as a substitute to MSBuildThisFileDirectory in all cases, so my workaround is limited.

Hopefully future versions of NCrunch will support MSBuildThisFileDirectory.

Leonid
Hi Leonid -

Thanks for reporting this issue. NCrunch relies on MSBuild abstractions when attempting to work with expressions such as this one. I'm wondering if this may be a .NET 4.0/4.5 version related issue of some kind. I'll take a deeper look and will see if I can identify a fix for it.


Cheers,

Remco
We have recently bumped into this issue too when trying to enable NCrunch.
Are there any updates?

Thanks,
Yael
Hi Yael,

Unfortunately because of the location of the expression (Import condition), this eventually proved impossible to fix within NCrunch itself.

I recommend using an alternative way to derive the import target directory. Note that in most cases it is still possible to configure NCrunch to work with this scenario by including the file import file using the 'Additional files to include' configuration setting - see http://www.ncrunch.net/documentation/considerations-and-constraints_implicit-file-dependencies.

Post a reply

Log in to reply.