多版本Vivado工程文件自动选择打开相应版本软件

📅 2026/8/4 16:40:37
多版本Vivado工程文件自动选择打开相应版本软件
1备份当前关联键1.1 打开注册表编辑器Win R → 输入 regedit → 回车。HKEY_CURRENT_USER └─ Software └─ Classes └─ Applications └─ vvgl.exe └─ shell └─ open (默认值) -- 这里记录双击时执行的命令1.2 右键 → 导出保存为 vivado_xpr_backup.reg保存到桌面或其他位置以防万一。2 让系统自动根据工程版本选择 Vivado 版本2.1新建文件 vivado_launcher.ps1C:\Users\%USERNAME%\bin\vivado_launcher.ps1如果 bin 文件夹不存在请自行创建2.2注册表改为调用 PowerShell 脚本在注册表找到直接复制到地址栏 ​​​​​​​HKEY_CURRENT_USER\Software\Classes\Applications\vvgl.exe\shell\open编辑 (默认值) → 改为C:\\Program Files\\PowerShell\\7\\pwsh.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File C:\\Users\\%USERNAME%\\bin\\vivado_launcher.ps1 -XprPath %1保存后 重启资源管理器。注意我电脑安装了power shell 7win11默认是power shell 5默认安装位置C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe可以改成自己电脑power shell的位置。你需要修改部分# --- 已安装的 Vivado 版本映射 (路径在此维护) --- $VivadoDirs { 2018.3 D:\Xilinx\Vivado\Vivado\2018.3 2019.2 D:\Xilinx\Vivado\2019.2 } $DefaultVersion 2019.2完整脚本param( [Parameter(Mandatory$true)][string]$XprPath, [switch]$DryRun ) $ErrorActionPreference Stop $LogFile C:\Users\W\bin\vivado_launcher.log function Write-Log([string]$msg) { $line [{0}] {1} -f (Get-Date -Format HH:mm:ss.fff), $msg Add-Content -LiteralPath $LogFile -Value $line -ErrorAction SilentlyContinue } try { Write-Log 启动 xprPath$XprPath Write-Log PS version: $($PSVersionTable.PSVersion) # --- 已安装的 Vivado 版本映射 (路径在此维护) --- $VivadoDirs { 2018.3 D:\Xilinx\Vivado\Vivado\2018.3 2019.2 D:\Xilinx\Vivado\2019.2 } $DefaultVersion 2019.2 # --- 1. 读取 .xpr 头部找版本 --- $detected $null if (Test-Path -LiteralPath $XprPath) { $content Get-Content -LiteralPath $XprPath -TotalCount 5 -ErrorAction SilentlyContinue | Out-String $m [regex]::Match($content, Vivado\sv(\d{4}\.\d)) if ($m.Success) { $detected $m.Groups[1].Value } } Write-Log Detected ver: $detected # --- 2. 选择版本 (检测不到或不匹配则用默认) --- $resolved $detected $vivadoDir $null if ($VivadoDirs.ContainsKey($resolved)) { $vivadoDir $VivadoDirs[$resolved] $bat Join-Path $vivadoDir bin\vivado.bat $exe Join-Path $vivadoDir bin\unwrapped\win64.o\vvgl.exe if (-not ((Test-Path $bat) -and (Test-Path $exe))) { $vivadoDir $null } } else { $vivadoDir $null } if (-not $vivadoDir) { $resolved $DefaultVersion $vivadoDir $VivadoDirs[$DefaultVersion] } Write-Log Resolved ver: $resolved Dir: $vivadoDir $vvgl Join-Path $vivadoDir bin\unwrapped\win64.o\vvgl.exe $vbat Join-Path $vivadoDir bin\vivado.bat if ($DryRun) { Write-Output XPR : $XprPath Write-Output Detected ver : $detected Write-Output Resolved ver : $resolved Write-Output Vivado dir : $vivadoDir Write-Output Command : $vvgl $vbat $XprPath return } # --- 3. 启动 Vivado (关键: vivado.bat 不加引号) --- Write-Log Command: $vvgl $vbat $XprPath $psi New-Object System.Diagnostics.ProcessStartInfo $psi.FileName $vvgl $psi.Arguments $vbat $XprPath $psi.UseShellExecute $false $psi.WorkingDirectory Split-Path $vbat $proc [System.Diagnostics.Process]::Start($psi) Write-Log Started PID$($proc.Id) } catch { Write-Log FAILED: $($_.Exception.Message) throw }3 重启 Explorer 使更改生效在 PowerShell管理员执行 Stop-Process -Name explorer -Force Start-Sleep 2 Start-Process explorer.exe