Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ptapply to work in PowerShell 7 #68

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

drab0wl
Copy link
Contributor

@drab0wl drab0wl commented Feb 11, 2025

Fixes #67

Update src/Features/Patch.Autoload.psm1 to support PowerShell 7.

  • Add a check to determine if running in PowerShell 7 by checking $PSVersionTable.PSVersion.Major.
  • Update the $powershellPath variable to use pwsh.exe if running in PowerShell 7, otherwise use powershell.exe.

For more details, open the Copilot Workspace session.

Fixes gundermanc#67

Update `src/Features/Patch.Autoload.psm1` to support PowerShell 7.

* Add a check to determine if running in PowerShell 7 by checking `$PSVersionTable.PSVersion.Major`.
* Update the `$powershellPath` variable to use `pwsh.exe` if running in PowerShell 7, otherwise use `powershell.exe`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/gundermanc/tools/issues/67?shareId=XXXX-XXXX-XXXX-XXXX).
@drab0wl
Copy link
Contributor Author

drab0wl commented Feb 11, 2025

This was all generated by Copilot Workspaces. It hasn't been tested yet.

@drab0wl
Copy link
Contributor Author

drab0wl commented Feb 11, 2025

This does work; however, the version checking is still broken.

$destinationAssembly = [System.Reflection.Assembly]::LoadFrom($destination)
fails in ps7 because the assemblies have already been loaded.

pwsh.exe: Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'Microsoft.VisualStudio.Shell.Connected, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Assembly with same name is already loaded"

This could be because ps7 uses .NET vs Framework. I couldn't get it to work, but the files still patch. I'll open a separate issue.

@drab0wl
Copy link
Contributor Author

drab0wl commented Feb 11, 2025

Verified this change works in both Windows PowerShell and PowerShell 7 on a Windows machine.

@@ -187,7 +187,11 @@ function CheckAssemblyVersions($source, $destination)

Write-Host " - Checking that assembly versions match..."

$powershellPath = (Join-Path $PsHome "powershell.exe")
if ($PSVersionTable.PSVersion.Major -ge 6) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment as to why this is necessary, what the behavior would be without it, and what's expected?

@gundermanc
Copy link
Owner

Can you rev- the version number?

@gundermanc gundermanc merged commit e4a33a2 into gundermanc:master Feb 11, 2025
@drab0wl drab0wl deleted the fix-ptapply branch February 11, 2025 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ptapply fails in PowerShell 7
2 participants