Showing posts with label pcl. Show all posts
Showing posts with label pcl. Show all posts

Friday, November 1, 2013

October 2013, What a month this has been...

October is about to pass. But what an amazing months it has been...

The greatest skill a developer has to have is to adjust within a group of people. Believe me, this is even difficult than developing a technical skill. Interpersonal communication is a craft and one needs to master it in order to better survive for selling the ideas. Since we are in the business of consulting for software services, we need to move between organizations every few months and years. Not all the people are welcoming, they have different psychologies and motivations. These events prove to be a practice. You need to go to the venue, introduce yourself, present in the presence of total strangers - you have no idea about their backgrounds.

Few Advices & Lessons Learned
Humor is an interpersonal lubricant. Since we are interacting with the audience for the first time, we need to break the barrier of being strange. Humor is the universal lubrication of friction between people. You are never strange for the people who smile with you. Although this is the most effective technique, but this can go either way. You need to pull off the joke really well. Like an actor, the punch line has to be effective. Practice it, tell it a few times to your friends no matter how annoying they become.

One must go through the session material before the session. I have realized that we try to be very detail oriented when are creating slides for our presentation. These conferences and code camps are not class room sessions. People are interested in links and ideas they can take home. This give them direction for their technical development. We need to give them as much as possible in the limited time we have. But the most important thing is to motivate them enough about the stuff that they study further after the event. We need to be fresh for the event, so take a nap before the event.

We can also record the session if possible. This is one of the take away item for yourself. A recorded session can be useful for preparing yourself if you are speaking about the same stuff later on. This is specially useful if you have been away focusing on some other technological stuff for a few months. You can also publish them for general audience if you think this might help them learning about the topic.

We must time box our session. A session has a list of agenda items. We need to make sure that we time box the agenda so that we are able to cover each item and still be able to finish our session in time. If there is an item which is taking more time, tell about some pointers the audience might take away with them. We must also be ourselves, confident and to the point. Call your family or friend for a little chit chat in the morning.

Session Slides
I have presented my thoughts and ideas over two areas from a huge list of Microsoft technology stack. They are as follows:
  1. Cross Platform Development using Portable Class Libraries
  2. Event Source API, ETW and Semantic Logging Application Block
I have uploaded the session slides on my sky drive. You can view it here or download it if you want to view them offline.



Session Videos
Here are the session videos from the events in Silicon Valley, Boston and Southwest Florida Code camps.

semanticLogs from Muhammad Siddiqi on Vimeo.


Portable Class Libraries - Boston Codecamp 20 from Muhammad Siddiqi on Vimeo.


slab from Muhammad Siddiqi on Vimeo.


Cross Platform Development with Portable Class Libraries from Muhammad Siddiqi on Vimeo.

Download Code
You can also download the code from these sessions. I even uploaded that to my sky drive.

Wednesday, October 30, 2013

Adding PCL Reference to Mono Touch and Mono for Android Applications

October has been a fun month. I got to travel across the country to three different places, met with amazing people and shared the common enthusiasm about technology. It's like our souls know each others. Code camps are opportunities for learning for everyone; including presenters and attendees. For one, presenters in one session like to go to other sessions as attendees, the other is, when they are asked thought provoking questions covered with practical problems of the individual developers. Most of the times, it makes the presenter think about the specialized area; it makes them see it in a different perspective.

I am planning a separate post about the experiences about the October. I think this would be a good idea to discuss some questions on the blog. Let's discuss first question in this post. The question is:

Can we add PCL references in Montouch and Mono for Android applications?

The short answer is Yes; and we can also do that in Visual Studio. I have Xamarin Starter edition installed on my machine. It also includes a trial version of Visual Studio extension for Xamarin tools.

Xamarin Studio
Here I have a sample solution called NameReflectorApp. It has a portable class library project Xamarin.Core. It also has an android application project NameReflectorApp.Android.



The portable class library project is targeting a number of frameworks as shown below:



This is targeting Profile 158 of .net portable subset. There are still some issues with Xamarin Studio like you see a warning message at the bottom of the target frameworks. But don't worry, this should still work. We cannot see here Mono for Android as one of the target frameworks but we can still add such references. In Xamarin's term, this is called Edit References, funny...



Visual Studio Support
Xamarin has support for Visual Studio. But this is not available for all the editions. Generally speaking, it is available for more expensive ones. But we can still play with the extension during the trial period available when we install the starter edition. The best thing is we can decide when we want to start the trial period. We can use this option to first familiarize ourselves with the technology and when we need to see how well it integrates with our current Microsoft technologies, we can start the trial period.



