Resolving PowerShell Module Assembly Dependency Conflicts - Andy Jordan - PSConfEU 2023

Published: 07 July 2023
on channel: PowerShell Conference EU
279
3

In this episode, Andy Jordan begins by introducing themselves and their role on the PowerShell team at Microsoft. They also mention their passion for amateur bike racing and how it allows them to pursue a hobby outside of work.

The main topic of discussion is assembly dependency conflicts in PowerShell modules, particularly binary modules. The speaker explains that these conflicts arise when different modules use different versions of the same library. They emphasize that managing these dependencies can be complex and that PowerShell's design as a single process contributes to the difficulty.

The speaker acknowledges that dependency conflicts are a challenging and opaque topic, and to address this, they've divided the talk into two parts. They will cover the challenges and issues with assembly dependency conflicts, and another speaker, Emmanuel Palm, will give a more detailed demonstration of ways to avoid these conflicts.

They explain that as programmers and module authors, they often rely on existing code and libraries to save time and improve security. However, when it comes to binary modules and their dependencies in PowerShell, it becomes complex to manage these dependencies within the .NET process. They discuss the concept of dependency hell, where dependencies can become incredibly complex and nested within each other.

The speaker gives examples of well-known libraries like Newtonsoft.Json and mentions that when there are multiple versions of these libraries, conflicts can arise. They explain that PowerShell itself has many dependencies and that combining them with other tools can create a dependency hell scenario that is difficult to manage and resolve.

The speaker goes on to discuss the difference between .NET Core and .NET Framework, which further complicates dependency management in PowerShell. They mention that while PowerShell 7 introduces a new feature called the system.runtime.loader.assemblyload context, older versions like PowerShell 5.1 lack this capability.

The main solutions discussed for resolving these conflicts are rewriting the module or using an assembly load context (ALC). However, the speaker mentions that both options have limitations and can be complex to implement. They highlight some modules they have come across that have not handled dependencies correctly and offer insights into the challenges faced while implementing modules.

The speaker also discusses the global assembly cache in .NET Framework and how it is the first place searched for an assembly in Windows desktop applications. They mention that while this feature exists, it can make resolving conflicts harder and often renders assembly resolve handlers useless.

They conclude by mentioning that there is no straightforward solution to these dependency issues, and the general recommendation is to migrate to PowerShell 7 whenever possible. They also invite questions from the audience and offer to demonstrate the workarounds again if there is interest.

Overall, this episode dives deep into the challenges and complexities of managing assembly dependency conflicts in PowerShell modules. The main speaker provides insights and examples throughout the discussion to help the audience understand the topic better.

Chapters:
00:00:00 Resolving PowerShell Module Assembly Dependency Conflicts - Andy Jordan (THEY/THEM) - PSConfEU 2023
00:00:07 Porting PowerShell to Linux and Mac OS
00:02:38 Part 1: Exploring the complexity of assembly dependency conflicts
00:08:45 Introducing PowerShell Core and its challenges
00:10:45 Assembly resolution in PowerShell 7 with system.runtime.loader.assemblyload context
00:12:59 The importance of the global assembly cache in .NET Framework
00:15:07 Options for avoiding dependency conflicts in PowerShell modules
00:17:23 Exploring the effectiveness of assembly resolve handlers
00:24:30 Annoying but robust module rewriting options
00:26:37 Unloading of modules can cause clashes and crashing
00:29:19 B…


Watch video Resolving PowerShell Module Assembly Dependency Conflicts - Andy Jordan - PSConfEU 2023 online, duration hours minute second in high quality that is uploaded to the channel PowerShell Conference EU 07 July 2023. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 279 times and liked it 3 visitors.