Adding a NuGet package to a project without Visual Studio - c#

I'm trying to automate adding NuGet packages to project on a remote server that doesn't have Visual Studio (nor any build servers) installed. I do know how to use NuGet.exe from my C# code, but this executable only downloads packages and doesn't do any other required work (adding references, executing ps scripts etc). What do I do in order to fully install a package?
Note: I don't need to update a package for my own app, I need to add a package to an arbitrary .csproj file on the server. I'm building a Web-based .Net IDE, and need my users to be able to add packages to their projects.
I see two possibilities: one is using some kind of functionality not present in NuGet.exe, but ratherin some other library (maybe a VS addin), but I don't know where to look for it. The other is to simulate some kind of NuGet Powershell console and send commands to it, but again, I don't know how to do that.

You might want to consider SharpDevelop.
Installing NuGet Packages outside of Visual Studio an article about the functionality you are trying to achieve (written by Matt Ward, one of the project contributors) says:
Since NuGet uses PowerShell the simplest approach was to extend the
existing PowerShell cmdlets included with SharpDevelop. Now you can
write a few lines of PowerShell script to install a NuGet package into
a project that has never had a NuGet package before, have the project
itself updated and any package PowerShell scripts run. All this from
the command line without Visual Studio open.

Just to add an additional answer in-line with Alex's post about SharpDevelop, you have a couple different options.
Use Nuget.exe (Related Blog post)
NuGet Addin for MonoDevelop and Xamarin Studio (see GitHub)
ASP.NET Pages using WebMatrix (see this video)
All of this info is from the Nuget FAQ.

Related

How to achieve full NuGet reinstall for dozens of solutions?

We have dozens of solutions in a repository and we're retargeting every project to net472 from net462. Currently our best bet is to open each and every solution in Visual Studio and execute the following command in the Package Manager Console.
Update-Package -Reinstall -IgnoreDependencies
As far as I'm aware, the PM console cannot be used outside Visual Studio, so this method of course is not very efficient, so what I was thinking about is using the nuget.exe tool for this. However at first glance I could not find any equivalent operation or argument set.
The documentation at this moment says the following
For all packages, delete the package folder, then run nuget install.
For a single package, delete the package folder and use nuget install
to reinstall the same one.
So based on this I tried to delete the packages folder and run nuget install for a project, so I expected it to do a re-install. However, while it installed the package indeed (to packages), it does not touch the packages.config (for retargeting).
Is anyone aware of any kind of possible way to automate this process?
How to achieve full NuGet reinstall using nuget.exe CLI?
That command cannot get what you want.
As far as I know, nuget install should be with packages.config file and it will not update the nuget framework version of packages.config file automatically.
So whenever you change the target framework version of your project, using that command will not update the target framework version of the nuget package.
So only update-package -reinstall command under Package Manager Console will update the target framework version of packages.config file.
And also Package Manager Console cannot access multiple solutions so you have to open each solution to run that command.
Although it may be possible to achieve your expectations with PowerShell scripts, but it is too complex so that it is easier to open each solution and then run the command.
As a suggestion,
1) open each solution on VS to run update-package -reinstall command.
2) And migrating from packages.config to PackageReference may be a good choice. In this case, the nuget packages will automatically adapt to the corresponding project target framework version.
Before doing this,you can make a backup of your project.
3) If these all do not meet your requirements, you could suggest a feature on our User Voice Forum to report your desire for automation. After that, you can share the link here and anyone who is interested in it will vote it so that it will get more attention from Microsoft.

Install a Nuget package in Visual Studio Code for Unity

I want to save my level files to .json files in the Unity assets folder. Due to the limited features of JsonUtility I want to use Json.NET. I use Linux so I can't access Visual Studio and use Visual Studio Code instead. I wanted to add the package to my Unity project and took the guide from here
Install a Nuget package in Visual Studio Code
First I used this command in the terminal
dotnet add package Newtonsoft.Json
but I got this error
error: Error while adding package 'Newtonsoft.Json' to project
'/.../myUnityProject/Assembly-CSharp.csproj'. The project does not
support adding package references through the add package command.
After that I installed the Nuget extension and installed Newtonsoft.Json#12.0.2 to my project. I was prompted to run dotnet restore to be able to use the package.
After doing so I got this error
MSBUILD : error MSB1011: Specify which project or solution file to use
because this folder contains more than one project or solution file.
So what is the correct way to install third party tools using Visual Studio Code with Unity?
Unfortunately, due to Unity3D's heavy-handed manipulation of SLN files, it is not possible to use NuGet packages within a Unity project.
In the case of Newtonsoft.Json, it is available on the Asset Store for free, you can install from there.
Other packages can be used manually by downloading the .nupkg file from the NuGet website, extracting the DLLs for .NET 4.x, and placing them in your project's Assets folder.
If the library contains native code, you might not be able to use it on every platform, however. But if you get per-platform DLLs, you can set them up in the Unity editor to only be used for the correct platforms.

