Adding MOQ to a .NET 4.0 project is not possible - visual-studio-2010

I want to add MOQ .net library to a .NET 4.0 project. I get an error message that I should convert the project to something smaller than 4.0. I need to use .NET 4.0 also because of other project dependencies.
How can I make MOQ work with a .NET 4.0 project in VS2010 ?

Make sure you have NuGet package manager installed (Tools/Extension Manager).
Right click on Solution Explorer/References, choose Manage NuGet Packages.
Type Moq in the search box.
Install and enjoy.

The latest version from Google Code (http://code.google.com/p/moq/), works in a .Net 4.0 project. I would just download the dll again.
Here is the download link: http://code.google.com/p/moq/downloads/detail?name=Moq.4.0.10827.Final.zip
The zip file at that location contains a .Net 4 folder. Use the dll : Moq.dll from the NET40 folder and everthing will work fine. Just do a normal Add Reference on the project.
I would check the version number and the Runtime veseion of the assembly you are trying to use. It should say:
Runtime Version: v4.0.20926
Version: 4.0.10827.0

For the sake of completeness, it may be worth pointing out that it is also possible to use the Visual Studio command line package manager tool:
1) Open the console in VS
View >> Other Windows >> Package Manager Console
2) Install Moq
Type Install-Package Moq at the prompt
Note: If your tests are in a separate project, make sure that you select that project in the project dropdown.
This will install the latest package available in NuGet, which should address your compatibility issue. See http://nuget.org/packages/moq.

Watch out that you're using .NET 4, rather than the .NET 4 Client Profile as your Target Framework. I had the same issue and that was the cause for me.

Related

Nuget-package not adding package reference

