msbuild - 从命令行编译时添加附加库并包含路径

标签 msbuild c++builder

我正在尝试添加我的项目组在编译期间使用的其他路径。由于C++ Builder 2010使用msbuild,我尝试查看相关文档,根据我能找到的AdditionalLibPaths应该可以作为属性传递。即

msbuild /p:AdditionalLibPaths=C:\FooBar\Libs /t:build foo.groupproj

但它似乎没有使用我添加的路径。我之前注意到,当传递给 msbuild 时,VC++C++ Builder 之间的某些属性名称有所不同,并且想知道C++ Builder 是否> 可能会使用其他一些属性名称来添加额外的库和包含文件夹?

我不想替换项目中定义的现有路径,而是附加其他路径。这样做的理由是,当项目在我们的构建服务器上构建时,某些库驻留在标准化位置,该位置可能与其在开发计算机上的安装位置不同。

msbuild 实际上调用一个 msbuild 脚本文件,该文件又调用其他脚本,包括使用 .groupproj 脚本> 标签。我知道使用 标记时会创建 msbuild 的新实例,因此我知道在脚本中运行该任务时必须添加该属性。

<MSBuild Targets="Build" Projects="..\Foo.groupproj" Properties="Config=Debug (property to add additional paths here!)" />

更新:

C++ Builder 似乎正在使用 IncludePathILINK_LibraryPath,但设置这些会覆盖项目文件中已定义的路径。由于此文件是由 IDE 创建和维护的,因此对其进行追加而不是覆盖的任何更改都将被 IDE 覆盖。这有点奇怪,因为它看起来确实应该附加值

<IncludePath>..\FooBar\;$(BDS)\include;$(BDS)\include\dinkumware;$(BDS)\include\vcl;Common Components;..\Config\Config32;$(IncludePath)</IncludePath>

更新2:

CodeGear.Cpp.Targets中,我将自己的属性(名为AdditionalIncludePaths)添加到PropertyGroup中,并摆弄包括路径。

第 251 行左右

<PropertyGroup>
        <BCC_NoLink>true</BCC_NoLink>
        <ILINK_OSVersion Condition="'$(ILINK_OSVersion)'=='' And '$(NoVCL)'!='true'">5.0</ILINK_OSVersion>
        <DCC_GenerateCppFiles>true</DCC_GenerateCppFiles>
        <ShowStdOut Condition="'$(ShowStdOut)'==''">$(ShowGeneralMessages)</ShowStdOut>

        <!-- _TCHAR mapping for Uni^H^H^H character selection -->
        <StartupObj Condition="'$(_TCHARMapping)'=='wchar_t'">$(StartupObj)w</StartupObj>
        <ILINK_StartupObjs Condition="'$(ILINK_StartupObjs)'==''">$(StartupObj)</ILINK_StartupObjs>
        <BCC_GenerateUnicode Condition="'$(_TCHARMapping)'=='wchar_t'">true</BCC_GenerateUnicode>
        <!-- Include Paths -->
        <Win32LibraryPath Condition="'$(Win32LibraryPath)'==''">$(BDS)\lib</Win32LibraryPath>
        <IncludePath Condition="'$(CBuilderIncludePath)'!=''">$(IncludePath);$(CBuilderIncludePath)</IncludePath>
                <IncludePath Condition="'$(AdditionalIncludePath)'!=''">$(IncludePath);$(AdditionalIncludePath)</IncludePath>
        <BCC_IncludePath Condition="'$(BCC_IncludePath)'!=''">$(BCC_IncludePath);$(IncludePath)</BCC_IncludePath>
        <BCC_IncludePath Condition="'$(BCC_IncludePath)'==''">$(IncludePath)</BCC_IncludePath>
        <BRCC_IncludePath Condition="'$(BRCC_IncludePath)'!=''">$(BRCC_IncludePath);$(IncludePath)</BRCC_IncludePath>
        <BRCC_IncludePath Condition="'$(BRCC_IncludePath)'==''">$(IncludePath)</BRCC_IncludePath>
        <DCC_IncludePath Condition="'$(DCC_IncludePath)'!=''">$(DCC_IncludePath);$(IncludePath)</DCC_IncludePath>
        <DCC_IncludePath Condition="'$(DCC_IncludePath)'==''">$(IncludePath)</DCC_IncludePath>
        <DCC_UnitSearchPath>$(DCC_IncludePath);$(Win32LibraryPath)</DCC_UnitSearchPath>
        <DCC_ResourcePath>$(DCC_IncludePath)</DCC_ResourcePath>
        <DCC_ObjPath>$(DCC_IncludePath)</DCC_ObjPath>
        <TASM_IncludePath Condition="'$(TASM_IncludePath)'!=''">$(TASM_IncludePath);$(IncludePath)</TASM_IncludePath>
        <TASM_IncludePath Condition="'$(TASM_IncludePath)'==''">$(IncludePath)</TASM_IncludePath>

然后我可以打电话

msbuild /t:build /p:AdditionalIncludePaths=C:\Foo\Include foo.groupproj

这工作正常并且达到了我想要的效果。我只需要对库路径做同样的事情。但我不想像这样破解 Embarcaderos 提供的文件之一。这太荒谬了:P...没有任何官方属性可以设置用于添加包含路径和库路径吗?

最佳答案

对于VS2013,只需在运行msbuild之前定义环境变量即可:

set "INCLUDE=%additional_include_path%;%INCLUDE%"
set "LIB=%additional_lib_path%;%LIB%"
REM use environment variables for INCLUDE and LIB values
set UseEnv=true

引用:MSBuild/Microsoft.Cpp/v4.0/V120/Microsoft.Cpp.targets

<Target Name="SetBuildDefaultEnvironmentVariables"
        Condition="'$(UseEnv)' != 'true'">
...
    <SetEnv Name   ="INCLUDE"
        Value  ="$(IncludePath)"
        Prefix ="false" >
       <Output TaskParameter="OutputEnvironmentVariable"             PropertyName="INCLUDE"/>
    </SetEnv>

但看起来 INCLUDE 和 LIB 附加在项目属性中指定的其他 include/lib 目录后面。

关于msbuild - 从命令行编译时添加附加库并包含路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15654002/

相关文章:

visual-studio - ##[警告]未找到 Visual Studio 版本 '14.0'。回退到版本 '15.0'

.net - 如何在 Jenkins 上为 .net 项目设置构建/部署

C++ 生成器 2010

delphi - TStringGrid 输入验证仅允许 C++ Builder XE8 上的数字、小数和逗号

c - 如何用(可读的)UTF8 字符写入文件?

visual-studio - 在错误窗口中隐藏缺少的引用错误

c# - 需要在命令行上 msbuild 低版本的 C# 项目,没有 Visual Studio

PowerShell 退出代码 - 从 MSBuild 调用

delphi - 如何合并使用单独图像列表的 TMainMenu 并保留每个菜单项的正确图像?

C++ strtok 无法获得 2 个 token Borland