将 PowerShell 与 .NET 3.5 运行时/库结合使用
是否可以运行由 3.5 运行时而不是 2.0 支持的 PowerShell 1.0(或 2.0 CTP)?
我们正在构建一个 .NET 3.5 解决方案,我仍然想使用 PowerShell 作为我们的脚本引擎来执行计划任务等。
我不需要 LINQ 语法或任何东西,只需要 3.5 库和运行时。
后续:感谢您关于动态加载程序集的回复。 但让我澄清一下我的问题:有什么方法可以运行 PowerShell 以便默认运行 3.5 库吗? 例如,如果我输入 New-Object System.Xml.XmlDocument
,我实际上会默认获得 3.5 版本?
半相关问题:如果我确实必须动态加载3.5中的System.Xml
库,它会覆盖现有符号吗定义使得下一次当我输入New-Object System.Xml.XmlDocument
时,它将加载3.5版本?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您的系统上安装了 3.5,那么您在运行 PowerShell 时将得到该版本。
PowerShell 仅“需要”2.0,但 3.0 和 3.5 兼容并在安装时自动转发。 在PowerShell V2 中,我们实际上会查看您拥有的版本并“点亮”某些功能(例如,当您拥有3.51 时,PowerShell_ISE 和Out-GridView 可用)。
实验! 享受! 从事!
杰弗里·斯诺尔 [MSFT]
Windows 管理合作伙伴架构师
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
只要你的完全限定名称正确,我不明白为什么这行不通:
我只使用 Linq,因为这是第一个想到的。 此时,ddl 已加载,您可以从中创建/使用对象。
As long as your get your fully qualified name right, I don't see why this wouldn't work:
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.
PowerShell 是针对 2.0 构建的,因此您别无选择,只能至少使用 2.0。 但就像 James 所说,您可以通过加载适当的程序集来加载 3.0 和 3.5 功能。 LINQ 是 3.5 中的一个很好的示例,但您也可以从 PowerShell 执行 WPF (3.0)。 但请注意 WPF 的 STA 和 MTA,因为只有 PowerShell v2 完全支持 WPF(完全支持线程关联)。
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).
3.5 实际上是 2.0 的附加组件。 也就是说3.5中没有被取代的类; 它不是替代品。 CLR(公共语言运行时)仍然是 v2.0。
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.