问题
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.
回答1:
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).
来源:https://stackoverflow.com/questions/8415549/how-to-make-package-dependencies-requirements-dependent-on-conditional-symbols