Visual Studio is not as forgiving in adding references in such case. There are issues with the Xamarin's Visual Studio extension. As we add our portable class library's reference to Android application, it shows up the following error dialog.



Xamarin developer community terms this situation as a lie. In order to fix this, we need to use some xml hack. I would totally recommend the following post where we discussed how we can add additional frameworks options for Portable Class Library projects.



As we discussed in the above post, we can add options for additional target frameworks by adding files the Supported Frameworks folder for a target profile. Let's add two new Xml files to our selected profile as follows:



The contents of these files are as follows:

After adding the above files, we need to restart Visual Studio. After that, as we go to the PCL's property page, we see that there are already Xamarin.iOS and Xamarin.Android in the target framework list. If we hit Change button, we see additional options for Xamrin.iOS and Xamarin.Android. These options are checked.



Adding the reference to the Android application project goes through just fine. Here is the portable library's reference added to the project's references list.



If you have Xamarin Studio running then restart this and open the same solution again. You can see that these new frameworks are also available in Xamarin, which is amazing.



Download



Thursday, October 10, 2013

VS2013 RC: Portable Class Libraries Target Frameworks

In this post we are going to discuss the changes in target framework selections in Visual Studio 2013 RC. Up until, Visual Studio 2012, Visual Studio has supported the following framework selections:
  1. .Net framework 4.0, 4.0.3 & 4.5
  2. Silverlight 4 & 5
  3. Windows Phone 7.x & 8.0
  4. Windows Store Apps
  5. Xbox 360
With Visual Studio 2013 RC, now Portable Class Libraries can also support targeting .net framework 4.5.1 and Windows Store Apps (Windows 8.1). But Visual Studio 2013 has mainly reduced other target frameworks for PCL. The following is the list of frameworks which are not supported in Visual Studio 2013 for PCL development.
  1. Silverlight 4
  2. Windows Phone 7.x
  3. Xbox 360


Supported Framework Xml Changes
In order to support a combination of target frameworks for PCLs, Visual Studio keeps a list of xml documents in Supported framework folders for each profile. Actually, a profile is selected based on target framework selection matching the profile.



Now we can develop PCLs in three different versions of Visual Studio. They are Visual Studio 2010 SP1, 2012 and 2013 RC. It appears that in order to limit target frameworks for PCL development in Visual Studio 2013 RC there are some changes in the Xml schema for these documents. Let's see the document for Silverlight 4 in Profile44 in Visual Studio 2012.


Visual Studio 2013 has added a few new attributes. They are FamilyName, MinimumVisualStudioVersion and MaximumVisualStudioVersion. We must remember that the version of Visual Studio 2012 and 2013 RC are 11.x and 12.x respectivly.


The above is the Xml document for Silverlight 4 in the Supported Framework folder in the same profile after the installation of Visual Studio 2013 RC. We can notice that the maximum version for the framework is "11.0", so the framework is not supported in Visual Studio 2013 RC. Below is the framework xml for Windows Store apps (Windows 8.1) in \v4.6\Profile\Profile44\SupportedFrameworks folder. From the xml document, we can clearly figure out that this profile can only be used for a Visual Studio version 2013 RC at minimum.


Converting Project for Unsupported Frameworks
Opening a PCL project in Visual Studio can convert the target frameworks to one of the supported frameworks. A Silverlight4 project is converted to Silverlight5 project.



We can opt to not migrate the project to a new framework version but we wouldn't be able to work on it in Visual Studio 2013 RC then. The project is shown in Solution Explorer as follows:



There seems to be a bug in the current version, which shows the following error message if we don't opt to convert, by not checking the check box. It is shown as follows:

Wednesday, October 9, 2013

Silicon Valley Code Camp 2013 Session Material

It was a great experience speaking at Silicon Valley Codecamp this year. As promised, here is the recording of my session.

Cross Platform Development with Portable Class Libraries from Muhammad Siddiqi on Vimeo.

This is the slide deck from my session:



You can get the code from my sky drive. Here is the download link:



Following, you can see further details about the event and sessions. You can also evaluate the session.

Sunday, March 10, 2013

Boston Code Camp 19 - Mar 2013

Thanks for attending my session in Boston Code camp on March 2013, if you did. Here are the slides:


You always meet the most amazing people in such events. This time I had the same pleasure of interacting and discussing about the how technology is shaping up specially Microsoft stack of technologies.


Me with Julie Larmen

