Using Referencing Packages feature

Hi all,

we’ve updated Octopus to version 2018.9.16 and we’d like to leverage Referencing Packages feature to use Newtonsoft.Json library.

In short, we’ve got a deploy step written in C#, this step has a referenced package from Nuget feed (uploaded secure Octopus way), Newtonsoft.Json library. Inside the C# script we’ve tried to use r# Newtonsoft.Json and using Newtonsoft.Json;, in both cases the step fails.

With using Newtonsoft.Json;, it throws error:
[CompilationErrorException] error CS0246: The type or namespace name ‘Newtonsoft’ could not be found (are you missing a using directive or an assembly reference?)

With #r Newtonsoft.Jsonthe error we receive is:
[FileNotFoundException] Assembly not found.

However, the #r "./Newtonsoft.Json/lib/net45/Newtonsoft.Json.dll" way seems to have worked for us, but is it an expected correct way to do this? Or are we missing something?

Thanks in advance.

1 Like

Hi Arsney,

Thank you for reaching out. Yes, what you are seeing is expected. A NuGet package pulled from NuGet.org is nothing more than a glorified .zip file.
And just like a zip file, each package can have its own folder structure. All Octopus will do is download and extract the package for you into a folder.

You will still need to find the right .dll to load into your PowerShell script. What you saw is a result of the NewtonSoft’s folder structure.

Here is the root folder:
eee8ac36fbadcb7d02ba4ffee083e1c8.png

When I go into lib I see all those additional folders

ba3f65e5c7596ca81d6faa84be57effa.png

And finally
fd9ed8d4752012a8d32c166f9d6d5b99.png

This particular package targets multiple .NET frameworks which is why you are seeing this.

Best regards,

Thank s a lot Bob, all clear to us now.

Best wishes!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.