代码之家  ›  专栏  ›  技术社区  ›  WileCau

如何将bdsproj批量转换为dproj?

  •  6
  • WileCau  · 技术社区  · 14 年前

    我们最近从Delphi2006升级到Delphi2007,项目文件从 .bdsproj .dproj .

    我的研究表明 .dproj公司 现有的项目需要在ide中打开。我们有400多个 .bdsproj项目 手动执行此操作的文件并不实际。

    我想出的方法是使用以下命令行打开所有项目:

    find . -name *.bdsproj -exec bds.exe -pDelphi -ns -m "{}" ";"
    

    这并不理想,因为它相当慢(等待BDS加载、等待编译发生、等待BDS关闭,…)。

    有没有一种有效的方法来转换 .bdsproj项目 .dproj公司 ?

    注意:上面命令行中的“find”是一个类UNIX的find(例如MKS或GNU),它搜索文件,而不是Windows find,它搜索文件中的文本。

    3 回复  |  直到 14 年前
        1
  •  3
  •   Toon Krijthe    14 年前

    您可以同时打开多个项目。甚至使用拖放。

    • 选择40个项目
    • 把它们拖到IDE
    • 单击“是”40次
    • 全部保存
    • 全部关闭
    • 重复直到完成。
        2
  •  3
  •   Community CDub    8 年前

    这里有一个更高级的版本 find 使用PowerShell的解决方案。它搜索 bdsproj 在指定目录下的文件,并生成 bdsgroup 包含所有项目。

    运行脚本后,打开 BDS组 使用D2007将项目转换为 dproj . D2007还产生 groupproj ,这似乎相当于D2007 BDS组 .

    提示:

    • 使用运行脚本 -help 查看说明。
    • 在打开之前启动D2007 BDS组 ,它似乎可以更快地处理项目。
    • 您不需要保存项目,打开它们就足以创建 dproj公司 .

    感谢:

    这是剧本。对我有用:o)

    Param(
        $path = ".",
        $exclude = "",
        [switch]$help
    )
    
    Set-PSDebug -Strict
    $ErrorActionPreference = 'Stop'
    
    # Ensure path is fully qualified and ends with a path delimiter
    $path = Join-Path (Resolve-Path $path) ""
    
    # Output file full name ($path\scriptname.bdsproj)
    $outfile = Join-Path $path ([IO.Path]::ChangeExtension($MyInvocation.MyCommand.Name, "bdsgroup"))
    
    # Bdsgroup template
    $groupXml = [xml]@"
    <?xml version="1.0" encoding="utf-8"?>
    <BorlandProject>
        <PersonalityInfo>
            <Option>
                <Option Name="Personality">Default.Personality</Option>
                <Option Name="ProjectType"></Option>
                <Option Name="Version">1.0</Option>
                <Option Name="GUID">{$([guid]::NewGuid().ToString())}</Option>
            </Option>
        </PersonalityInfo>
        <Default.Personality>
            <Projects>
                <Projects Name="Targets"></Projects>
            </Projects>
            <Dependencies/>
        </Default.Personality>
    </BorlandProject>
    "@
    
    ### Functions ###
    
    function ShowUsage()
    {
        $myName = Split-Path -Leaf $MyInvocation.ScriptName
        Write-Host "Usage:"
        Write-Host "`t$myName [-path <Path>] [-exclude <Exclude>] [-help]"
        Write-Host
        Write-Host "`t-path <Path>"
        Write-Host "`t`tSpecifies the directory to begin searching for *.bdsproj."
        Write-Host "`t`tPath:" $path
        Write-Host
        Write-Host "`t-exclude <Exclude>"
        Write-Host "`t`tSpecifies a directory to exclude from the search."
        Write-Host "`t`tExclude:" $exclude
        Write-Host
        Write-Host "`t-help"
        Write-Host "`t`tDisplays this message."
        Write-Host
        Write-Host "Output will be written to:"
        Write-Host "`t" $outfile
        Write-Host
        Write-Host "Limitations:"
        Write-Host "`tDoes not support multiple directories for Path or Exclude."
    }
    
    # Get the target name.
    # e.g. "D:\dev\src\foo.bdsproj" returns "foo.exe"
    function GetTarget($bdsproj)
    {
        $mainSource = GetMainSource($bdsproj)
        $ext = GetTargetExt($mainSource)
        Split-Path -Leaf ([IO.Path]::ChangeExtension($mainSource, $ext))
    }
    
    # Get the relative project path.
    # e.g. If path is "D:\dev" then "D:\dev\src\foo.bdsproj" returns "src\foo.bdsproj"
    function GetProject($bdsproj)
    {
        $prefixLen = $path.Length
        $suffixLen = $bdsproj.Length - $prefixLen
        $bdsproj.Substring($prefixLen, $suffixLen)
    }
    
    # Get the fully qualified MainSource (dpr/dpk) path.
    # e.g. "D:\dev\src\foo.bdsproj" returns "D:\dev\src\foo.dpr"
    function GetMainSource($bdsproj)
    {
        $projXml = [xml](Get-Content $bdsproj)
        $mainSource = $projXml.BorlandProject."Delphi.Personality".Source.Source |
            Where-Object { $_.Name -eq "MainSource" }
    
        $result = Join-Path (Split-Path -Path $bdsproj) $mainSource.InnerText
    
        if (-not (Test-Path $result))
        {
            throw "No MainSource (dpr/dpk) found for $bdsproj"
        }
    
        $result
    }
    
    # Get the target extension depending on the source type.
    function GetTargetExt($mainSource)
    {
        $targets = @{"package"="pkg"; "library"="dll"; "program"="exe"}
        $targetType = GetTargetType($mainSource)
        $targets[$targetType]
    }
    
    # Read the target type out of the dpr.
    function GetTargetType($mainSource)
    {
        $name = [IO.Path]::GetFileNameWithoutExtension($mainSource)
        $pattern = "^\s*(package|library|program)\s+$name;$"
        $matches = (Select-String -Path $mainSource -Pattern $pattern)
        if ($matches -eq $null)
        {
            throw "Unknown target type (pkg/dll/exe) for $mainSource"
        }
        $matches.Matches[0].Groups[1].Value
    }
    
    # Add a project entry to groupXml.
    # e.g. <Projects Name="foo.exe">src\foo.bdsproj</Projects>
    function AddProject($target, $project)
    {
        $node = $groupXml.CreateElement("Projects")
        $node.SetAttribute("Name", $target)
        $node.InnerText = $project
        $groupXml.BorlandProject."Default.Personality".Projects.AppendChild($node) | Out-Null
    
        $targets = $groupXml.BorlandProject."Default.Personality".Projects.Projects |
            Where-Object { $_.Name -eq "Targets" }
        $targets.InnerText = $targets.InnerText + " " + $target
    }
    
    ### Main ###
    
    if ($help)
    {
        ShowUsage
    }
    else
    {
        Get-ChildItem -Path $path -Include "*.bdsproj" -Recurse |
        Where-Object { $exclude -eq "" -or $_.FullName -notmatch $exclude } |
        ForEach-Object { AddProject (GetTarget $_.FullName) (GetProject $_.FullName) }
    
        $groupXml.OuterXml | Out-File -Encoding "UTF8" $outfile
    }
    
        3
  •  2
  •   Uli Gerhardt    14 年前

    也许你可以使用类似于 find (可能还有一些Delphi程序)创建一个包含所有项目的*.bdsgroup文件,并在D2007中打开它。