This time I also tried walking a bit around town. Here are some beautiful pictures. Unfortunately, the battery died down, otherwise, I was planning to have the whole catalog here [I mean my cell phone's battery :) (not mine)]




Wednesday, January 16, 2013

Connect Items Status for Portable Class Library Project References

A few months back we disucssed about an issue with assembly references with Portable Class Library Project. The issue was submitted here:

https://connect.microsoft.com/VisualStudio/feedback/details/768350/assembly-references-in-portable-library-projects

We have a complete post detailing the actual issue here:

http://www.shujaat.net/2012/10/issues-bugs-with-portable-class-library.html

Microsoft team was kind enough to pick up the issue for fixing. Actually the connect item has two reported items. It seems that the issue is partially fixed in the final release of Visual Studio 2012. The status is now set as "Active".

Friday, November 9, 2012

Portable Class Library & Selected Profile

How can we determine the profile used by a portable class library project?

I have seen the question frequently thrown at me in some of my talks. This question is generally raised as soon as I explain how profiles are used by portable libraries. So I thought for the interest it would be beneficial for the Microsoft developer community if I create a separate post about this.

Profiles Info from Visual Studio 2012
Here we are using Visual Studio 2012 RC for this example. The release version should have the same behavior. Let's open the portable class library project, named MyPortableLibrary, created in the previous example in Visual Studio.


In order to see the selected profile for the project, let's open the solution explorer and expand References section. You should only see .Net Portable Subset if you haven't added any other assembly references manually. Right click .Net Portable Subset and select Properties. The Properties should be opened with the following display.


Here you can see that the project is targeted for Profile4. You can see the details of the profiles by following the profile path. In Visual Studio, you can also see the referenced assemblies for the target profile. Just open Object Browser window and select My Solution.


Profile Info outside Visual Studio
Is it possible to find out which profile the project is referencing on a non-developer machine? Generally, you wouldn't find Visual Studio installed on such machines. These profiles are standard profiles provided by Microsoft. Actually the profile info is part of project definition. You can open the project file [*.csproj for c# projects] in any text editor and find the profile info. Here we have opened the project file in Notepad.


Obviously you can see the same in Visual Studio as well. Just unload the project in Solution Explorer and Edit Project file. You should be able to see this.


Profile Info from Assembly Manifest
Profile info is also available in assembly manifest. Just look for TargetFrameworkAttribute and you should be able to find the actual profile that the assembly is targeting. Here we have used the manifest from one of our previous posts.


Obviously we can check the profile of the running assembly:

The code results in the following output for one of my portable library:


The same information is certainly available for a debug session as well:


Portable Vs Retargetable Assemblies

As we have been discussing that Portable Class Libraries allow us to target the same assembly for multiple platforms. Hence the name "portable" as they can be ported to the platforms and frameworks specified at design time. And as we have discussed before, that this sharing can be called Assembly Portability. Although you can create a portable library which is also retargetable but being portable is not the same as being retargetable. We can just use this manifest from one of our previous discussions about portable libraries. You can see that it is referencing a few retargetable libraries.

Are you wondering what actually is being retargetable? Basically portable Class Libraries is a recent introduction to developer's toolkit but retargetability has been there for a long time. As we have discussed in one of our previous posts that the assemblies in profile folder are just there for reference. They are to make sure that only certain features and types are used from them based on the automatic profile selection by the Visual Studio IDE. [The selected profile is part of the definition of portable class library project. You can easily find this in the project definition].

The actual runtime assemblies [e.g. System.dll] wouldn't be used from the profile. They would be used directly from the host framework. So if your portable library has Silverlight 4 as one of the target framework then it would be using the System assembly as provided by Silverlight 4 runtime. Portable Library Developers at Microsoft has made sure that there are no runtime surprises when your portable assembly is loaded by the host framework by only supporting the features provided by all of the selected target frameworks. That is exactly what Retargetability is. For an assembly, being retargetable means that the actual assembly will be used as provided at runtime. Let's see the manifest of a retargetable assembly [System.dll] from Profile1 using ILDASM.


Now you might be wondering if we can create a retargetable library. Actually you can do it. You can provide flags when you are developing your assembly. These flags are used from AssemblyNameFlags enumeration available in System.Reflection.

http://msdn.microsoft.com/en-us/library/system.reflection.assemblynameflags.aspx


The combination of these flags can be accessed through Flags property of your required assembly.

http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.flags.aspx

Just because you can do this, it doesn't necessarily mean you should. There doesn't seem to be any reason why we would be needing a custom retargetable library. This is from the documentation of the member of the enumeration from MSDN.

"Specifies that the assembly can be retargeted at runtime to an assembly from a different publisher. This value supports the .NET Framework infrastructure and is not intended to be used directly from your code."

This member is also available for your Portable Class Library project. Remember the special icon that shows the Portable Library support in msdn?


To see how this works, let's create a simple portable class library project, named MyPortableLibrary.


Let's build the project and see the manifest in ILDASM tool. This is definitely not a retargetable library.


Now let's add the flag in the assembly info file for the project as follows:


Now let's build the project again and see the updated manifest. You can notice that the assembly is now marked as retargetable.


Saturday, July 28, 2012

Multi Plaftorm Targeting using Portable Class Libraries - An Introduction

I have been putting off the discussion about portable class library tool for a long time now. But since Microsoft has released RC2 of the tool this month with exciting new features, it is very appealing to carry the message forward to followers of my blog.

Multi-platform targeting has been a big issue when we want to reuse our code for these platforms. It is common when we are working on a rich UI application with Silverlight and WPF interfaces. It has been so difficult to reuse our code because of incompatible class libraries. Silverlight does not support regular class libraries targeted for Windows platform and we need to create separate Silverlight Class Libraries.

Existing Workarounds for Multi-Targeting:
There are several workarounds developed to cope with this issue. One of them is project link. We create links between project to use types from the other project.

Project Linker:
This is a Visual Studio Add-on provided by Microsoft P&P. It makes life easier for linking the project items in multiple projects. If we link a project with another project, then if an item is added in the source project, the same item is added to the destination project. For a long time, developers have used this to be the only option for multi-targeting to WPF and Silverlight projects.

http://msdn.microsoft.com/en-us/library/ff648745.aspx

This can be downloaded from Visual Studio Gallery from here:

http://visualstudiogallery.msdn.microsoft.com/5e730577-d11c-4f2e-8e2b-cbb87f76c044/

Once installed, it can be used to add a project link to a destination project. Just right click a project and select Add Project Link. You can then specify the source project.


Adding Existing Item as Link: . This is the same thing as "Project Linker" does. It is just doing the same thing manually. Add an item in source project. Go to destination project, add existing item and make sure that you add it as link.

Pre-requisite:
Visual Studio 2010 sp1 or Visual Studio 2011 can be used to create portable class libraries. We do need to install Portal Library Tools. It can be downloaded from Visual Studio Gallery [http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981]


We can also use Extension Manager to install Portable Class Library.


Installation On Build Machines
In this time and age, you wouldn't find an organization with no Continuous Integration [CI] support. Mostly they use Jet Brain's Team City or Cruise Control .net. The pre-requisite described above are for development machines. Portable Class Library tools can be installed on build machines using /buildmachine switch. From msdn:

Run the installation program from a Command Prompt window, and include the /buildmachine switch on the command line.

Creating Portable Class Library Project
After installation of extension in Visual Studio 2010 Sp1, a project template is added for creating portable class library project. It is also available in Visual Studio 2011. We can find it in Add New Project dialog as follows:


While creating the project, an option is provided to select the required target frameworks. We can select the supported .net, silverlight and WP frameworks. It also supports the selection of XBox 360 and Metro Style App support.


These options can also be changed later on from the project's Properties page. Please notice the new Library tab available. Here we can select the target frameworks. This is equivalent to Application tab of .net framework class library where we can select the target framework.


Please not that there are other tabs too which are not available for portable class libraries.


Feature Set & Selected Frameworks:
The feature set available for portable libraries depend on the selected target frameworks. There is a universal set of feature supported by all the frameworks which are possible targets. Out of these universal features, each individual framework would support a subset.

It is very tempting to select all available frameworks for target. But doing that is limiting ourselves. As described above each framework would only support a subset of available features. Selecting multiple frameworks would make only the intersection of the features of supported frameworks. In the following example, we are selecting the .net framework and Silverlight as target frameworks. The available feature set is the overlapping area between two circles [Remember Venn diagram from your statistics courses :)]. If this is .net framework 4, then the library wouldn't have any view model support.


This could be further limiting if we select other frameworks.


Selecting all frameworks would only provide the little overlapping features supported by all frameworks.


This shouldn't be a limiting factor for your development. The library which is supposed to be shared across different platform would never have such code which have a dependency for a particular framework. The selected frameworks is basically an indication that the code is generic enough that it could be shared across these platforms.

The following subset is available for Silverlight 4, .Net for Metro style app and Windows Phone 7 platforms.


The following is the list of available libraries for the multiple targets of .net framework 4.0.3, Silverlight 4, Windows Phone 7, .Net for Metro style apps and Xbox 360.


Please not that if there is an additional framework which could also be selected without any effects to the available set for the selected frameworks than it is automatically selected.


Referencing Portable Libraries and Portable Library References:
Portable libraries cannot add references from non-portable libraries. Here ClassLibrary1 is a .net framework 4.0 class library. An attempt to add a reference to the portable class library causes the following:


Portable Library references can be added to regular libraries belonging to the supported frameworks. The same error message is displayed if an a portable library's assembly references is being added to an unsupported framework.