Wednesday, January 25, 2017

PnP Core Provisioning: Part 3

Today was a tough day with provisioning.  I ran into a problem at work and spent all day trying to track it down.  The provisioning engine was failing on a client system, but working on multiple generic farms, both 2013 and 2016.  I finally had to get direct access to do the deployment from a development machine and debug the PnP.Core itself to track down what was causing the problem.  Even then, I was only able to pinpoint that the issue was related to a Document Library that was in the template.  Having found that out, we replaced the Document Library with a List of the same name so that the lookup columns would all still function.  Given that, I thought it appropriate to spend a post showing how to get the source for PnP.Core from GitHub and use it directly.

I am going to be using Visual Studio Enterprise 2015 for this, but it should work fine with Visual Studio 2015 Community.  Open up your Team Explorer and then Manage Connections.  Once there, Clone the repository:
Clone the PnP.Core repository
Once you have your clone of the project, just open the PnP:
PnP.Core solution file
Once you do, you should find 2 projects and a readme.md file:
PnP.Core solution file open
As a quick aside, if you open the readme.md file and see the raw markup:
readme.md file raw markup
then I would strongly suggest you add the Markdown Editor by Mads Kristensen:
Markdown Editor
so that you get the cool split screen:
readme.md viewed with the Markdown Editor
You will want to see it formatted and you will definitely want to read it.  The most important part is the part about choosing the proper build depending on your target environment:

Compiling for SharePoint 2013
SharePoint 2013 depends on version 15 client assemblies, SharePoint 2016 depends on 16 client assemblies whereas Office 365 (SharePoint Online) uses version 16.1 client assemblies. The PnP core solution foresees support for this. The solution contains 6 configurations:

  • Debug: compiles the solution in debug mode using the version 16.1 assemblies (=default)
  • Release: compiles the solution in release mode using the version 16.1 assemblies
  • Debug15: compiles the solution in debug mode using the version 15 assemblies (=default)
  • Release15: compiles the solution in release mode using the version 15 assemblies
  • Debug16: compiles the solution in debug mode using the version 16 assemblies (=default)
  • Release16: compiles the solution in release mode using the version 16 assemblies

Once you understand that, you can easily add a console application to the solution and pick up where we left off in Part 2.  You may well have to do some tweaking to get it working, but it shouldn't be too difficult.  For example, when I tried to compile the first time this time I received 5 errors because of a bad reference to Microsoft.Identity:
Initial Compilation Errors
I just needed to add a NuGet package for it to make the errors vanish:
Adding the Microsoft.Identity NuGet package
and then it built cleanly.  That's it.  Just add your own project to the solution to wrap the DLL and you are able to debug into and make modifications to the library itself.

The Microsoft team has done a great job getting the required packages into NuGet, and an awesome job with the PnP.Core library itself.  If you happen to find an error or a shortcoming in the library, consider making the fix yourself and providing a pull request for the team.  They are very open to contributions and there is an active community constantly improving the product:
Commit Graph
Most of the contributions are coming from outside of Microsoft.  Pitch in and help by looking through the Issues list:
Issues List, Open Issues

or adding your own.  There are currently 156 open issues.  Help get it down to below 100!

Keep your code clean!

No comments:

Post a Comment