Is it possible to install the MaterialDesignThemes package once and be able to reference it on each and every other wpf project?

I am new in WPF application development and I came across the Material Design package, I am using Visual Studio 2015 Enterprise.
Every time I want to create a new WPF application I always go to
Project -> Manage NuGet Packages and install the MaterialDesignThemes package for that specific project and when I am working on another project I need to do the same process again.
Is possible to only install this package once and somehow use it (or reference it) on all projects that I am creating as opposed to installing it with each and every new project I create?
I hope my question makes sense and I am asking this for the sake of being able to develop new material design WPF applications offline.
They ask to use nugget to keep the package updated that way you can check versions and so on. But you can download the source code from GitHub and keep it on your machine or server you use it for. That way you can refer it from your machine and don’t need to download for every project you work.
Project source: https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/releases
In my opinion, I highly recommend download from nugget repository because it is easy to maintain and anyone else that code and the same project will find the package over there.
Create a Project Template.
VS2015: https://msdn.microsoft.com/en-us/library/xkh1wxd8.aspx
VS2017: https://learn.microsoft.com/en-us/visualstudio/ide/how-to-create-project-templates
Another way of quickly installing nuget packages is using the Package Manager Console and use the install-package command. e.g. install-package materialdesignthemes

Entity Framework 7 in Class Library

Can I use a EF7 Code First in a Class Library to be referenced by a Console Application?
I'm preparing/creating a Database to be used in multiple projects in the future.
Now I need to play around with EF7 but not in ASP. Im ok with Console.
Now in a console application to management the first data.
Then in the Final Release of ASP.NET Core 1.
Thanks.
EF/NuGet
Assuming you are using Visual Studio, you would use the built in NuGet functionality to download and install the package. Here is a detailed tutorial.
The easiest thing to do from that link is to open the Package Manager Console window and type the following: Install-Package EntityFramework. This will install the latest version which happens to currently be 6.1.3.
EF Without NuGet
If you don't use Visual Studio or you cannot use NuGet for whatever reason, you can manually download the package from the EF NuGet Site and rename it from a .nupkg extension to a .zip extension and extract the DLL from the lib folder.
EF7
Now your question specifically mentions EF7 which is can be installed using NuGet with the following command: Install-Package EntityFramework.Commands -Pre in the Package Manager Console.
If you don't have NuGet, you can follow the steps above or download the source from GitHub and build the DLL yourself. Having said that, it is a RC so use at your own risk.

How to use NuGet?

I have installed NuGet, how to use it?
I saw the video and i tried
>Add-Package log4j
Command "Add" is not valid.
>
it does not work, I entered that in Command Window.
EDIT:
I uses VS2010 and I build WindowsForm App and not ASP.NET.
You've got two options;
You can either use the GUI; right click on project references > Add Library Package Reference...
Or you can use the console, which has more features, but I'd not recommend it.
You're entering this in the Command window when you should be entering it in the Package Manager Console window. Open it through 'View' / 'Other windows' / 'Package Manager Console'.
To answer your specific question besides the documentation link:
Using the Package Manager Console you can find a package by filtering it i.e.:
get-package -remote -filter Log4net
Once you find the package you want, you can add it to your project with
install-package log4net
That's all there is to it - if you don't need to use the console then for casual use the Add Library Package Reference Dialog Box (that's a handful) provides an easy to use UI to add packages.
Click on project --> Manage nuget packages.
You can see this youtube video which shows the importance of Nuget and how to use by using VS 2012
http://www.youtube.com/watch?v=AXfZsTj-7P0
If you have visual studio 2013 or above.. the solutions now come up with Nuget package manager and a packages.config file is also added to the solution. packages.config file contains information about all the packages present in the solution.
Read more > About Nuget Install/Uninstall & Downgrading

Categories