SharedProject and portable class library (PCL) project in VS2015, vs2015
Today, I was idle and saw a video of the Connect conference. C #6.0's new syntax, EF7's support for non-relational databases, and Windows Store applications. net native and so on all touched me very much. However, I am more touched by the fact that the SharedProject is open to all types of projects.
Before talking about the SharedProject, let's talk about its predecessor, the Portable Class Library (PCL.
Portable Class Library:
The essence of PCL is a class library, but it is portable. What is portable? For example, if we have a project that requires the use of multiple platforms, it is generally designed as follows:
The picture is bad. Forget it. -_-|
The Model layer, data access layer, and business logic layer are generally created as common class library projects, which is normal.
As time went by, the company was growing. When the Boss/Boss began to get lucky, he said, "Well, I think that SilverLight is a pretty good thing, let's get a project ". You can only do what you want as a coanon. Open VS -- create a project -- SilverLight 5 -- add a reference to the Model layer. Mom, what?
SilverLight cannot add references to common class libraries!
At this time, the portable class library will be used. Create a new portable class library and transfer the code of the original Model layer to the portable class library. Then, the Code is the original code, however, the Model layer can be referenced by projects of various platform types.
Although the portable class library is very common, its limitations are also very large. I/O methods are almost all unavailable in the portable class library, and you do not need to think about controls.
General applications lead to the birth of the SharedProject:
In the WP8.0 period, we developed the application using the SilverLight technology, while in the Windows 8 Application store development process, we used the Windows Runtime technology. During that time, Microsoft must have been kicked out. The earliest WPF, SilverLight, and then a WinRT, and the use of controls changed from one set to another, so that we cannot find WrapPanel (native without the need to add components) when writing WP8.0, and LongListView when writing WinRT .. As a result, programmers complained that WinRT was supported during WP8.1 and that applications on both platforms could be developed at one time. What should we do? The size of the PCL limit is too large. For a common class library, there are a few differences between the two platforms (for example, the Win tablet does not have the WP return key and search key), so the SharedProject came into being.
How to Create a SharedProject:
In VS2013 and earlier versions, when we were only able to create a general application, VS automatically created one and only one for us.
App1.Shared is the SharedProject.
Open App. xaml. cs
We can see that App. xaml is used as an entry point (of course, the traditional Main is still in use. We will not discuss it here, but only discuss it in the visible scope of the project ). In addition, we can see that some of the Code in the figure is grayed out because it is compiled by the condition. Note # if WINDOWS_PHONE_APP indicates that this code is compiled only when this condition is met. Next we will modify the place in the upper left corner.
Changed to WindowsPhone and found that our code will no longer be gray. That is to say, this code is ignored when it is compiled into a Windows Store application, it is effective only when it is used in the WindowsPhone store.
It can be seen that the function is very powerful. Portable class libraries can inherit the Conditional compilation commands of referenced projects, but unfortunately, they can only be used in application store Program projects, winform, WPF, and so on can only be stunned.
However, this changed in VS2015.
And create multiple? No problem.
Conclusion:
It's hard for you to look at the official website.
Through the above process, we believe that we can find the essence of SharedProject, that is, to add the code to the referenced project during compilation. (Otherwise, the SharedProject cannot be affected by Conditional compilation instructions)
Therefore, we can obtain the following table to differentiate the characteristics of SharedProject and PCL.
Project Type |
Compilation Method |
Conditional compilation |
API restrictions |
SharedProject |
Compile the Code together with the code of the project that references SharedProject |
The condition compilation symbol cannot be defined by the Project referencing the SharedProject. |
Combined with Conditional compilation, it is the same as the project that references the SharedProject. |
Portable class library (PCL) |
Separately compiled into dll |
It is not affected by the project that references PCL and can define Conditional compilation symbols. |
Large |
It can be seen that SharedProject has a great advantage over PCL. Due to the Project Condition compilation that references the SharedProject, The SharedProject can use the APIs of the corresponding platform without losing the flexibility. I believe that after the official release of VS2015, many bloggers will like SharedProject, a new project type.