NuGet Package Reference While Debugging Add-In

NuGet Package Reference While Debugging Add-In

richard.joseph.pollak
Advocate Advocate
1,656 Views
2 Replies
Message 1 of 3

NuGet Package Reference While Debugging Add-In

richard.joseph.pollak
Advocate
Advocate

SETUP:

 

I am using Visual Studio 2017 to create an add-in for Inventor with C#.

 

For debugging purposes, my project is set to start Inventor.exe as an external program.

 

Inside my Build Events property, I have the following post-build event command line:

 

call "%VS140COMNTOOLS%vsvars32"
     mt.exe -manifest "$(ProjectDir)ProjectName.X.manifest" -outputresource:"$(TargetPath)";#2
          XCopy "$(TargetPath)" "%AppData%\Autodesk\ApplicationPlugins\$(TargetName)\" /Y /R
          XCopy "$(ProjectDir)Autodesk.ProjectName.Inventor.addin" "%AppData%\Autodesk\ApplicationPlugins\$(TargetName)\" /Y /R

I found this code in a forum and admittedly do not have my head wrapped around how it works, but so far it has been successfully copying my project's *.dll and *.addin files to the appropriate addin folder for Inventor to run my add-in while debugging.

 

PROBLEM:

 

My project interacts with a web api that I have built in a separate project. Things were going smoothly until I attempted to deserialize a json object using Newtonsoft.Json. I added a reference to Newtonsoft.Json using the NuGet Package Manager.

 

The project builds successfully without errors; however, when I run the debugger, I get the following error:

 

FileNotFound.JPG

System.IO.FileNotFoundException: 'Could not load file or assembly
'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The
system cannot find the file specified.'

I have tried the suggested fixes for this problem that I find online. However, none of them work.

I suspect the issue has to do with the location of Newtonsoft.Json.dll being different than the relative path for which my copied project *.dll or *.addin is looking. This would explain why my project builds successfully only to fail at run-time.

 

Is there something different I should be doing with my post-build event? Is there some other change I could make to my project to keep NuGet packages references working? Am I way off base on what my problem even is? I am clueless on this problem, and it is preventing me from completing my project. If anybody has insight, I would be extremely grateful.

0 Likes
Accepted solutions (1)
1,657 Views
2 Replies
Replies (2)
Message 2 of 3

richard.joseph.pollak
Advocate
Advocate
Accepted solution

Took an awful lot of head-scratching because this problem involves uncharted territory for me, but I got an opportunity to learn about msbuild while solving this.

 

Looks like in order to copy all the related *.dll files needed for my solution, I needed to change

XCopy "$(TargetPath)" "%AppData%\Autodesk\ApplicationPlugins\$(TargetName)\" /Y /R

to

XCopy "$(TargetDir)" "%AppData%\Autodesk\ApplicationPlugins\$(TargetName)\" /Y /R

So that the contents of the entire directory of my project's *.dll would be copied rather than only the individual *.dll file.

 

Turns out my hypothesis for the cause of the problem was correct, and the solution was to simply change 'TargetPath' to 'TargetDir'. Such a simple problem to have spent a day and a half solving. Oh well! haha

Message 3 of 3

Edoardo.Baima
Enthusiast
Enthusiast
Thank you so much.
“Raise your words, not voice. It is rain that grows flowers, not thunder.”
― Rumi
0 Likes