I am trying to install MySql.Data and MySql.Data.Entity to my class lib.
Somehow there is no reference added to the project.
Things I've tried:
Update-Package -reinstall (does not help)
packages.config contains the correct entries
*.csproj also has the correct entries
Cleared NuGet-Cache
This is the output:
Package 'MySql.Data.6.10.6' already exists in folder
'C:\Users\MYUSERNAME\Documents\Repositories\XXXXXXX\packages'
Added package 'MySql.Data.6.10.6' to 'packages.config'
Successfully installed 'MySql.Data 6.10.6' to XXXXXXXX.Persistence
Executing nuget actions took 1,6 sec
Strange thing is that NuGet creates that \docs in my project which is part of MySql
Nuget-package not adding package reference
I agree with Matt`s comment. You project targets framework should be .NET 4.5.1 or below. Because the package MySql.Data only contain assembly reference to .NET framework 4.5.2 for .NET framework:
However, this package also have the content files, which are compatible with .net framework. So when you add this package to the project(target framework 4.5.1 or below), nuget will install this nuget package without any error, just add the content file (\docs) but not add any reference to the project.
To resolve this issue, you can change the target framework to 4.5.2 and above of this project or you should use the nuget package MySql.Data with the version 6.9.11, which contain assembly reference to .NET framework 4.0 and 4.5:
Note: If you change the target framework to the .net framework 4.5.2 and above, you may get the error "The package 'MySql.Data' tried to add a framework reference to 'System.ComponentModel' which was not found in the GAC.", please add a manually reference to missed library:
Package tried to add reference to System.Runtime which was not found in the GAC
Hope this helps.
I experienced this problem even though I had the correct Framework.
It was solved by Migrating the Nuget Format to Package References
For visual studio latest versions you have to right click on Dependencies > Manage NuGet Packages > click in the settings button with a flower-like shape, then in NuGet Package Manager option choose General, and change Default package management format from packages.config to PackageReference.
If that does not do the trick, then you will have to add the packages through the CLI tools, looking into the nuget gallery and pasting the comand directly with the desired version, like for example:
dotnet add package Microsoft.EntityFrameworkCore.Design --version 6.0.10

Visual Studio for Mac does not get past "Add packages"

I am trying out Xamarin Forms on Visual Studio for Mac.
When I create a new project, I see VS is trying to add packages to the solution, but every single time- it fails at the same place...
Here is the Package Console output:
https://drive.google.com/open?id=1-KfdWC2hub4YuEOHfJ_LICL86o6zkecytmMAi0emDeQ
On this new project, after the package installer fails, it always fails to build with the default assets:
Is it possible other dev environments are affecting Visual Studio?
Is there a more stable way I can use Xamarin forms on a Mac?
Thanks in advance!
One of the errors I see in your Package Console is:
Could not install package 'Xamarin.Android.Support.v4 23.3.0'. You are
trying to install this package into a project that targets
'MonoAndroid,Version=v2.3', but the package does not contain any
assembly references or content files that are compatible with that
framework.
NuGet looks at your project's target framework and version to see if the NuGet packages are compatible. As far as NuGet is aware your project is targeting MonoAndroid version 2.3. Check what you have selected as the Compile using Android version in the project properties and ensure that it's compatible with the package you want to add.
Also, a "more stable" way to use Xamarin Forms on a Mac is not available unless you want to try Xamarin Studio but that is almost the same as Visual Studio for Mac (which is based on it).

How use Roslyn Scripting in OSX with F#?

I'm getting confusing with the pletora of assemblies that I get from nuget related to Roslyn. I have last version of xamarin with .NET 4.5 profile. I wish to use the scripting part of Roslyn. But don't found how setup the project.
What si the package from nuget I need to download? Is my impression, but the names of the namespaces have changed? Because the tutorial I have found using C# not match what I have get from nuget
With the last version of Visual Studio for Mac, I can finally create .NET Standard Library and reference the Microsoft.CodeAnalysis NUGET packages.

GoCardless SDK "requires a later version of the .NET Framework than the one specified in the project" (ASP.NET 3.5, Visual Studio 2010)

UPDATE 201521011559: I'm wondering if this is caused by an error in the dependency specifications in the .nuspec file used to build the package...
The .nuspec file for the client SDK is on GoCardless' GitHub repo
https://github.com/gocardless/gocardless-dotnet/blob/master/GoCardlessSdk/GoCardlessSdk.nuspec
and includes this section:
<dependencies>
<group targetFramework="net20">
<dependency id="Newtonsoft.Json" version="4.5.11"/>
<dependency id="RestSharp.Net2" version="1.1.11"/>
</group>
<!-- For reasons unknown, NuGet pack will not recognise targetFramework and tries to put all our deps into the default group.-->
<!--
<group targetFramework="net35">
<dependency id="Newtonsoft.Json" version="5.0.2"/>
<dependency id="RestSharp" version="104.1"/>
</group>
-->
</dependencies>
Am I right in thinking that means it's going to try and install RestSharp.Net2, regardless of the target framework version of the target project?
ORIGINAL QUESTION:
One of our projects is an ASP.NET web application - target framework set to .NET 3.5, no client profile or anything.
I've just installed the NuGet package containing the GoCardless .NET SDK (http://www.nuget.org/packages/GoCardless/)
PM> Install-Package GoCardless
It appears to work fine. Then I add a reference to GoCardless.Sdk to one of my pages, and the project refuses to compile:
The type or namespace name 'GoCardlessSdk' could not be found (are you missing a using directive or an assembly reference?)
What's really odd is that if I remove the reference, then right-click References, Add Reference, browse to the ..\packages\GoCardless\lib\net35\ folder and select GoCardlessSdk.dll, I get this error:
'GoCardlessSdk.dll', or one of its dependencies, requires a later version of the .NET Framework than the one specified in the project. You can change the .NET Framework target by clicking Properties on the Project menu and then selecting a new target in the '.NET Framework' dropdown box.
Do you still want to add a reference to 'GoCardlessSdk.dll' in the project?
I've checked the package using NuGet Package Explorer. It definitely exposes both a .NET 2.0 and a .NET 3.5 version; the only dependencies are Newtonsoft.Json and RestSharp, both of which run just fine on .NET 3.5.
I'm using Visual Studio 2010 Premium on Windows 7 x64. Is this a Visual Studio problem, a .NET problem or something specifically wrong with the GoCardless SDK NuGet package?
I've fixed this in the past by uninstalling Microsoft Blend. It gets installed along with Visual Studio 2012, and it also installs its own version of Newtonsoft.Json.dll. It does something weird with the DLL (maybe it installs the DLL in the GAC?) that causes Visual Studio to reference the Blend version of the DLL, rather than whatever other DLL it should be referencing.
There's possibly a friendlier solution than uninstalling Microsoft Blend, but if you don't use Blend then that's the easiest option!
What I would suggest you is re-arrange your whole solution:
First of all remove: - GoCardless Client Libraries 1.1.15 (Or 1.1.16)
again if you have installed it now:
Than try to compile your solution again and if everything runs normal you should get the error that you can not find a file from the reference .dll right?
Than you need to make sure that for:
.NETFramework 3.5
Newtonsoft.Json (≥ 5.0.2) || RestSharp (≥ 104.1)
and for
Or for .NETFramework 2.0
Newtonsoft.Json (≥ 4.5.11) || RestSharp.Net2 (≥ 1.1.11)
are matching exaclty the version they are here. (Newest update from GoCardless)
If you have checked that with the nuget controller:
Updating a Package(click to visit page)
From the Tools menu, select Library Package Manager and then click
Package Manager Console. To check if there are newer versions
available for any installed packages, enter Get-Package -updates at
the prompt.
Get-Package command
To update a package, enter Update-Package with the package ID. For
example, enter the command Update-Package jQuery. For more options
that you can use with the Update-Package command, enter get-help
Update-Package or see (../Reference/Package-manager-Console-Commands).
If those updates / maybe downgrades are done you can want to change the .Net Framework of you Application by doing following:
In Solution Explorer, open the shortcut menu for the project that you want to change, and then choose Properties.
In the left column of the properties window, choose the Application tab. Visual Studio App Properties Application tab
(After you create a Windows Store app in Visual Studio 2013, you can't
change the targeted version of either Windows or the .NET Framework.)
In the Target Framework list, choose the version that you want.
In the verification dialog box that appears, choose the Yes button.
The project unloads. When it reloads, it targets the .NET Framework
version that you just chose.
Than if you have changed it to the .Net FrameWork 3.5 (Id suggest you take that regarding your imports) you can re-import the GoCardless.dll and tell me what happens. In my opinion it should be able to add the reference and start working with it.
That package is no longer supported and has been unlisted by it's owner.
I've create a new one here:
https://github.com/getAddress/goCardless
(or PM> Install-Package getAddress.goCardless)

Is TPL DataFlow included with either .NET 4.5 or .NET 4.5.1?

I'm confused. We upgraded our project recently to .NET 4.5.1. We installed .NET 4.5.1 on our servers.
I'm referencing assembly System.Threading.Tasks.Dataflow from the GAC at C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Threading.Tasks.Dataflow\v4.0_4.5.9.0__b03f5f7f11d50a3a\System.Threading.Tasks.Dataflow.dll
CopyLocal is set to false as (I assume) it's part of the Framework, so should be already installed wherever the app is deployed.
The trouble is, when running on the server, it says it can't find this assembly.
I've read here that is is part of .NET Framework 4.5:
but the library is now built-in with .NET 4.5.
...and I've read here that it isn't!
The TPL Dataflow Library (System.Threading.Tasks.Dataflow namespace) is not distributed with the .NET Framework 4.5
What gives? It doesn't look like it is. Is it just part of the 'targetting pack'? Is it me, or are these in-place upgrades more agro than they're worth?!
I'm not sure why that page says it is part of .NET 4.5 -- it's still an out-of-band NuGet release, like Entity Framework, MVC, etc.
I recognize this question is pretty old, but I wanted to add my solution as well. I found adding the below two items to the Visual Studio 2019 install (run Visual Studio Installer > Modify > .Net Desktop Development) the problem went away and it was able to pull System.Threading.Tasks.Dataflow from the GAC.
Edit: Installing Visual Studio 2015 also seemed to be required. Obviously it isn't VS 2015 itself, just something it comes with. But there are too many packages for me to figure out which one easily.
Edit2: This isn't really the best solution, more of a stopgap. MS suggests downloading it through Nuget. https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.dataflow?view=netcore-3.1
The TPL Dataflow Library (the System.Threading.Tasks.Dataflow namespace) is not distributed with .NET. To install the System.Threading.Tasks.Dataflow namespace in Visual Studio, open your project, choose Manage NuGet Packages from the Project menu...

Resources