Short version:
I have an MSBuild project that imports another project. There is a property holding a relative path in the imported project that is relative to the location of the imported project. How do I convert this relative path to be absolute? I've tried the ConvertToAbsolutePath task, but this makes it relative to the importing project's location).
Long version:
I'm trying out Robert Koritnik's MSBuild task for integrating nunit output into Visual Studio (see this other SO question for a link). Since I like to have all my tools under version control, I want the target file with the custom task in it to point to the nunit console application using a relative path.
My problem is that this relative path ends up being made relative to the importing project.
E.g. (in ... MyRepository\Third Party\NUnit\MSBuild.NUnit.Task.Source\bin\Release\MSBuild.NUnit.Task.Targets):
...
<PropertyGroup Condition="'$(NUnitConsoleToolPath)' == ''">
<NUnitConsoleToolPath>..\..\..\NUnit 2.5.5\bin\net-2.0</>
</PropertyGroup>
...
<Target Name="IntegratedTest">
<NUnitIntegrated
TreatFailedTestsAsErrors="$(NUnitTreatFailedTestsAsErrors)"
AssemblyName="$(AssemblyName)"
OutputPath="$(OutputPath)"
ConsoleToolPath="$(NUnitConsoleToolPath)"
ConsoleTool="$(NUnitConsoleTool)"
/>
</Target>
...
The above target fails with the error that the file cannot be found (that is the nunit-console.exe file). Inside the NUnitIntegrated MSBuild task, when the the execute() method is called, the current directory is the directory of the importing project, so relative paths will point to the wrong location.
I tried to convert the relative path to absolute by adding these tasks to the IntegratedTest target:
<ConvertToAbsolutePath Paths="$(NUnitConsoleToolPath)">
<Output TaskParameter="AbsolutePaths" PropertyName="AbsoluteNUnitConsoleToolPath"/>
</ConvertToAbsolutePath>
but this just converted it to be relative to the directory of the project file that imports this target file.
I know I can use the property $(MSBuildProjectDirectory)
to get the directory of the importing project, but can't find any equivalent for directory of the imported target file.
Can anyone tell me how a path in an imported file that is supposed to be relative to the directory that the imported file is in can be made absolute?
Thanks!