7

Is it possible to run PowerShell 1.0 (or 2.0 CTP) backed by the 3.5 runtime instead of 2.0?

We're building a .NET 3.5 solution, and I'd still like to use PowerShell as our scripting engine for scheduled tasks, etc.

I don't need LINQ syntax or anything, just the 3.5 libraries and runtime.

FOLLOWUP: thank you for the reply about dynamically loading assemblies. But let me clarify my question: is there any way to run PowerShell so that the 3.5 libraries run by default? So that if I enter New-Object System.Xml.XmlDocument, for example, I'm actually getting the 3.5 version by default?

Semi-related question: if I do have to dynamically load, say, the System.Xml library from 3.5, will it overlay the existing symbol definitions such that the next time I type New-Object System.Xml.XmlDocument, it will load the 3.5 version?

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Zach Blocker
  • 309
  • 6
  • 16

4 Answers4

8

If you have 3.5 installed on your system, that is what you'll get when you run PowerShell.

PowerShell is only "requires" 2.0 but 3.0 and 3.5 are compatible and autoforward when installed. In PowerShell V2, we actually look to see what version you have and "light up" certain features (e.g. PowerShell_ISE and Out-GridView are available when you have 3.51).

Experiment! Enjoy! Engage!

Jeffrey Snover [MSFT] Windows Management Partner Architect

Jeffrey Snover - MSFT
  • 10,173
  • 4
  • 21
  • 13
4

As long as your get your fully qualified name right, I don't see why this wouldn't work:

[System.Reflection.Assembly]::Load("System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")

I only used Linq as that was the first one to come to mind. At that point, the ddl is loaded, and you can create/use objects out of that.

James Pogran
  • 4,279
  • 2
  • 31
  • 23
  • I assume, though, that if I dynamically load a .NET 3.5 assembly (including any that I might write), and then create a .NET object (say, a System.Xml.XmlDocument) and pass it to a method in my assembly, I'll be passing a 2.0 object to a 3.5 object. Am I correct? – Zach Blocker Feb 06 '09 at 19:17
  • So to pass a 3.5 XmlDocument, I'd actually need to import the .NET 3.5 System.Xml library just the way you demonstrated doing the System.Xml.Linq library. – Zach Blocker Feb 06 '09 at 19:20
  • I'm not a pro-dev person, but I would tend to agree that your assumptions above are correct. – Marco Shaw Feb 06 '09 at 19:27
3

PowerShell was built against 2.0, so you don't have any options but to have 2.0 present at least. But like James says, you can load 3.0 and 3.5 functionality by loading the appropriate assembly. LINQ is a good example from 3.5, but you can also do WPF (3.0) from PowerShell. Be mindful of STA and MTA for WPF though, as only PowerShell v2 has full support for WPF (full support for thread affinity).

Marco Shaw
  • 1,117
  • 6
  • 13
  • What about my question about overlays? Can I replace (or at least) hide a 2.0 assembly by loading the equivalent 3.5 assembly, so that the default implementation of System.Xml.XmlDocument (for example) changes? – Zach Blocker Feb 06 '09 at 19:36
  • I'll try to find a way to determine this for sure. Sorry, I missed that part. Feel free to unmark as the answer. – Marco Shaw Feb 08 '09 at 20:23
3

3.5 is effectively an ADD-ON for 2.0. That is to say, there are no superceded classes in 3.5; it is not a replacement. The CLR (common language runtime) is still v2.0.

x0n
  • 51,312
  • 7
  • 89
  • 111