How to include a Nuget package in a Visual Studio Extension (vsix)
Asked Answered
E

2

6

I have created a Visual Studio Extension (VSIX) that makes changes to our Application's code using Roslyn.

The VSIX solution includes the NUGET package Microsoft.CodeAnalysis.Analyzers. As an aside, it is described as version 1.3.2, but the underlying DLLs (e.g. "Microsoft.CodeAnalysis.CSharp.dll") all report to be 1.3.2.

Anyhow, I put this on our local private Gallery. From there, I can add it to Visual Studio (VS2015 Update 3) and it executes as expected.

However, after my colleagues add it to their Visual Studio (VS2015 Update 3) and attempt to execute it, they receive the following message:


Microsoft Visual Studio

Could not load file or assembly 'Microsoft.VisualStudio.LanguageServices, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

OK

When I look in the VSIX archive, I do see many DLLs, but these are "my DLL" and all those with the prefix "System.". I'm not seeing any with the prefix "Microsoft.". I did try manually copying every DLL that I have in my BIN folder to the VSIX to see if it would make any difference, but with no success.

All DLL referenced appear to have "copy local" on them, so they're in my BIN, but they're just not accessible on the end users' machines.

I see the manifest can include both "Assets" and "Dependencies", but it's not immediately clear if these can be used for NUGET packages.

What am I missing?

Edelsten answered 10/11, 2016 at 16:42 Comment(0)
E
3

Eventually found the answer:

VSIX with Project Templates and NuGet Packages

  • See the answer from Min (Aug 28 '13) regarding his YouTube video
  • And take note of KyleMit's comment regarding where in the rather lengthy video this appears.

The fix is rather lengthy, so best presented in his video.

Edelsten answered 11/11, 2016 at 18:54 Comment(1)
It looks like the point of this video is to add NuGet packages to a VS project template, such that when the user makes a project via the template, the new project has references to NuGet packages. Your question doesn't mention templates. But all I want to do is to make my vsix include the DLLs it uses from NuGet. My extension uses Microsoft.CodeAnalysis.CSharp.Scripting from NuGet which depends on many other packages... when I install my vsix, Microsoft.CodeAnalysis.CSharp.Scripting.dll and SOME of its dependencies are installed, but others like Microsoft.CodeAnalysis.CSharp.dll are missing.Melise
M
0

I received the same exception using roslyn for a custom command and as described above the Microsoft.CodeAnalysis DLLs were not included while other referenced DLLs or NuGet packages were added. However, once I downgraded the Dependencies in NuGet to the version used by Visual Studio which can usually be found in C:\Program Files (x86)\Microsoft Visual Studio [Version Number, e.g. '14.0']\Common7\IDE\PrivateAssemblies the exception did no longer occur, as it just used the available dlls.

Monge answered 16/8, 2017 at 5:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.