adamreeve / semver.net

Semantic versioning for .NET
MIT License
117 stars 22 forks source link

Usage in PowerShell #34

Closed felixfbecker closed 6 years ago

felixfbecker commented 6 years ago

Node's semver package has both a programmatic API and a CLI. Is there a way to use this package inside PowerShell?

adamreeve commented 6 years ago

It looks like it's possible to use any .NET dll from PowerShell: https://stackoverflow.com/q/3079346/395337. It would be possible to create a PowerShell module that had a nicer interface than using the dll directly, but I'm not sure there's much need for that when the semver CLI from Node could be used from PowerShell. If someone did have a need for this I'd be happy for them to contribute it to this project but I'm not doing much new feature development myself, mostly only maintenance and bug fixes.

felixfbecker commented 6 years ago

The use case is to use it in https://github.com/aaronpowell/ps-nvmw - before a user has Node or the semver CLI installed :D

I am unsure how the DLL approach works. Would that be added with NuGet and then packaged in the PowerShell package? Do DLLs even work on macOS and Linux?

adamreeve commented 6 years ago

A DLL built for the full .NET framework won't work but .NET core creates DLLs on Mac and Linux and I imagine they should be usable from PowerShell. I haven't tried this myself though. As for how to package a PowerShell module that references a NuGet package, I guess you'd need to use NuGet to install the DLL first. It looks like you could also build a PowerShell module in .NET core that references the package (https://github.com/PowerShell/PowerShell/blob/master/docs/cmdlet-example/command-line-simple-example.md) and then you should be able to publish the module to the PowerShell gallery using PowerShellGet.

felixfbecker commented 6 years ago

Publishing a module and depending on that sounds like a cleaner approach than bundling DLLs directly in ps-nvmw, but I'm worried about getting that to work and up to date. Given the use case is there, would you be opposed to having cmdlets exposed from this repo? I can imagine this utility being useful for all kinds of PS scripts that need to interact with semantically-versioned software that are not related to Node and do not want to depend on it

adamreeve commented 6 years ago

Yeah I'd be happy to have the cmdlets published from this repo if you want to go with that approach.

felixfbecker commented 6 years ago

I started implementing it, but then realised that there is actually not that much to wrap in a CmdLet. It is way easier to just instantiate the object and use PS native utils like -gt/-lt, Sort-Object, Select-Object etc as SemVer.Version implements Comparable.

ps-nvm now uses SemVer.NET for full SemVer range support, cross-platform on Linux/macOS/Windows 🎉

adamreeve commented 6 years ago

👍 nice!