Portable Class Library Projects Dont Work with NuGet - c#

I have a funny error where NuGet will not work in Portable Class Library projects. I have created a portable class library project and when I attempt to search (through the NuGet dialog) or install (through the console) I get the following error:
Specified argument was out of the range of valid values. Parameter
name: supportedFrameworks
I had this error with all projects (Class, etc.) in VS2012 but I followed this advice and it has fixed it except for PCL projects. In a class project the NuGet dialog will list packages and install them just not in PCLs.
What is wrong and how can I fix this?
Note: I am creating a Xamarin Cross Platform project in VS2012 (ie the project is a PCL solution). Maybe this is the cause error - Xamarin's VS Extensions? I am also using VS2012 Professional Trial version - could this be the issue?
Edit Maybe I dont have my PCL setup? For example I dont have the folder C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile.

As far as I know Visual Studio 2012 does not include any Portable Class Libraries. They are installed with Visual Studio 2013. Otherwise you will have to install them yourself which involves several steps.
Install the Portable Library Tools and the Portable Library Reference Assemblies 4.6.
Extract the PCLs from the .zip file that the Portable Library Reference Assemblies 4.6 installs into C:\Program Files (x86)\Microsoft .NET Portable Library Reference Assemblies 4.6.
Copy the PCLs extracted into C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable.
Repair the Xamarin install so it adds its PCL profile xml files to the new PCL directories.

Related

Cannot find Math.net in References after installing package with NuGet in Visual Studio 2015

I'm trying to use the Math.net extension for Visual Studio 2015 with C#.
Unfortunately, after installing the package with
PM> Install-Package MathNet.Numerics -Version 3.20.0
I cannot find it anywhere in the Add References menu. I searched Assemblies->Framework and Assemblies->Extensions and COM, but it's not there
I wouldn't mind the just adding the DLL to my project, but I cannot find the DLL anywhere on https://numerics.mathdotnet.com , all the links take me to the NuGet package manager.
Also, do I need to distribute the MathNet dll with my application if I add it through the package manager, or does it build internally with the application?
Sorry, new to .net library management
I see that when I ran the command line, it added a packages folder to my project folder. Which has a few different versions of the library per .net version. Which I could browse to with Add Reference->Browse->Browse
Is this the correct way about adding a third party library?

Added reference not detected in visual studio

When trying to install the netmq vis nuget, I get the following error:
Could not install package 'AsyncIO 0.1.18'. You are trying to install this package
into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111',
but the package does not contain any assembly references or content files that
are compatible with that framework. For more information, contact the package author.
The problem is that netmq depends on AsyncIO. when installing it, nuget find that the assembly is not compatible with .Net 4.5.
so nuget fail in installing AsyncIO, and then failed in installing netmq.
So I downloaded the AsyncIO Source from Github and build it locally with .Net 4.5.
After that and added the dll of AsyncIO built locally as a reference for my project.
Theoretically, NetMQ should be successfully installed with nuget. because I added the needed reference to AsyncIO.
But when trying to reinstall NetMQ, I get the same error:
Could not install package 'AsyncIO 0.1.18'. You are trying to install this package
into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111',
but the package does not contain any assembly references or content files that
are compatible with that framework. For more information, contact the package author.
and nuget did not detect that I added 'AsyncIO 0.1.18' in my project.
How to let nuget detect that I added this reference in my project?
Have a look here:
.NET Portable profiles
Profile111 is a combination of:
.NET Framework 4.5
Windows 8.0
Windows Phone 8.1
or in other words:
portable-net45+netcore45+wpa81
So your project into which you are trying to append the NuGet targets Windows Phone 8.1 and other 2 platforms, I mention this one as the most restrictive.
Now let's have a look at the named NuGet package's source:
<ProjectGuid>{3830B7A3-0225-4FDA-B155-E085E183650C}</ProjectGuid>
<OutputType>Library</OutputType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
What do we have here? We can see that the project is not a PCL. It is targeting full .NET 4.0 framework which is not available on Windows Phone 8.1. And your library does target Windows Phone 8.1. See the problem?
You say that if you compile the AsyncIO targeting .NET 4.5 than you can successfully append it into your project as a reference? That's not altogether true. I mean you can append a reference to it but you cannot use it. You will see that when you try to call something from that reference.
In order to use AsyncIO from you PCL will have to build AsyncIO as a PCL targeting the same or more restrictive set of platforms. Try creating a PCL project targeting Profile111 and try compiling the AsyncIO code with it (just link the original AsyncIO source files (*.cs) into this new AsyncIO_PCL project). If you are lucky enough and the code of AsyncIO is really compatible you will be able to use that library.
Here are your steps:
Create a new project (named AsyncIO_PCL) of type PCL class library.
Pick the Profile111 platform set i.e.
.NET Framework 4.5
Windows 8.0
Windows Phone 8.1
Link all the .cs files from the original AsyncIO project save one (AssemblyInfo.cs) into the new AsyncIO_PCL project.
Set the output assembly name to the same as in original AsyncIO project.
Try building the project.
Your ability to build the AsyncIO as a PCL with the required set of supported platforms depends on AsyncIO code i.e. which API is used inside and if that API is supported by all the three platforms you are targeting.
Try clicking right-button on the project -> Properties. In the "Application" menu check the "Target Framework". It should be set to .NET Framework 4.5

