I am writing a PowerShell cmdlet in C#, and all is OK until I reference libraries from nuget which then throws regarding could not load file or assembly.
It is as if the code is not being built into the DLL - how can I ensure all referenced nuget libs are embedded within my DLL, or at least externally registered, to allow the cmdlet to be used?
In this case it is specifically complaining about Nito.AsyncEx (or if i remove this, it will then go to the next library such Flurl) basically any libs which I referenced via nuget for the project:
Import-Module .\PolygonIo.PowerShell.dll
Get-Aggregates -StocksTicker TSLA
Get-Aggregates : Could not load file or assembly 'Nito.AsyncEx.Tasks, Version=5.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file
specified.
At line:1 char:1
+ Get-Aggregates -StocksTicker TSLA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Aggregates], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,PolygonIo.PowerShell.GetAggregates
My proj file is:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nito.AsyncEx" Version="5.1.0" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PolygonIo.WebApi\PolygonIo.WebApi.csproj" />
</ItemGroup>
</Project>
The code in the cmdlet is:
public class GetAggregates : Cmdlet
{
/* snip parameters and ProcessRecordAsync() */
protected override void ProcessRecord()
{
base.ProcessRecord();
var task = ProcessRecordAsync();
var result = task.WaitAndUnwrapException();
}
}
The files that are generated are (and i note, where i would normally have all referenced lib DLLs here like in my other built applications, they are missing):
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 21/12/2020 23:49 26112 PolygonIo.Api.dll
-a---- 21/12/2020 23:49 12300 PolygonIo.Api.pdb
-a---- 21/12/2020 23:49 9838 PolygonIo.PowerShell.deps.json
-a---- 21/12/2020 23:49 9216 PolygonIo.PowerShell.dll
-a---- 21/12/2020 23:49 9156 PolygonIo.PowerShell.pdb
And PolygonIo.PowerShell.deps.json is:
{
"runtimeTarget": {
"name": ".NETStandard,Version=v2.0/",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETStandard,Version=v2.0": {},
".NETStandard,Version=v2.0/": {
"PolygonIo.PowerShell/1.0.0": {
"dependencies": {
"NETStandard.Library": "2.0.3",
"Nito.AsyncEx": "5.1.0",
"PolygonIo.Api": "1.0.0",
"PowerShellStandard.Library": "5.1.0"
},
"runtime": {
"PolygonIo.PowerShell.dll": {}
}
},
"Flurl/3.0.1": {
"runtime": {
"lib/netstandard2.0/Flurl.dll": {
"assemblyVersion": "3.0.1.0",
"fileVersion": "3.0.1.0"
}
}
},
"Microsoft.NETCore.Platforms/1.1.0": {},
"NETStandard.Library/2.0.3": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
},
"Newtonsoft.Json/12.0.3": {
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"assemblyVersion": "12.0.0.0",
"fileVersion": "12.0.3.23909"
}
}
},
"Nito.AsyncEx/5.1.0": {
"dependencies": {
"Nito.AsyncEx.Context": "5.1.0",
"Nito.AsyncEx.Coordination": "5.1.0",
"Nito.AsyncEx.Interop.WaitHandles": "5.1.0",
"Nito.AsyncEx.Oop": "5.1.0",
"Nito.AsyncEx.Tasks": "5.1.0",
"Nito.Cancellation": "1.1.0"
}
},
"Nito.AsyncEx.Context/5.1.0": {
"dependencies": {
"Nito.AsyncEx.Tasks": "5.1.0"
},
"runtime": {
"lib/netstandard2.0/Nito.AsyncEx.Context.dll": {
"assemblyVersion": "5.1.0.0",
"fileVersion": "5.1.0.0"
}
}
},
"Nito.AsyncEx.Coordination/5.1.0": {
"dependencies": {
"Nito.AsyncEx.Tasks": "5.1.0",
"Nito.Collections.Deque": "1.1.0"
},
"runtime": {
"lib/netstandard2.0/Nito.AsyncEx.Coordination.dll": {
"assemblyVersion": "5.1.0.0",
"fileVersion": "5.1.0.0"
}
}
},
"Nito.AsyncEx.Interop.WaitHandles/5.1.0": {
"dependencies": {
"Nito.AsyncEx.Tasks": "5.1.0"
},
"runtime": {
"lib/netstandard2.0/Nito.AsyncEx.Interop.WaitHandles.dll": {
"assemblyVersion": "5.1.0.0",
"fileVersion": "5.1.0.0"
}
}
},
"Nito.AsyncEx.Oop/5.1.0": {
"dependencies": {
"Nito.AsyncEx.Coordination": "5.1.0"
},
"runtime": {
"lib/netstandard2.0/Nito.AsyncEx.Oop.dll": {
"assemblyVersion": "5.1.0.0",
"fileVersion": "5.1.0.0"
}
}
},
"Nito.AsyncEx.Tasks/5.1.0": {
"dependencies": {
"Nito.Disposables": "2.2.0"
},
"runtime": {
"lib/netstandard2.0/Nito.AsyncEx.Tasks.dll": {
"assemblyVersion": "5.1.0.0",
"fileVersion": "5.1.0.0"
}
}
},
"Nito.Cancellation/1.1.0": {
"dependencies": {
"Nito.Disposables": "2.2.0"
},
"runtime": {
"lib/netstandard2.0/Nito.Cancellation.dll": {
"assemblyVersion": "1.1.0.0",
"fileVersion": "1.1.0.0"
}
}
},
"Nito.Collections.Deque/1.1.0": {
"runtime": {
"lib/netstandard2.0/Nito.Collections.Deque.dll": {
"assemblyVersion": "1.1.0.0",
"fileVersion": "1.1.0.0"
}
}
},
"Nito.Disposables/2.2.0": {
"dependencies": {
"System.Collections.Immutable": "1.4.0"
},
"runtime": {
"lib/netstandard2.0/Nito.Disposables.dll": {
"assemblyVersion": "2.2.0.0",
"fileVersion": "2.2.0.0"
}
}
},
"PowerShellStandard.Library/5.1.0": {
"runtime": {
"lib/netstandard2.0/System.Management.Automation.dll": {
"assemblyVersion": "3.0.0.0",
"fileVersion": "5.1.0.0"
}
}
},
"System.Collections.Immutable/1.4.0": {
"runtime": {
"lib/netstandard2.0/System.Collections.Immutable.dll": {
"assemblyVersion": "1.2.2.0",
"fileVersion": "4.6.25519.3"
}
}
},
"PolygonIo.Api/1.0.0": {
"dependencies": {
"Flurl": "3.0.1",
"Newtonsoft.Json": "12.0.3"
},
"runtime": {
"PolygonIo.Api.dll": {}
}
}
}
},
"libraries": {
"PolygonIo.PowerShell/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Flurl/3.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-i7CuPSikVroBaWG8sPvO707Ex9C6BP5+r4JufKNU1FGMmiFgLJvNo1ttUg6ZiXIzUNknvIb1VUTIO9iEDucibg==",
"path": "flurl/3.0.1",
"hashPath": "flurl.3.0.1.nupkg.sha512"
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
"path": "microsoft.netcore.platforms/1.1.0",
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
},
"NETStandard.Library/2.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
"path": "netstandard.library/2.0.3",
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
},
"Newtonsoft.Json/12.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
"path": "newtonsoft.json/12.0.3",
"hashPath": "newtonsoft.json.12.0.3.nupkg.sha512"
},
"Nito.AsyncEx/5.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-KOahZdW0fRLnoym5lGtyWpFUZ94I5s0wLgYF5RHhK8RUhXpCiEX+185qjNvkse3H9WJV2/pFfPlKZHv8Eej7Hw==",
"path": "nito.asyncex/5.1.0",
"hashPath": "nito.asyncex.5.1.0.nupkg.sha512"
},
"Nito.AsyncEx.Context/5.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-EE7M37c5E/kvulzEkpUR6v1AnK34b2wysOLJHSjl78p/3hL7grte0XCPRqCfLZDwq98AD9GHMTCRfZy7TEeHhw==",
"path": "nito.asyncex.context/5.1.0",
"hashPath": "nito.asyncex.context.5.1.0.nupkg.sha512"
},
"Nito.AsyncEx.Coordination/5.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Nv+oA+cSxidjOImiKcz2FJgMIDxiK0A6xormKmsUklUBjTNqQpjtdJsACMgTQG56PkTHdbMi5QijPTTUsmcCeg==",
"path": "nito.asyncex.coordination/5.1.0",
"hashPath": "nito.asyncex.coordination.5.1.0.nupkg.sha512"
},
"Nito.AsyncEx.Interop.WaitHandles/5.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-wFm3lrXXNPBtZHjLI21xhcADoh5CzO5KKNO38ybLO/CcL9zMUWWfsNiAFbw8JGp/wHoxhfdEUlThBnY3XaLR/w==",
"path": "nito.asyncex.interop.waithandles/5.1.0",
"hashPath": "nito.asyncex.interop.waithandles.5.1.0.nupkg.sha512"
},
"Nito.AsyncEx.Oop/5.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-J5DVgQrmE9qMNhK2eEMsuEw7V7cw7MIPrv3jqqQWolzDXkOxJFFYKUK+4dnC6UAEmum3xRVD2oBAoXg0vdYDDQ==",
"path": "nito.asyncex.oop/5.1.0",
"hashPath": "nito.asyncex.oop.5.1.0.nupkg.sha512"
},
"Nito.AsyncEx.Tasks/5.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-tU3Ib4zs8ivM+uS8n7F7ReWZlA3mODyLqwPE+v+WJI94hZ8xLXl+a9npfj/IcmeXo9a6fGKLWkswKQHOeTWqwA==",
"path": "nito.asyncex.tasks/5.1.0",
"hashPath": "nito.asyncex.tasks.5.1.0.nupkg.sha512"
},
"Nito.Cancellation/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-BSezc6jsEEAoa8UtVjQ6Qr/D5xX+FozlDKFHAvDeTv24I7ZZmmfbFxEmdjaSLnrboz1WMRjUKCQwZw7Gf4+WcA==",
"path": "nito.cancellation/1.1.0",
"hashPath": "nito.cancellation.1.1.0.nupkg.sha512"
},
"Nito.Collections.Deque/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-RXHe531Oaw2IathDr0Q2kbid0iuudBxtgZsfBZ2eUPuFI8I1P7HMiuUeaIefqYykcDYFTDQsFAPAljduIjihLA==",
"path": "nito.collections.deque/1.1.0",
"hashPath": "nito.collections.deque.1.1.0.nupkg.sha512"
},
"Nito.Disposables/2.2.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-QcL+uBwUCEoK8GKp/WzjdCiG8/3G1WLlVNJgLJUNG7bIIVAcEV+Mro4s53VT4Nd8xMSplv0gy+Priw44vRvLaA==",
"path": "nito.disposables/2.2.0",
"hashPath": "nito.disposables.2.2.0.nupkg.sha512"
},
"PowerShellStandard.Library/5.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-iYaRvQsM1fow9h3uEmio+2m2VXfulgI16AYHaTZ8Sf7erGe27Qc8w/h6QL5UPuwv1aXR40QfzMEwcCeiYJp2cw==",
"path": "powershellstandard.library/5.1.0",
"hashPath": "powershellstandard.library.5.1.0.nupkg.sha512"
},
"System.Collections.Immutable/1.4.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-71hw5RUJRu5+q/geUY69gpXD8Upd12cH+F3MwpXV2zle7Bqqkrmc1JblOTuvUcgmdnUtQvBlV5e1d6RH+H2lvA==",
"path": "system.collections.immutable/1.4.0",
"hashPath": "system.collections.immutable.1.4.0.nupkg.sha512"
},
"PolygonIo.Api/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}