简体   繁体   English

如何在每个项目文件夹中保存dcu文件(例如:。\ $(平台)\ $(配置)\ $(ProjectFilename)?

[英]How to keep dcu files in per project folder (e.g.: .\$(Platform)\$(Config)\$(ProjectFilename)?

I have lot of Delphi projects in a project group. 我在一个项目组中有很多Delphi项目。 I can set Unit output directory to .\\$(Platform)\\$(Config) and all dcu files will keep in the directory according to platform and config value. 我可以将Unit output directory设置为.\\$(Platform)\\$(Config) ,所有dcu文件将根据platformconfig值保存在目录中。

In my build environment, I would like to set the Unit output directory to something like .\\$(Platform)\\$(Config)\\$(ProjectFilename) so all DCU files shall keep in it's own directory identified by current project file. 在我的构建环境中,我想将Unit output directory设置为.\\$(Platform)\\$(Config)\\$(ProjectFilename)这样所有DCU文件都应保存在当前项目文件标识的自己的目录中。

The Build Events in Project | Options Project | Options的构建事件Project | Options Project | Options has $(ProjectFilename) macro but I can't use it in Unit output directory . Project | Options$(ProjectFilename)宏但我无法在Unit output directory使用它。

I want to set .\\$(Platform)\\$(Config)\\$(ProjectFilename) to all projects' Unit output directory and it will keep all DCU files in unique project directory. 我想将.\\$(Platform)\\$(Config)\\$(ProjectFilename)为所有项目的Unit output directory ,它将所有DCU文件保存在唯一的项目目录中。

I found this answer coincidentally. 巧合的是我找到了这个答案。 I pick one project and (ms)build with verbosity of diagnostic . 我选择了一个项目和(ms)构建,具有详细的diagnostic By studying the output of msbuild , I simply pick a variable: MSBuildProjectName and specify in my optset file shared by 300 projects: 通过研究msbuild的输出,我只需选择一个变量: MSBuildProjectName并在我的optset文件中指定300个项目共享:

<DCC_DcuOutput>.\$(Platform)\$(Config)\$(MSBuildProjectName)</DCC_DcuOutput>

And I try build all projects in IDE. 我尝试在IDE中构建所有项目。 Amazingly, Delphi create folders for each project built and keep the DCU files in the folders respectively. 令人惊讶的是, Delphi为每个构建的项目创建文件夹,并将DCU文件分别保存在文件夹中。

The Build Events pre-processors supports a range of macros, some of which are equivalent to some environment variables. Build Events预处理器支持一系列宏,其中一些宏等同于某些环境变量。

The DCU Output folder setting supports only environment variables and not these macros. DCU输出文件夹设置仅支持环境变量 ,而不支持这些宏。

Possible Alternative Approach 可能的替代方法

To get a per-project DCU folder you can take a different approach, making dcu a subfolder of the current project, eg: 要获得每个项目的 DCU文件夹,您可以采用不同的方法,使dcu成为当前项目的子文件夹,例如:

Unit Output Directory: .\dcu

(or perhaps just "dcu", but I prefer to include the ".\\" if only to make it clear that the relative setting is intentional) (或者也许只是“dcu”,但我更喜欢包含“。\\”,如果只是为了明确相关设置是有意的)

This achieves the objective of keeping the DCU's for each project separate from each other, but means you no longer have all DCU's in a separate location outside of the project folder. 这实现了保持每个项目的DCU彼此分离的目的,但意味着您不再将所有DCU放在项目文件夹之外的单独位置。

You can of course still use the $(platform) and $(config) variables in this relative path, if this is important to you: 你当然可以在这个相对路径中使用$(platform)和$(config)变量,如果这对你很重要:

Unit Output Directory: .\dcu\$(platform)\$(config)

Whether this is an acceptable compromise only you can say in your situation. 这是否是一个可接受的妥协,只有你可以说你的情况。

Often the intention of keeping DCU's in a location other than the project folder is to: 通常,将DCU保留在项目文件夹以外的位置的目的是:

  • keep the project folder "clean" 保持项目文件夹“干净”

  • avoid having to maintain a long list of "ignore" entries for each dcu file in VCS (SubVersion/Git etc) 避免在VCS(SubVersion / Git等)中为每个dcu文件维护一长串“忽略”条目

Keeping DCU's in a project subfolder achieves the first of these, and the second issue is much simplified by being able to add just the DCU subfolder to the VCS ignore list, to ignore any file in that DCU folder. 将DCU保存在项目子文件夹中实现了第一个,第二个问题通过能够仅将DCU子文件夹添加到VCS忽略列表而大大简化,以忽略该DCU文件夹中的任何文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM