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?
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:
When I go into lib I see all those additional folders
And finally
This particular package targets multiple .NET frameworks which is why you are seeing this.