【问题标题】:Build target tools path构建目标工具路径
【发布时间】:2016-04-16 23:52:50
【问题描述】:

我目前正在为我的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

【问题讨论】:

    标签: msbuild nuget msbuild-target


    【解决方案1】:

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

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

    【讨论】:

    • 相对路径很好,但我需要一个到我的 nuget 包目录的相对路径。
    • @Toxantron 对,但 msbuild 中没有“我的 nuget 包目录”的概念。但是,当前文件的位置有一些东西,它位于您的 nuget 包目录中。如果你的 proj 文件在包的“build”目录中,那么 nuget 包的目录是“$(MSBuildThisFileDirectory)..”,你可以从那里找到任何东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多