为不同的Delphi IDE创建Delphi包的最佳实践

时间:2014-05-23 13:28:58

标签: delphi project-files

我维持an opensource Delphi Library。我想为所有Delphi XE系列编译器提供一个最小的项目文件。 理想情况下有这样一个工具,所以我只需要为XE6创建一个项目文件,它将自动删除所有冗余信息并为XE-XE5创建相应的项目文件。有没有任何聪明的方法归档那个?

这是我当前的项目文件,其中包含许多冗余信息。例如,它包含Android / iOS等的虚拟配置,但我的项目是传统Windows应用程序的目标。如果我手动删除这些信息,它将在项目更改时返回。我也知道,DebugInformation的值在XE4中是布尔值,而在XE5中是整数。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectGuid>{1118D87C-9E72-4D93-9098-E70AD237493A}</ProjectGuid>
        <MainSource>dutil_rtl.dpk</MainSource>
        <ProjectVersion>15.1</ProjectVersion>
        <FrameworkType>None</FrameworkType>
        <Base>True</Base>
        <Config Condition="'$(Config)'==''">Release</Config>
        <Platform Condition="'$(Platform)'==''">Win32</Platform>
        <TargetedPlatforms>3</TargetedPlatforms>
        <AppType>Package</AppType>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
        <Base_Win32>true</Base_Win32>
        <CfgParent>Base</CfgParent>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
        <Base_Win64>true</Base_Win64>
        <CfgParent>Base</CfgParent>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''">
        <Cfg_1>true</Cfg_1>
        <CfgParent>Base</CfgParent>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win32)'!=''">
        <Cfg_1_Win32>true</Cfg_1_Win32>
        <CfgParent>Cfg_1</CfgParent>
        <Cfg_1>true</Cfg_1>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win64)'!=''">
        <Cfg_1_Win64>true</Cfg_1_Win64>
        <CfgParent>Cfg_1</CfgParent>
        <Cfg_1>true</Cfg_1>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
        <Cfg_2>true</Cfg_2>
        <CfgParent>Base</CfgParent>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
        <Cfg_2_Win32>true</Cfg_2_Win32>
        <CfgParent>Cfg_2</CfgParent>
        <Cfg_2>true</Cfg_2>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win64)'!=''">
        <Cfg_2_Win64>true</Cfg_2_Win64>
        <CfgParent>Cfg_2</CfgParent>
        <Cfg_2>true</Cfg_2>
        <Base>true</Base>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Base)'!=''">
        <VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
        <VerInfo_Locale>1033</VerInfo_Locale>
        <DCC_DUPLICATE_CTOR_DTOR>false</DCC_DUPLICATE_CTOR_DTOR>
        <GenPackage>true</GenPackage>
        <GenDll>true</GenDll>
        <RuntimeOnlyPackage>true</RuntimeOnlyPackage>
        <DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
        <DCC_DcuOutput>..\lib\$(Platform)\$(Config)</DCC_DcuOutput>
        <DCC_ExeOutput>.\$(Platform)\$(Config)</DCC_ExeOutput>
        <DCC_E>false</DCC_E>
        <DCC_N>false</DCC_N>
        <DCC_S>false</DCC_S>
        <DCC_F>false</DCC_F>
        <DCC_K>false</DCC_K>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Base_Win32)'!=''">
        <DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Base_Win64)'!=''">
        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
        <DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Cfg_1)'!=''">
        <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
        <DCC_Optimize>false</DCC_Optimize>
        <DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
        <DCC_DebugInfoInExe>true</DCC_DebugInfoInExe>
        <DCC_RemoteDebug>true</DCC_RemoteDebug>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
        <DCC_RemoteDebug>false</DCC_RemoteDebug>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Cfg_2)'!=''">
        <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
        <DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
        <DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
        <DCC_DebugInformation>false</DCC_DebugInformation>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
    </PropertyGroup>
    <ItemGroup>
        <DelphiCompile Include="$(MainSource)">
            <MainSource>MainSource</MainSource>
        </DelphiCompile>
        <DCCReference Include="rtl.dcp"/>
        <DCCReference Include="..\src\dutil.core.Exception.pas"/>
        <DCCReference Include="..\src\dutil.core.NonRefCountedInterfacedObject.pas"/>
        <DCCReference Include="..\src\dutil.io.device.File_.pas"/>
        <DCCReference Include="..\src\dutil.io.device.TempFile.pas"/>
        <DCCReference Include="..\src\dutil.io.FileVersion.pas"/>
        <DCCReference Include="..\src\dutil.sys.win32.MessageWindowThread.pas"/>
        <DCCReference Include="..\src\dutil.sys.win32.Platform.pas"/>
        <DCCReference Include="..\src\dutil.sys.win32.Process.pas"/>
        <DCCReference Include="..\src\dutil.sys.win32.registry.Reader.pas"/>
        <DCCReference Include="..\src\dutil.sys.win32.registry.Validation.pas"/>
        <DCCReference Include="..\src\dutil.sys.win32.registry.Writer.pas"/>
        <DCCReference Include="..\src\dutil.sys.win32.SpecialPath.pas"/>
        <DCCReference Include="..\src\dutil.sys.win32.SubclassingWindow.pas"/>
        <DCCReference Include="..\src\dutil.text.arg.Arg.pas"/>
        <DCCReference Include="..\src\dutil.text.arg.Arguments.pas"/>
        <DCCReference Include="..\src\dutil.text.arg.Builder.pas"/>
        <DCCReference Include="..\src\dutil.text.Convert.pas"/>
        <DCCReference Include="..\src\dutil.text.json.Json.pas"/>
        <DCCReference Include="..\src\dutil.text.json.Reader.pas"/>
        <DCCReference Include="..\src\dutil.text.json.Validation.pas"/>
        <DCCReference Include="..\src\dutil.text.Util.pas"/>
        <DCCReference Include="..\src\dutil.text.xml.Validation.pas"/>
        <DCCReference Include="..\src\dutil.time.Time.pas"/>
        <DCCReference Include="..\src\dutil.util.concurrent.BlockingQueue.pas"/>
        <DCCReference Include="..\src\dutil.util.concurrent.FailSafeThread.pas"/>
        <DCCReference Include="..\src\dutil.util.concurrent.Result.pas"/>
        <DCCReference Include="..\src\dutil.util.concurrent.Timer.pas"/>
        <DCCReference Include="..\src\dutil.util.concurrent.TimerImpl.pas"/>
        <DCCReference Include="..\src\dutil.util.concurrent.TimerQueue.pas"/>
        <DCCReference Include="..\src\dutil.util.container.DynArray.pas"/>
        <DCCReference Include="..\src\dutil.util.digest.Crc32.pas"/>
        <BuildConfiguration Include="Release">
            <Key>Cfg_2</Key>
            <CfgParent>Base</CfgParent>
        </BuildConfiguration>
        <BuildConfiguration Include="Base">
            <Key>Base</Key>
        </BuildConfiguration>
        <BuildConfiguration Include="Debug">
            <Key>Cfg_1</Key>
            <CfgParent>Base</CfgParent>
        </BuildConfiguration>
    </ItemGroup>
    <ProjectExtensions>
        <Borland.Personality>Delphi.Personality.12</Borland.Personality>
        <Borland.ProjectType>Package</Borland.ProjectType>
        <BorlandProject>
            <Delphi.Personality>
                <VersionInfo>
                    <VersionInfo Name="IncludeVerInfo">True</VersionInfo>
                    <VersionInfo Name="AutoIncBuild">False</VersionInfo>
                    <VersionInfo Name="MajorVer">1</VersionInfo>
                    <VersionInfo Name="MinorVer">0</VersionInfo>
                    <VersionInfo Name="Release">0</VersionInfo>
                    <VersionInfo Name="Build">0</VersionInfo>
                    <VersionInfo Name="Debug">False</VersionInfo>
                    <VersionInfo Name="PreRelease">False</VersionInfo>
                    <VersionInfo Name="Special">False</VersionInfo>
                    <VersionInfo Name="Private">False</VersionInfo>
                    <VersionInfo Name="DLL">False</VersionInfo>
                    <VersionInfo Name="Locale">1033</VersionInfo>
                    <VersionInfo Name="CodePage">1252</VersionInfo>
                </VersionInfo>
                <VersionInfoKeys>
                    <VersionInfoKeys Name="CompanyName"/>
                    <VersionInfoKeys Name="FileDescription"/>
                    <VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
                    <VersionInfoKeys Name="InternalName"/>
                    <VersionInfoKeys Name="LegalCopyright"/>
                    <VersionInfoKeys Name="LegalTrademarks"/>
                    <VersionInfoKeys Name="OriginalFilename"/>
                    <VersionInfoKeys Name="ProductName"/>
                    <VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
                    <VersionInfoKeys Name="Comments"/>
                </VersionInfoKeys>
                <Source>
                    <Source Name="MainSource">dutil_rtl.dpk</Source>
                </Source>
                <Excluded_Packages>
                    <Excluded_Packages Name="$(BDSBIN)\dcloffice2k190.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
                    <Excluded_Packages Name="$(BDSBIN)\dclofficexp190.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
                </Excluded_Packages>
            </Delphi.Personality>
            <Deployment/>
            <Platforms>
                <Platform value="iOSDevice">False</Platform>
                <Platform value="iOSSimulator">False</Platform>
                <Platform value="Win32">True</Platform>
                <Platform value="Win64">True</Platform>
            </Platforms>
        </BorlandProject>
        <ProjectFileVersion>12</ProjectFileVersion>
    </ProjectExtensions>
    <Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
    <Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
</Project>

2 个答案:

答案 0 :(得分:6)

过去,当所有内容仅基于DPR / DPK文件时,单个项目文件可能有效,但是由于引入了DPROJ文件,因此单个项目将不再起作用。这是因为DPROJ文件包含IDE版本之间不同的版本信息,在某些情况下还包含节点结构。如果您在较新的IDE中打开DPROJ并且该文件包含较旧的版本/结构,则IDE将升级该项目。如果您随后将更改保存到同一文件中,则它将不再适用于较旧的IDE。

如果查看任何主要的第三方组件包,它们会为每个IDE版本维护不同的项目。你需要做同样的事情。

答案 1 :(得分:2)

大多数商业软件包(如DevExpress)和开源组件/软件包(如SynEdit和Jedi库)在每个版本的IDE上对相同的源代码使用单独的项目文件。 D7,D2010,DXE2 ......等。

这允许提供程序使用条件定义来处理IDE / Platform的不同版本,以便它们的代码适用于开发人员。

您可能需要这样做,以避免使用您的库的人员的复杂安装说明。

此外,这几乎是它的标准方式,使用你的库的人可能会寻找适当命名的项目文件。

希望这有帮助。