1

I'm trying to create a nuget package from my class libary. So far I managed to create and install the package in a test project, but I also want to create a package manager command. My NuGet package is created with the NuGet Package Explorer.

NuGet Package structure

structure

NuGet files content

init.ps1

param($installPath, $toolsPath, $package) 
Import-Module (Join-Path $toolsPath MyNuGetCommands.psm1)

MyNuGetCommands.psm1

function Hello($name, $city) 
{ 
    Write-Host (‘Hello ‘ + $name + ‘. See you soon in ‘ + $city + ‘.’) 

    $lib = [Reflection.Assembly]::LoadFile("\\lib\EF.XML.dll")
    $obj = new-object Parser
    $result = $obj.UpdateXml()
}

Export-ModuleMember Hello

Register-TabExpansion ‘Hello’ @{  
‘name’ = { "MSFTees", "MVPs", "My friends" }; 
‘city’ = { "Redmond", "Seattle", "Bellevue", "Duvall" }; 
}  

I found the Hello function on the net and it worked in my project so I thougt lets add some lines found here to call my C# method. When I call the Hello function in my test project I get this errors:

Error 1

Exception calling "LoadFile" with "1" argument(s): "Cannot find the network path. (Exception from HRESULT: 0x80070035)" At \svr\redirectedfolders\Stage\my documents\visual studio 2015\Projects\Test\packages\XML.EF.1.0.0\tools\MyNuGetCommands.psm1:5 char:43 + $lib = [Reflection.Assembly]::LoadFile <<<< ("\lib\EF.XML.dll") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

Error 2

New-Object : Cannot find type [Parser]: make sure the assembly containing this type is loaded. At \svr\redirectedfolders\Stage\my documents\visual studio 2015\Projects\Test\packages\XML.EF.1.0.0\tools\MyNuGetCommands.psm1:6 char:22 + $obj = new-object <<<< Parser + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

Error 3

You cannot call a method on a null-valued expression. At \svr\redirectedfolders\Stage\my documents\visual studio 2015\Projects\Test\packages\XML.EF.1.0.0\tools\MyNuGetCommands.psm1:7 char:29 + $result = $obj.UpdateXml <<<< () + CategoryInfo : InvalidOperation: (UpdateXml:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

So I think in the above errors obj is null but how can I fix this (I am not sure if LoadFile path is correct)? I did run set-executionpolicy RemoteSigned in Powershell.

Parser.cs file structure in EF.XML.dll

public class Parser
{       
    public void UpdateXml()
    {
        //code
    }
}

This is the code to I use to call the method from a .cs file (which works but I want to call this from my Powershell Module:

 var parser = new EF.XML.Parser();
 parser.UpdateXml();
6
  • new-object Parser -> new-object EF.XML.Parser Commented Oct 19, 2015 at 14:49
  • @PetSerAl I tried your suggestion, but I still get the same errors. Commented Oct 19, 2015 at 14:53
  • How about [Reflection.Assembly]::LoadFile("\\lib\EF.XML.dll")? Does it throw or not? If not, does it return Assembly object? Does path specified exactly like that "\\lib\EF.XML.dll"? Commented Oct 19, 2015 at 15:00
  • @PetSerAl I will try this tommorow when I continue working on this project and I will let you know what the results are. Commented Oct 19, 2015 at 17:31
  • @PetSerAl I also get an error for LoadFile(), the error is added to my post. I also tried Add-Type -AssemblyName but the dll is not found. Commented Oct 20, 2015 at 6:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.