如何使包依赖项/要求依赖于条件符号?
我有一个包Package1
,它依赖于包PackDependency
。 Package1
的 .dpk 包含以下内容:
requires
vcl,
rtl,
PackDependency,
dbrtl;
现在,仅当定义了条件符号 CONDITION
时,我才希望拥有此依赖项。因此,我手动将 .dpk 文件更改为:
requires
vcl,
rtl,
{$IFDEF CONDITION}
PackDependency,
{$ENDIF}
dbrtl;
但这足够了吗?我担心 .dproj 文件。
我有两个像 Package1
这样的包,我想用它来执行上述操作。其中一个包的 .dproj 文件中包含以下行:
<DCCReference Include="PackDependency.dcp"/>
其他包的 .dproj 确实不包含此行,即使该包是还依赖于 PackDependency
。
这提出了一些问题:
- 是否可以
require
基于条件符号的包? - 如果是,我是否需要对 .dproj 文件执行某些操作?如果是的话,如果 Delphi 修改了文件的某些区域,我会遇到麻烦吗?
- 为什么上面的
行包含在一个 .dproj 文件中,但不包含在另一个 .dproj 文件中(即使两个包在其 .dpk 中都有依赖项,并且也显示在德尔福项目经理)? - 我怀疑从 Delphi 构建和使用 msbuild 从命令行构建时的行为不同。前者可能会查看 .dpk 文件 - 但后者会吗?
我的最终目标是使用 msbuild 从命令行进行构建。因此,命令行和 IDE 之间的不同行为对我来说也是重要的信息。
I have a package Package1
which depends on package PackDependency
. The .dpk of Package1
contains this:
requires
vcl,
rtl,
PackDependency,
dbrtl;
Now I want to have this dependeny only if a conditional symbol CONDITION
is defined. Thus I change the .dpk file manually to:
requires
vcl,
rtl,
{$IFDEF CONDITION}
PackDependency,
{$ENDIF}
dbrtl;
But is this enough? I am worried about the .dproj files.
I have two packages like Package1
I want to do the above with. One of them has the following line in its .dproj file:
<DCCReference Include="PackDependency.dcp"/>
The other packages' .dproj does not contain this line even though the package is also dependent on PackDependency
.
This raises some questions:
- Is it possible to
require
a package based on a conditional symbol? - If yes, do I have to do something to the .dproj file? And if yes, can I get in trouble if certain areas of the file are modified by Delphi?
- Why is the
<DCCReference Include...>
line above included in one of the .dproj files but not in the other (even though both packages have the dependency in their .dpk and also shown in the Delphi Project Manager)? - I suspect different behavior when building from Delphi and from command line using msbuild. The former might look into the .dpk file - but does the latter?
My ultimate goal is building from command line using msbuild. So different behavior between command line and IDE is also important information for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您在问题中所解释的那样,这将正常工作,直到您向包中添加新单元为止!此时,您的条件定义将被 IDE 自动删除,您必须再次将它们放入(这很烦人)。
我不知道有什么优雅的方法可以避免这种情况!
不必太担心 DPROJ 文件...因为这些文件应该由 IDE 维护,因此删除 DPK 源中的依赖项应该(在编译时)删除 DPROJ 中的任何相应节点(其中在DPK 应在编译时将相应的节点注入到 DPROJ 中)。
This will work fine as you have explained in the question, until you add a new unit to the package! At that point, your conditional defines will be automatically erased by the IDE, and you'll have to put them in again (which is annoying).
I know of no elegant way to avoid this!
Don't worry about the DPROJ files so much... as these are supposed to be maintained by the IDE, so removing a dependency in the DPK source should (upon compile) remove any corresponding nodes in the DPROJ (where adding dependencies in the DPK should, upon compile, inject the corresponding nodes into the DPROJ).