I installed a package which I found with Find-Package and the Nuget package provider. With Get-Package I verified that it was installed. But how do I use that package in a powershell script?
In reply to postanote:
Thanks for the reply. You were right I was not complete in my explanation... :-) I found a library on Github (Nlight) and I want to leverage the DelimitedTextRecordReader/Writer classes to experiment with importing CSV-files. I am not a .Net developer but a PS enthusiast so I was wondering if I could leverage this library in PS. First I had to register NGet as a new package source: Register-PackageSource -Name nuget.org -Location http://www.nuget.org/api/v2 -Force -Trusted -ProviderName NuGet When I use Find-Package NLight i get: Name Version Source Summary ---- ------- ------ ------- NLight 1.1.6 nuget.org Toolbox for .NET projects With Install-Package NLight I get a bunch of packages installed in the folder C:\Program Files\PackageManagement\NuGet\Packages. Using Get-Package NLight I get Name Version Source ProviderName ---- ------- ------ ------------ NLight 1.1.6 C:\Program Files\PackageManag... NuGet So far so good. And then... what to do?... :-D. The idea is to create a wrapper/module around those classes but I cannot find the right way to do create/access them.
I have seen some projects on Github where they leverage a .Net lib (e.g. the Nancy lib) with PS (github.com/.../). But it seems quite complex. I cannot find good blogs/sites where it is explained how to incorporate .Net libs in PS. Maybe PS is not the right environment to incorporate .Net libraries. I am learning the do's and don'ts with PS so any help and pointers in the right direction would be great. Regards, Q
In reply to Kjoebie:
I never heard of Nlight, so no real comment on it. Yet, PowerShell native provide cmdlets for text file import, Csv and xml. Specifically, the Import-Clixml and Import-Csv cmdlets.
What is it about Nlight which is of interest that the built-in ones above cannot provide? The whole idea about importing text data with the import-cmdlets, is to turn them into PoSH object for whatever work you need to do with the file.
Or maybe you are just experimenting as a learning effort? Which is a good thing, as PoSH is all about discovery and what is possible. Most things are built-in, many things you have to be a bit more creative to get what you need as at results.
Well a quick look at the Git repo source, shows, it’s all MS C# classes. This means you have to bring (instantiate) that class into your PoSH session in order to use it. There are several articles on how to use .Net classes in PoSH.
PoSH is requires .NET to work at all. When you look at each of the PoSH (WMF), you see that you must be on a specific version of .Net Framework, based on the PoSH (WMF) version you install. So, it can use all the .NET classes just as any other programming language.
# PowerShell: How to Create and Use Classes‘social.technet.microsoft.com/wiki/contents/articles/27080.powershell-how-to-create-and-use-classes.aspx'
# Why Use .NET Framework Classes from Within PowerShell?‘blogs.technet.microsoft.com/heyscriptingguy/2012/02/11/why-use-net-framework-classes-from-within-powershell'
# Use PowerShell to Work with the .NET Framework Classes‘blogs.technet.microsoft.com/heyscriptingguy/2010/11/11/use-powershell-to-work-with-the-net-framework-classes'
Using CSharp (C#) code in Powershell scripts‘blogs.technet.microsoft.com/stefan_gossner/2010/05/07/using-csharp-c-code-in-powershell-scripts’
# Implementing a .NET Class in PowerShell v5‘trevorsullivan.net/2014/10/25/implementing-a-net-class-in-powershell-v5'
Here is the MVA (Microsoft Virtual Academy) course on PoSH specifically on classes.‘mva.microsoft.com/en-us/training-courses/whats-new-in-powershell-v5-16434#!’
Another 2hr training video on using / creating classes for use in PoSH# Virtual PowerShell User Group - March 2015‘youtube.com/watch?v=gkwyhUc-xRQ’
So, you will note, from the above, that whole Nuget import registration and PoSH use case you are after, this may have been a non-sequitur in the stream of thought. As one can literally copy a defined class in another .Net language repo / source (or create your own) and use it in PoSH.
Point of Note, if you did not know already, PowerShellGet (built-in to PoSHv5) and as a install on PoSH v4 is the PoSH version of get, which Find-Module is part of and brings down packages / module from the PowerShell Gallery. You could have also chosen to use Chocolatey instead. ‘chocolatey.org’.