Visual Studio 2010 portable class library won't let me change the target - visual-studio-2010

I'm trying to make a portable class library in VS2010. By default, it seems to be targeting .NET Framework 4 and higher. I need to target 4.03 or higher because I need some features that were added (System.Xml.Linq). But when I try to change the target framework, the change doesn't work. I get this dialog:
I can choose one of the other frameworks and say OK, but when I look again, it's set back to the same Framework 4.0 setting, and my code using the 4.03 features still doesn't compile. What's going on here?
Update: It does let me choose 4.5 as long as I don't choose Mono for Android or VS Mono Touch. It looks like something in those libraries requires 4.0, but I don't understand why, since 4.5 is backwards compatible. And this is for use in Mono, so I need those.

I figured this out with some hacking of the configuration files for the portable framework. First, read this post about how to add library support for PCL's for MonoDroid and this one to do a similar thing for MonoTouch.
In the .csproj file for the PCL project, I found this line:
<TargetFrameworkProfile>Profile95</TargetFrameworkProfile>
which points to this folder:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile95
In that folder, there's a subfolder called SupportedFrameworks and this was missing the magic files MonoAndroid,Version=v1.6+.xml and VSMonoTouch,Version=v1.0+.xml. I added these, as described in the linked post, and now it works.

I've implemented the ability to pick and choose the PCL profile constraints in MonoDevelop in git master, but it has not yet been released.
I believe these features will be included in MonoDevelop 3.1.0

Related

How to get NuGet options in Visual Studio 2017 Community?