Xamarin.Forms in Xamarin Studio

I downloaded Xamarin Studio to build my first application, but I'm having some problems which I have not found a solution.
First of all I have created a new solution with the App Xamarin.Forms Blank template. When I have tried to build it, a few errors have appeared (I did not changed a single line from the template):
The type or namespace name 'Xamarin' could not be found (are you mission a using directive or an assembly reference?)
The type or namespace name 'Application' could not be found (are you mission a using directive or an assembly reference?)
Then I supposed that the Xamarin.Forms package was missing, so I clicked on Project > Add NuGet Packages... and I tried to install the Xamarin.Forms package. Here is where I get stuck, because a new error is displayed:
Could not install package 'Xamarin.Forms 1.3.3.6323'. You are trying to install this package into a project that targets 'portable-Profile78', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I would appreciate any help, because I have not found any solution.
The error message suggests that you do not have the Portable Class Libraries (PCLs) installed.
If you are on the Mac you can get these installed by installing the Mono Development Kit (MDK).
If you are on Windows the procedure is a bit more tricky. To install the Portable Class Libraries on Windows you have three options:
Install Visual Studio 2013 (full or Express version). Update 2 or above is required.
Install the Portable Library Tools and the Portable Library Reference Assemblies 4.6.
Install the Portable Library Tools and copy the .NETPortable directory from Mono over to Windows.
One problem with 2. is that installing the Portable Library Reference Assemblies 4.6 does not install them into the correct location but instead just installs a PortableReferenceAssemblies.zip file into the directory:
C:\Program Files (x86)\Microsoft .NET Portable Library Reference Assemblies 4.6
This PortableReferenceAssemblies.zip file contains three directories (4.0, 4.5 and 4.6) which need to be extracted and copied into the PCLs directory:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable
There is more detail in the Installing Portable Class Libraries for Xamarin Studio post but the above should give you an overview of what is required.

Clickonce WPF application with custom and default prerequisites

I have a .Net 4 WPF ClickOnce app that has .NET Framework 4, VC++ 2013 Runtime Libraries and Windows Installer 4.5 as prerequisites.
I now have to add VC++ 2010 Libraries.
I have followed the steps here to create a custom prerequisite package. In visual studio, the package shows up in my prerequisite list. However, the installer is not attempting to install the VC++2010 package.
product.xml
package.xml
I have downloaded the vcredist_x86.exe into the package directory, however I am unsure what to set under "Specify the install location for prerequisites", since I am now mixing custom and default pre-reqs.
Any assistance would be much appreciated!
Edit: I have logged my clickonce installation and see nothing referencing the VC++ package at all. No errors or anything.
The following configurations worked without having to include the package in the deploy.
package.xml
package.xml
product.xml
product.xml
I placed the files above in a new directory:
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\Bootstrapper\Packages\vcredist_x86-2010\product.xml
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\Bootstrapper\Packages\vcredist_x86-2010\en\package.xml
Note: I did not include the vcredist_x86.exe package anywhere in the bootstrapper directory - it is downloaded during installation.
Before the installer is run, on a fresh Windows 8.1 install;
Prompt for prerequisites;
After installer, both C++ Runtime Libraries installed;

Building Portable Class Library Project in build server fails

I've recently added some custom Portable Class Library projects to an application that is built in an build server. The build was working fine, but after that it stopped working and shows me the following messages:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(983,
5): warning MSB3644: The reference assemblies for framework
".NETPortable,Version=v4.0,Profile=Profile136" were not found.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(1578,
5): warning MSB3270: There was a mismatch between the processor
architecture of the project being built "MSIL" and the processor
architecture of the reference
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll",
"AMD64".
error CS0234: The type or namespace name 'Linq' does not exist in the
namespace 'System' (are you missing an assembly reference?)
The build server specs:
Windows Server 2008 R2 Standard
TeamCity 8.0.4
.NET 4.5
Portable Class Library Tools (as advised here)
Silverlight 5 SDK
The solution is a .NET 4.0 application and the portable projects target .NET4.0+ e Silverlight 5, only.
I have checked my development machine (Windows 8, Visual Studio 2012). There is indeed a folder "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile136" (in fact, the profiles for .NET 4.0 go up to 158).
In the build machine, however, there are only folders for profiles up to 131.
Is Portable Class Library Tools up to date? It seems it miss installing profiles for the most recent platforms.
UPDATE
I copied the ".NETPortable\v4.0\Profile\Profile136" of my development machine to the build server, and now the application builds successfully. I still would like to know why installing the Portable Class Library Tools does not work out of the box.
A more general and elegant solution is to install the latest Microsoft .NET Portable Library Reference Assemblies. This will install profile138 among many others.
The standalone installer(s) can be found at:
4.6 (June 2014):
Copying the desired profile (it is explicit in the error message) from the dev machine to the build server, after installing Portable Class Library Tools, allowed my build to work.
Apparently the Portable Class Library, as it is now, does not include the most up to date portable profiles.
If anyone knows of a more up to date way to get portable profiles on a build server, other than installing VS or copying them manually, I really would like to know.
UPDATE
Path, on my dev machine, for the folder to be copied to the server machine (the path in the server was the same):
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile136
Profile136 came with the version of the portable library targeting pack that was part of the Phone SDK 8.0 (or a later VS Update for VS 2012). The version of the targeting pack you were using is older.

Categories

Resources