Creating PowerShell module via .NET class library

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Kahlan Amnell Kahlan Amnell 1 year, 3 months ago.

  • Author
    Posts
  • #32464
    Profile photo of Kahlan Amnell
    Kahlan Amnell
    Participant

    I am building a PowerShell module in .NET. I've read somewhere that PowerShell 3.0 targets .NET Framework 4.0 and so my class library project must also be targeting the same version. My problem is I have existing projects that are targeting .NET Framework 4.5 and referencing them in my powershell module class library project using .NET 4.0 does not work, it does not see those project references unless they are the same version. Is there a way around this or is PowerShell going to target .NET 4.5 soon? Changing the .NET Framework version of my existing projects is not an option for me right now. Any suggestions?

  • #32465
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    You can have your PowerShell module target .NET 4.5. Just make sure your module manifest reflects this in its CLRVersion property.

  • #32466
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Also, in the opposite direction, if you're writing a module that is compatible with PowerShell v2.0, then it's fine for you to compile it once using .NET 2.0, 3.0 or 3.5 (all valid for PowerShell 2.0), and the module should still run just fine when imported in PS v3 or later, as far as I know. When I distribute https://github.com/dlwyatt/PowerShellLoggingModule , I don't compile it multiple times for different frameworks, and I've never had any complaints about it not working in later PS versions.

  • #32469
    Profile photo of Kahlan Amnell
    Kahlan Amnell
    Participant

    Thanks Dave!

You must be logged in to reply to this topic.