2

I am writing a VS Extension which needs to add a NuGet package to a project. I am using the interfaces suggested here, in particular the IVsPackageInstaller.InstallPackage(string, Project, string, string, bool) method. The package gets installed just fine and the packages.config is changed to contain the relevant version - however the binding redirects that are usually generated when installing a NuGet package aren't being created.

Is there a 'correct' way to do this (i.e. calling a publically accessible API) or just the 'roll your own' kind of way where the app.config is modified effectively as if it was XML?

Karthick Raju
  • 757
  • 8
  • 29
Matt Whitfield
  • 6,436
  • 3
  • 29
  • 44

1 Answers1

0

Binding redirects is working at project level, we often bind redirects in project file or .config file, which are all working for project.

And in NuGet API, it doesn't provide such methods to modify project file and project config file. It only change the packages.config file, which only works for NuGet packages.

There are two ways to implement bind redirects. One is modify the app.config as you mentioned. And another way is bind redirects in code. You could reference below code.

SideBySide Error with Binding Redirect in .net Windows Service

Weiwei
  • 3,674
  • 1
  • 10
  • 13
  • This is slightly misleading - the NuGet API changes the packages.config - but also adds the references to the project. And I understand how it works - but this is a VS extension - so for me to redirect binds in code using the AssemblyResolve handler, I would have to generate some code and add it to the project that was being built - which is probably less simple than simply modifying the app.config. – Matt Whitfield Sep 21 '17 at 12:49
  • The Nuget API just provide the Install, remove packages in project. And the install/remove process will add/remove reference into project which cause the project file changed. But it only reference the corresponding assembly. It doesn't redirects it when there has different versions. – Weiwei Sep 26 '17 at 06:51