如何批量转换bdsproj到dproj?

时间:2010-11-19 02:43:04

标签: delphi delphi-2007

我们最近从Delphi 2006升级到Delphi 2007,项目文件从.bdsproj更改为.dproj

到目前为止,我的研究表明,为了创建.dproj,需要在D2007 IDE中打开现有项目。我们有超过400 .bdsproj个文件,因此手动执行此操作并不实用。

我想出的过程是使用以下命令从命令行打开所有项目:

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

这不太理想,因为它很慢(等待BDS加载,等待编译发生,等待BDS关闭,......)。

是否有一种有效的方法可以将多个.bdsproj转换为.dproj

注意:上面命令行中的“find”是类似UNIX的查找(例如MKS或GNU),它搜索文件,而不是Windows查找文件中搜索文本的内容。 < / p>

3 个答案:

答案 0 :(得分:3)

您可以一次打开多个项目。即使使用拖放也是如此。

  • 选择40个项目
  • 将它们拖到IDE
  • 点击是40次
  • 全部保存
  • 关闭所有
  • 重复直至完成。

答案 1 :(得分:3)

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

运行脚本后,打开带有D2007的bdsgroup,将项目转换为dproj。 D2007也产生groupproj,它似乎是D2007相当于bdsgroup

提示:

  • 使用-help运行脚本以查看说明。
  • 在打开bdsgroup之前启动D2007,似乎可以更快地处理项目。
  • 您无需保存项目,打开它们就足以创建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
}

答案 2 :(得分:2)

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