'How do I automatically install a nuget package from a roslyn code fixer

I try to add a nuget package reference automatically to a visual studio project if needed, with the help of a roslyn code fixer.

Since the "CodeFixProvider" is not a "Microsoft.VisualStudio.Shell.Package" there is no GetGlobalService Method to retreive a "IComponentModel" in order to get the "IVsPackageInstaller2" service.

Is there another or an even better way to add a nuget reference to a project? I am a bit lost here after days of googling.

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source