Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PowerShell with .NET 3.5 runtime/libraries

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?

like image 494
Zach Blocker Avatar asked Feb 06 '09 18:02

Zach Blocker


People also ask

Can you use .NET in PowerShell?

Windows PowerShell provides syntax that allows you to create . NET objects and then explore the members of those . NET objects. You have seen many examples in earlier chapters of using the get-member cmdlet to explore the members of objects.


2 Answers

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.

like image 32
James Pogran Avatar answered Oct 04 '22 02:10

James Pogran


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

like image 194
Jeffrey Snover - MSFT Avatar answered Oct 04 '22 02:10

Jeffrey Snover - MSFT