There seem to be two rules for assembly / project references in a portable class library project.
- Portable Class Library Project can only reference other portable class library projects / assemblies.
- The project where the reference is being added must have compatible set of framework selection as the project / assembly whose reference is being added. This compatibility is difficult to understand. Basically the available features set of the source assembly / project must be same or smaller than the target project. This happens when the source project / assembly is either targeting the same set of frameworks or has more framework selections than the target portable class library project.
No Checks for Portable assembly references:
The only verification for assembly references seem to be that the source assembly must be a portable library. It doesn't seem to verify the platform selection of the source assembly.
Let's look at the sample solution with two portable class library projects as follows:
The platforms selection of the PortableSourceLibrary and PortableTargetLibrary is as follows:
From the platform selection it is apparent that PortableSourceLibrary is targeting a bigger subset of features than the PortableTargetLibrary project. Based on the rules discussed above, a reference of PortableClassLibrary project can be added to the PortableSourceLibrary project.
For the same reason vice versa is not true i.e. when we try to add a reference of PortableSourceLibrary into PortableTargetLibrary, the IDE doesn't allow so and shows the error notification dialog. But when we try to add the assembly reference instead of the project reference, it doesn't show the same behavior.
And it silently adds the reference.
This is definitely a different behavior than the project reference and it needs to be requested to be fixed.
No Verification when the target platforms for source portable library project is updated:
Portable Class Library project checks whether the source portable library project has the compatible platforms selection as the current project. But it seem that this is only checked when the reference is being added. Once the reference is added then we can change it to an incompatible platforms selection and this would still build fine.
Let's again add PortableTargetLibrary project reference into PortableSourceLibrary project.
Now select the PortableTargetLibrary project and update the target frameworks as follows:
Now this is the combination which would be an issue if we add a fresh reference of this project to PortableSourceLibrary project. But there doesn't seem to be any issue now when the reference is already added.
Please note that the project having the references does report issues when we unload the project and try to load it again. We can't load it unless we update the target platforms for the source project being referenced.
I have reported the issue on Microsoft Connect. Please vote for this.
https://connect.microsoft.com/VisualStudio/feedback/details/768350/assembly-references-in-portable-library-projects
Download
No comments:
Post a Comment