I am struggling with creating NuGet packages. I am using Visual Studio 2017 Community edition.
I have seen a couple of videos that show a "Pack" option on the menu when right-clicking the project in Solution Explorer. However, I do not have that option. Is this one of the features in the other (non-Community) versions of Visual Studio? I believe I have also seen a "create NuGet package on build" option mentioned somewhere. I cannot find that either.
I have tried various ways of using nuget, dotnet, and msbuild from the command line(s), but haven't had much success. Very frustrating.
Any help is appreciated.
If you really want to use Visual Studio, I would recommend installing an extension that helps you with that problem. For example, this one. The options people have in videos depend on the extensions they have installed. For you, it is the same.
Alternatively, just use the command-line tooling for this as explained here or for .NET Core here or here.
dotnet/msbuild pack is only available for SDK-style projects, but I believe works for all versions of Visual Studio, as well as on the command line. .NET Core introduced these SDK-style projects, which can be identified by <Project Sdk="Microsoft.NET.Sdk">. If your project (.csproj if it's a C# project) doesn't have the Sdk property or import Microsoft.NET.Sdk in either of the two other ways, then it's not an SDK style project and doesn't support packing in this way. Another obvious difference between the two styles of projects is that SDK projects are only a few lines long from the new project template and don't list files in the project, whereas old style projects are typically a full screen long, even from a new project template with only a single class file, and it does list individual files in the project. If you want to continue with this project type, you'll need to use nuget.exe pack and you'll probably want to create a .nuspec file to define some of the package metadata.
However, using SDK style projects is the future, it just takes time for all of Microsoft's existing project types to migrate. It's much simpler to use, so personally I would avoid old style projects unless you're using a project type (like ASP.NET, not ASP.NET Core) that doesn't support it.
All of this is confusing for anyone new to the .NET ecosystem. My recommendation is 1. when you install Visual Studio, when making your workload selections, make sure in the component list that .NET Core is selected, whatever the newest version of .NET Core that is available at the time of installation. When creating a new project in Visual Studio, always select the .NET Core version, or .NET Standard version of any new project template, even if you want to target the (Windows) .NET Framework, in which case you edit the .csproj and change <TargetFramework>netstandard2.0</TargetFramework> to <TargetFramework>net45</TargetFramework>, although I would recommend multi-targeting possible by adding a s to the element name and using a semi-colon separated list: <TargetFrameworks>net45;netstandard2.0</TargetFrameworks>. So, avoid the "Class Library (.NET Framework)" template, instead use "Class Library (.NET Standard)" and then change the target if you have to.
#zivkan led me down the right path. Changing my project types to .Net Core from .Net Framework made all the options I mentioned in my original post available. No extensions were needed.
My .Net Core class library project now has the Pack and Publish options available on the project's context menu. In addition, there is a another tab (Package) on the project properties page. On that page there is a "Generate NuGet package on build" option along with version, name, tags and other properties.
I have done much .Net framework development, but have been ignoring .Net Core and the newer options. I guess I need to dig in and learn about them.

Is it possible to avoid ADK uses in Xamarin?

I need to implement few features, however, they do not seem to be possible, and I don't have a lot of implementation time.
I have a solution PCL (.NET 4.5, Profile=111) and for some reasons (that I don't understand from hours now), I can't install the following packages :
Stripe (The only one that can be installed is Stripe.net, but I can only install it on Android and iOS, not on the PCL part..)
Cloudinary (I tried all of them and... It's not compatible with .NET 4.5, Profile=111)
Do you have any idea or any work around to make it work? I need Stripe for payments and Cloudinary for images hosting. It's already what the company is using so, I have to adapt.
I was thinking about don't use any sdk and just do everything by myself, is it allowed/possible?
Both of that packages have .Net Standard targets so i would prefer to use new *.csproj vs2017 format with library targeting .Net Standard. That is not an PCL that targets .Net Standard, this is not an PCL at all.
.Net Standard library with new csproj format have some advantages like:
Ability to install old nuget packages that targeting platforms as well as new packages that targeting .Net Standard(as opposite to PCL that can install only ald packages)
Ability to edit csproj file on the fly without unloading project
Simplified csproj file
Cleaner look of dependencies
Smoother work (fewer bugs problems)
Some other stuff Im not aware of
Here is full list of changes.
For that you need to create new project from template .Net Standard->Class Library(.Net Standard). Than install all nuget packages there and link that project from your platform projects. Old PCL can be deleted. Here is some guide to migrate. Note: to install old nuget packages that targets .Net Portable you need to add in your csproj file similar lines:
<PropertyGroup>
<PackageTargetFallback>portable-net45+win8+wp8+wpa81</PackageTargetFallback>
<PackageTargetFallback>net461</PackageTargetFallback>
</PropertyGroup>
PackageTargetFallback attribute for every target framework you library needs. That will allow old packages to pass target checks.

How (practically) to reuse an existing .NET library in MonoTouch

Let's say I've got an existing .NET assembly built in Visual Studio 2010, which is consumed in some other Winforms product. It has no third-party dependencies.
I want to reuse that library directly in a MonoTouch solution.
As it stands, to be able to add a reference to my library from within my MonoTouch UI project, I have to create a new csproj file and create links to all of the source files within it.
This works but is a maintenance burden. There must be a better way?
Thanks in advance.
As of today you need to rebuild your assemblies. That's because they'll be linked to monotouch BCL (e.g. a different mscorlib.dll) which a superset of the base class libraries (BCL) shipped with Silverlight.
Hopefully newer release of MonoTouch (and Mono, Mono for Android...) will support the new "portable library" which would make it easier to share compiled binaries across frameworks.
http://blogs.msdn.com/b/bclteam/archive/2011/01/19/announcing-portable-library-tools-ctp-justin-van-patten.aspx
Believe it or not, you actually can reference a .dll lib built in VS.NET as long as your shared assembly is not referencing any other assemblies that would make it incompatible with monotouch. I currently am doing this on our project. The referenced .dll only has dependencies on System and System.Core and its basically just a set of POCO's. I'm sure someone with better knowledge can tell you exactly what it would take to make the .dll incompatible. Even using an incompatible API call within System or System.Core could break it per poupou's answer but if you keep your shared .dll dead simple it should work.

Building Compact Framework applications with VS2010 (without VS2005)

I want to perform a .NET CF 2.0 build using VS2010. I know it's not supported "normnally," but I've seen this answer: ( .NET Compact Framework with Visual Studio 2010? ) ...and I want to use that approach.
The blog post cited there says I need to modify the .csproj files for the .NET CF projects, to point to a particular Microsoft.CompactFramework.Common.targets . But I don't have that file.
I figured I needed to install the Windows Mobile 6 Standard SDK to get it.
I tried installing it and get this:
I have seen this question:
Windows Mobile 6 Standard SDK Refresh install issue on Visual Studio 2010 Professional Beta 2
I don't think the solution proposed there is workable for me. I do not have VS2008. I do not have VS2005. I have only VS2010, and I have no installable media for those other products.
I have also tried the administrative install (msiexec /a), but the resulting directory structure doesn't contain any files like Microsoft.CompactFramework.Common.targets .??
Q1:
Is there a way for me to install WM6 Standard SDK?
Q2: Anyone know the reg key that it looks for to determine if I have the appropriate pre-reqs?
Is this going to work if I just fiddle with my registry?
Q3: Is my assumption wrong? Really I want the Microsoft.CompactFramework.Common.targets file and its friends. Where can I get this? (I have no existing VS2008 machine to suck from)
Q4: Another approach I can think of is getting an eval version of VS2008, installing that into a VM, then installing the WM6 Std SDK there, then grabbing the Microsoft.CompactFramework.Common.targets file from that. Long way round. Is this gonna work and is it worth the trouble?
ANSWER
Here's the answer.
It is possible to build CF apps with VS2010, as outlined in Joel Fjorden's blog post. There are pre-requisites you need, in order to make this happen.
I believe the only official way to get the required files, including Microsoft.CompactFramework.Common.targets , Microsoft.CompactFramework.CSharp.targets , Microsoft.CompactFramework.VisualBasic.targets and Microsoft.CompactFramework.Build.Tasks.dll , is to install the related version of Visual Studio. These files are all version-specific, so to get the files for building for .NET CF 2.0, you need to install VS2005, and for .NET CF 3.5 you need to install VS2008. Installing VS2010 gives you neither. It works to use eval versions of the tools. It worked for me anyway.
If you are willing to go custom, you can simply copy these files from a working installation of VS2005 or VS2008 (or both), into the appropriate .NET directory, usually something like C:\Windows\Microsoft.NET\Framework\v2.0.50727 (change the version as appropriate). Chris Tacke has helpfully posted a link to the files you need. I don't know if copying these files violates the license for VS20?? , I am not a licensing expert.
You cannot get these files from the Windows Mobile SDK, as far as I can tell. Even so, you might still want a version-specific mobile SDK to get the emulators and skins and so on.
This is a basic "build" capability. It works but it doesn't give you designer support, debugging capability, built-in project templates, and so on. My advice to anyone who wants to do forward development on .NET CF is to use the tools that are geared toward those tasks - VS2005 or VS2008.
Thanks to Chris Tacke for posting a link for the files.
Not sure if it's any help, but the CF targets files from VS2008 can be found here. Let us know if you make any progress.
The "Power Toys for .NET Compact Framework" package (currently found at http://www.microsoft.com/en-us/download/details.aspx?id=13442) also contains the required files.
Thought I'd leave that here since it's an official Microsoft download.

How do I change a standard library project to be a silverlight library project?

I've downloaded the Ninject SVN visual studio project and I want to compile it against Silverlight libraries to make a Silverlight compatible DLL.
Is there a setting to change somewhere to make it a Silverlight library project, or do I need to swap in and out references here and there?
There is no setting, you will need to swap in the appropriate SL libraries, its not just "here and there" its actually "everywhere". You then need to hope that the project doesn't use anything that isn't present in the SL libraries.

Resources