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

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!

Related

Autofac.Extensions.Hosting NuGet?

Does anyone know how to install Autofac.Extensions.Hosting from a NuGet package within Visual Studio (2019)? I see the project here GitHub Autofac.Extensions.Hosting. Within the project instructions, it states that you can "reference the from NuGet". However, I can't find it within Visual Studio's NuGet Package Manager. Is it not available yet, or am I doing something wrong.
Thanks.
It was never published because it's basically just one extension method. The readme needs to be corrected. If you need the extension method, just copy paste it.

package manager in visual studio code

I've been using visual studio code as a second display (with visual studio as the first) to view/edit code mostly JavaScript since you can right click/format the code with easy.
But I recently took to time to study how it's c#/asp.net core debug functionality has evolved and it seems it has become even more easier to start whipping debug in no time.
But there is one thing I haven't figured out and whether it's even possible. That's it managing nuget packages. Visual studio offers a nice package manager ui to view installed packages and which packages might need a version bump.
It's there an alternative for visual studio code other than browsing the nuget site and checking which of your referenced packages have updated and editing the .csproj manually or running dotnet add <project> package ...?
This is probably not relevant anymore, but for anyone else also searching for something like this, there is a pretty handy extension for VSCode called Package Manager GUI here.

Visual Studio 2017 Communnity Incorrectly Updates Roslyn Scripting

I am using Roslyn for application scripting via Nuget Package Manager. Setup should be rather simple. Create new project and, in Nuget manager, add Microsoft.CodeAnalysis.Sripting package. After couple of confirmations you are ready to go.
Next step should be checking for installed packages update. Currently, there are 5 updates that are shown after initial installation. Again, it is pretty straightforward to do this.
However, immediately after the update, two of those packages show yellow triangle in Reference node of the project.
I have tried to resolve this following SO and other hints but nothing helped me so far.
At the end, I have installed new VM with Windows 10 Pro (with all updates) and VS2017 Community Edition. After that new Windows Forms project (.net 4.6.1. based for x64) was created and scripting package is added. Unfortunately, yellow triangles are still there (after update).
Problematic packages are System.ValueTuple and System.Security.Cryptography. X509Certificates.
Also, after cleaning and rebuilding the solution, a number of warnings (MSB3836) - explicit binding redirect on "System..." conflicts with autogenerated binding redirect.
Solution to this problem might shed a light on problem with more complex solution that I stumbled upon after migration to VS 2017.
So, what is the reason for such behavior? Remember, this happens on new installation of OS and VS with simplest project possible.
Visual Studio 2017 Communnity Incorrectly Updates Roslyn Scripting
I got the same result with you steps. This issue only occurred on the Visual Studio 2017 not Visual Studio 2015. That should have some issue with package Microsoft.CodeAnalysis.
To resolve this issue, I would like provide you a workaround:
Update packages "System.ValueTuple" and "System.Security.Cryptography. X509Certificates" first, then update other packages.
It works fine on my side, you can check if it works for you.
In order to track this issue, I have create a new issue on GitHub:
https://github.com/dotnet/roslyn/issues/22290
If you have additional information to add, you can add comments below that issue. And you can check the feedback from this link.

What to do when package version cannot be found however I can see it on nuget.org?

I have a project where I need Microsoft.TeamFoundation.DistributedTask.Common.Contracts. According to nuget.org there is a 15.114.0-preview package. But, Visual Studio says that there is no package like this.
I clean all local cache and doesn't help.
How can I solve it? Generally, how much time is needed for a package to go through the spreading process if there is any?
You seem to be looking at the wrong package in Visual Studio Package manager window.
Microsoft.TeamFoundation.DistributedTask.Common.Contracts has latest version as 15.114.0-preview
while Microsoft.TeamFoundation.DistributedTask.Common has latest version as 15.112.1
Hope this helps.
-AG.

nuget - package restore not working

My aim is to have package restore working on a build server so that I don't have to check in binaries. At the moment, I'm simply trying to get it to work on my own machine using Visual Studio.
Here's what I've done so far:
Followed the instructions here http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages, including both setting the Tools-Options flag and the environment variable (belt and braces)
Installed the NuGetEnablePackageRestore package as suggested here NuGet package restore consent without NuGet
Checked everything in (the .nuget solution folder and its contents), but not the binaries I want to reference, because that's the whole point of the exercise
Here's what I'm doing:
Check out solution
Verify that nunit.framework.dll and moq.dll are not present in the checked out solution
Build the solution
Visual Studio complains that Moq is missing. I search for the dlls in the solution directory and find that:
nunit.framework.dll is present in the appropriate bin folders
Moq.dll is nowhere to be found
But there's more. This is truly mysterious, but if I do a fresh checkout, disconnect from the internet and build, I get precisely the same results - nunit.framework.dll is there, but moq.dll is not. The build process has conjured nunit.framework.dll literally from nowhere.
So it's something of an understatement to say that I am completely baffled. Can anyone suggest answers to the following questions:
Why is package restore not downloading Moq?
Where on earth is the build process getting nunit.framework.dll, if not the internet?
In vs, Options, Package Manager... there's a section "Package Cache", if you click on the "Browse" button it will take you to the location of the nuget cache in your machine.
Okay, I noticed in the documentation that enabling package restore was supposed to modify project files in order to add a new target. My project files did not have this change. Right-clicking the solution title in VS and selecting 'Manage NuGet packages...' then added the required changes and everything built as it should.
I checked, and package restore still appears to work when I have no internet access, so I'm still mystified about that. Does NuGet maintain some kind of cache of binaries outside the solution?