问题描述
我有进口的另一个项目MSBuild项目。有一个持有物业的进口项目,是相对于进口项目位置的相对路径。我如何把这个相对路径是绝对的?我已经尝试了ConvertToAbsolutePath的任务,但是这使得它相对于进口项目的位置)
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).
我想了罗伯特Koritnik的MSBuild任务的NUnit的输出集成到Visual Studio(见的其他SO问题的链接)。因为我想有我的所有版本控制下的工具,我想在它的自定义任务指向使用相对路径NUnit的控制台应用程序的目标文件。
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.
例如(在... MyRepository\Third Party\NUnit\MSBuild.NUnit.Task.Source\bin\Release\MSBuild.NUnit.Task.Targets):
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>
...
以上目标失败,该文件无法找到错误(即的nunit-console.exe文件)。里面的NUnitIntegrated MSBuild任务,当在execute()方法被调用时,当前目录是在导入项目的目录,所以相对路径将指向错误的位置。
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.
我试图通过将这些任务的IntegratedTest目标,以绝对的相对路径转换:
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.
我知道我可以使用属性 $(MSBuildProjectDirectory)
来获得的导入的目录的项目,但找不到在导入目标文件的目录中的任何等价物。
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?
谢谢!
推荐答案
您必须确定您与 MSBuildProjectDirectory
导入项目:
<PropertyGroup>
<RelativePathToProject>subdir\</RelativePathToProject>
</PropertyGroup>
<Import Project="$(RelativePathToProject)SubSample.proj"/>
<Target Name="GetNUnitConsolePath">
<Message Text="NUnitConsoleToolPath : %(NUnitConsoleToolPath.FullPath)"/>
</Target>
进口项目文件:
<ItemGroup>
<NUnitConsoleToolPath
Include="$(MSBuildProjectDirectory)\$(RelativePathToProject)..\..\..\NUnit 2.5.5\bin\net-2.0"/>
</ItemGroup>
这篇关于的MSBuild:进口项目转换为绝对路径相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!