构建目标工具路径

时间:2016-04-16 23:52:50

标签: msbuild nuget msbuild-target

我目前正在为我的code generator project打包一个nuget包,我已经将可执行文件包含在tools目录中,并将构建目标包含在该进程中。

部分来自nuspec

<files>
    <file src="cgbr.targets" target="build\cgbr.targets" />
    <file src="cgbr.json" target="content\cgbr.json" />
    <file src="..\bin\CGbR.Lib.dll" target="lib\CGbR.Lib.dll" />
    <file src="..\bin\cgbr.exe" target="tools\cgbr.exe" />
</files>

cgbr.targets文件的内容

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="BeforeBuild">
        <Exec Command="cgbr.exe $(ProjectDir)"/>
    </Target>
</Project>

现在,当我安装软件包时,我发现它已包含在构建过​​程中。不幸的是cgbr.exe的路径无效,我有点卡住了。当然我可以使用$(SolutionDir)packages\CGbR.0.3\tools\cgbr.exe,但每次更改版本时我都必须修改它。

澄清一下:我需要路径到我的包工具路径。

修改:找到related post

1 个答案:

答案 0 :(得分:2)

您可能希望从目标文件获得该工具的相对路径。有许多predefined properties in msbuild。对这些场景最有用的可能是MSBuildThisFileDirectory,它返回当前proj文件目录的完整路径。一个例子:

<Exec Command="&quot;$(MSBuildThisFileDirectory)..\tools\cgbr.exe&quot; &quot;$(ProjectDir)&quot;"/>