I plan on using Moq to mock some interfaces in the unit test code I've created. I've already downloaded the latest version of Moq.
My question is how do I install it? Where should I place the Moq.dll?
I've tried searching on the internet, but all I can find are samples of how to use Moq, not how to install it.
The best way to add reference to Moq framework is installing it from Nuget. Also you still can download Moq.dll and add reference to this library (usually I create folder libs under the solution folder, where I put all third-party libraries, which is not available via Nuget).
BTW Another option to install package from Nuget - right click on project references and select Manage Nuget packages.... Then search online for Moq and install it. See why use Nuget over installing libraries directly on my machine
There's no need to install it. Just add a reference to the moq.dll in your project.
But of course you can use gacutil to register the library in your global assembly cache.
c:\path> gacutil /i Moq.dll
When using Visual Studio:
Right click on References [It's in the project Explorer]
Manage NuGet Packages
Search for Moq and add it to your solution.
This is an old question, but the convenient method I used is not listed here and this is the first result on google. I am using VS 2013 and if I search for Moq in Extensions and Updates there are no results so:
Go to Package Manager Console - (Tools -> Library Package Manager)
Change the default project to your test project
Then type: install-package moq
For .NET Core, using the dotnet CLI - dotnet add package Moq
You don't need to install it.
You could use NuGet of course (if you use newer versions of VS), but you can just copy it to your project folder (or preferably something like lib subdirectory of your project folder) and just add a reference to it.
EDIT:
You seem to have problem with wrong version. In your downloaded moq zip archive, there are multiple folders. You need to use one from folder Net35, not one from Net40. These numbers refer to the version of target .NET framework, not version of Moq itself.
When using Visual Studio
Right-click the test project in Solution Explorer
Manage NuGet packages...
Change Package source to All
Browse for Moq
Install
If you are on newer version of Visual Studio (2013+), you can use Package Manager Console.
Tools > Nuget Package Explorer > Package Manager Console
Execute:
Install-Package Moq -Version 4.5.16
Also see:
https://www.nuget.org/packages/Moq/
Related
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.
I'm using Visual Studio(VS) 2010 Ultimate (with .NET 4.0) to install Json.NET (10.0.2) but get failed with error message:
'Newtonsoft.Json' already has a dependency defined for
'Microsoft.CSharp'
I've tried to search solution for this and tried many ways like: update NuGet Package. but unfortunately, it didn't work.
What is to be done?
More tried update:
The version of NuGet Package: 2.8.60318.667
Install Json.net version: 9.0.1 without problem
I tried this solution and it worked for me:
Tool -> NuGet Packages Manager - Manage Nuget Package for Solution
Select Online tab and search online for Nuget.CommandLine -> install it
After installing, you can find nuget.exe in your Current Project folder -> Packages -> NuGet.CommandlineXXX
Run CMD and use command install to install latest version of Json.NET
Back to Project -> add reference - Browse for DLL file
Done!
Please check the version of .NET Framework you are using. There are chances that previous frameworks such as v3.5 or below doesn't support latest version of JSON.
Or this would help you : NuGet: 'X' already has a dependency defined for 'Y'
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.
Please help me understand: I have a Visual Studio project. It has Nuget package manager enabled. I install several libraries. The library versions are shown in packages.config. Each library has a corresponding entry in References.
Now, say I want to change the library version from, say, 2.2.0 to 2.1.0. How I do this? At first I assumed you could just change the version number in packages.config. But when I do this, and get Nuget to download an earlier version of the library, the project references are not changed.
Do I have to manually remove each and every reference in the project to 2.2.0 and replace it with 2.1.0?
I get the feeling I'm "doing it wrong", but there doesn't seem to be any examples I can find of anyone doing it right.
Thanks for any help!
Using jQuery as an example:
If you want to rollback to a previous version you can run the Uninstall-Package jQuery and Install-Package jQuery -Version 2.1.0 commands from the package manager console.
Also, the package nuget page will have a list off all the versions available. EX: jQuery
All of this and more available in the nuget Docs
You can't simply change the version in the config file since your project still holds a reference to the binaries, so the binaries need to be replaced too.
Now, I'm not entirely sure if there is a "downgrade" Powershell command but you can certainly uninstall the specific package and then install a lower version. By using the Package Manager Console. So from within Visual Studio:
Go to the View menu -> Other Windows -> Package Manager Console
Select the Default Project from the dropdown list
Then run the following command to uninstall the package
The command to uninstall is...
Uninstall-Package YOUR_PACKAGE_NAME
To install a lower version, run this command...
Install-Package YOUR_PACKAGE_NAME -Version 1.0
These and other commands are very well documented in The Package Manager Console Powershell Reference
Uninstall-Package Command
Install-Package Command
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.