Getting started with PnP Core SDK

Published Mar 15 2021 01:55 AM 3,605 Views

Introduction

PnP Core SDK is a library designed to help you work with Microsoft 365 services in your .NET projects, this currently focuses on SharePoint and Teams as part of the V1.0 GA release. The PnP Core SDK is the successor to the PnP-Sites-Core project - the library that underpins well known tools such as the PnP Provisioning Engine and PnP PowerShell, and is designed to use the latest development techniques and standards such as:

  • .Net 5 and .Net Standard 2.0 support – this has cross-platform support allowing you to build solutions for a wider range of platforms, greater performance, and a larger range of APIs.
  • Unified object model - obscures the underlying API used to retrieve the data, so from a developer point of view, the SDK handles determining the best API to use e.g., Graph, SharePoint, REST or CSOM meaning you can focus on writing your business logic rather than dealing with working with the various APIs to access the features you need to consume. This yields a significantly faster response and huge performance benefits over the older CSOM method accessing SharePoint.
  • Batching support at the API level to reduce the calls to the service with retry logic to handle cases such as service throttling.

Improved Quality

The PnP Core SDK has a strong focus on quality, to help reduce bugs and issues, provide developers with better support working with the SDK, concentrating, and building on the following points:

  • Unit testing – with a project goal to maintain over 80% of the SDK covered by unit tests, we also as part use a new mocking framework that allows us to perform rapid tests without the dependency of the underlying services.
  • Improved documentation – we have built a portal that contains all the API documentation, how to use the SDK and perform common operations with sample code to help developers use the SDK in their business logic.
  • Samples – a range of samples initially focusing on, Console App, Web App, Azure Functions, Blazor, WPF and even an example on a Raspberry Pi – each demonstrating a working example using the SDK interacting with Microsoft 365 services.
  • Contributor guidance – we have included support documentation for contributors to explain, how to get setup, how to extend the models that work with SharePoint and the Graph, writing unit tests and supporting documentation.

This is a starting point, and we are actively working on better ways of supporting developers with the use of the SDK and testing to ensure that SDK maintains a high standard of quality – of course, we welcome any feedback, issues, suggestions from the community, all are welcome.

Getting started building an app

We are next going to show you, the simplest method of creating a console app that interacts with Microsoft 365, provides you with a login window, and creates a page in SharePoint using the awesome support for working with Modern Pages in the PnP Core SDK.

 

But before we start writing the application, we are going to need to setup a few things in Azure and SharePoint:

SharePoint Site

For the purposes of this example, we will use a Microsoft 365 Group connected team, please sure that you set one up for the application to connect to.

Azure AD App

The application uses Azure AD app to authenticate into the services required, for this you we recommend creating your own Azure AD app, and there are tools that can assist with this either the Microsoft 365 CLI, PnP PowerShell are great at making it easy to setup your own Azure AD Apps – additionally, we also have documentation to help set up the app. Make sure you take a note of the Azure AD app - Application Id, you will need this later.

 

If you want to test the app first, we recommend setup of a “dev” tenant to test the application in a non-production environment – check out this article to understand on how to get a free developer tenant from Microsoft.

Building the Application

So, let’s get going with using the SDK, so for this next section, we will show you how to get going in Visual Studio (btw, Visual Studio Code supported as well), to get the packages and connect to the Microsoft 365 Services using a C# Console Application.

 

Note: If you do not have visual studio, and you are using this for academic, open-source, or personal usage, you can download Visual Studio Community edition to get going, this blog is using Visual Studio 2019, version V16.9.

 

In Visual Studio, create a new C# Console Application (.NET core),

 

Create a new visual studio projectCreate a new visual studio project

(Note: I have filtered the list using the dropdowns to find the project type quickly)

Select Next, and Enter Project Name, Location and Solution Name as your discretion,

Under additional information, please select .NET 5.0 as the Target Framework

 

Visual studio - select .NET versionVisual studio - select .NET version

Visual Studio will create a hello world project for you, as a starting place.

 

Next we, want to get the NuGet package for the PnP Core SDK, NuGet is a package manager tool that by Microsoft is an essential tool in modern development that allows you to download, create, share, useful libraries and packages to use in your .NET projects – this is where the PnP Core SDK packages are published to.

 

Continuing in Visual Studio, right click on the solution and find the “Manage NuGet Packages for Solution” option.

 

Option to manage NuGet packages in the solution right-click menuOption to manage NuGet packages in the solution right-click menu

When the package manager opens, Click to Browse for Packages and Enter “PnP Core SDK” in the search bar, to show the two packages described earlier.

Find the PnP Core SDK NuGet packagesFind the PnP Core SDK NuGet packages

About the versions and libraries

When searching for the NuGet packages you will see two options, these options are:

  • PnP.Core – this includes the core library that interacts with the Microsoft 365 workloads such as SharePoint and Microsoft Graph.
  • PnP.Core.Auth – includes the authentication library providing multiple methods in which to securely connect to Microsoft 365 using Azure Active Directory - this includes PnP.Core as a dependency. In most cases, you will only need to use this one to get started.

You will need an additional NuGet Package called “Microsoft.Extensions.Hosting” – this allows us to manage the services in the lifetime of running the app. For further information, please refer the documentation around the generic host library.

 

With regards to the way versioning is done for the SDK, there are major releases which currently is v1.0.0 and nightly releases e.g., v1.0.1-nightly which are the prerelease versions allowing you to use the very latest build this would include any fixes and new features.

 

PnP Core SDK release versionsPnP Core SDK release versions

Let’s start writing some code

Once you have added the NuGet packages, open the program.cs file, this is the entry point that the application runs calling on the Main method, we need to add code to this to configure the connection to Microsoft 365 services and perform the page operations.

 

Change the program.cs file using the following code:

 

 

using System;

// Add the relevant using statements for PnP Core
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using PnP.Core.Model.SharePoint;
using PnP.Core.Services;
using System.Threading.Tasks;
using PnP.Core.Auth;

// Ensure you have added the NuGet packages
//  - PnP.Core.Auth
//  - Microsoft.Extensions.Hosting

namespace GettingStartedConsoleApp
{
    class Program
    {
        // Update main method for asynchronous 
        static async Task Main(string[] args)
        {
            // Setup the host
            // This app uses interactive login
            
            var host = Host.CreateDefaultBuilder()
            
            .ConfigureServices((hostingContext, services) =>
            {
                //    Add the PnP Core SDK library services
                services.AddPnPCore(options => {

                    options.DefaultAuthenticationProvider = new InteractiveAuthenticationProvider(
                            "f8023692-08de-48ea-8bef-d987f10e08d2", // Client Id
                            "contoso.onmicrosoft.com", // Tenant Id
                            new Uri("http://localhost"));  // Redirect Id
                });
            })

            // Let the builder know we're running in a console
            .UseConsoleLifetime()
            // Add services to the container
            .Build();

            // Start console host
            await host.StartAsync();

            // Connect to SharePoint
            using (var scope = host.Services.CreateScope())
            {
                // Obtain a PnP Context factory
                var pnpContextFactory = scope.ServiceProvider.GetRequiredService<IPnPContextFactory>();
                // Use the PnP Context factory to get a PnPContext for the given configuration
                using (var context = await pnpContextFactory.CreateAsync(new Uri("https://contoso.sharepoint.com/sites/pnpcoresdktestgroup")))
                {
                    var web = await context.Web.GetAsync();
                    Console.WriteLine($"Title: {web.Title}");

                    // Create the page
                    var page = await context.Web.NewPageAsync();

                    // Configure the page header
                    // Check out for more detail https://pnp.github.io/pnpcore/using-the-sdk/pages-header.html
                    page.SetDefaultPageHeader();
                    page.PageHeader.LayoutType = PageHeaderLayoutType.CutInShape;
                    page.PageHeader.ShowTopicHeader = true;
                    page.PageHeader.TopicHeader = "Welcome";
                    page.PageHeader.TextAlignment = PageHeaderTitleAlignment.Center;

                    // adding sections to the page
                    page.AddSection(CanvasSectionTemplate.OneColumn, 1);

                    // Adding text control to the first section, first column
                    // Check out for more detail https://pnp.github.io/pnpcore/using-the-sdk/pages-webparts.html#working-with-text-parts
                    page.AddControl(page.NewTextPart("<p style=\"text-align:center\">" +
                                                        "<span class=\"fontSizeSuper\">" +
                                                            "<span class=\"fontColorRed\">" +
                                                                "<strong>PnP Core SDK Rocks!</strong>" +
                                                            "</span>" +
                                                        "</span>" +
                                                     "</p>"), page.Sections[0].Columns[0]);

                    // Save the page
                    await page.SaveAsync("Awesomeness.aspx");
                    
                    // Publish the page
                    await page.PublishAsync();
                }
            }

            // Cleanup console host
            host.Dispose();
        }
    }
}

 

 

In the above sample, we look through the sections of the code:

 

Async – the PnP Core SDK is designed to work asynchronously, so we need to update the main method to include the “async” keyword and “Task” return type to allow the code inside to run.

 

 

 // Update main method for asynchronous 
 static async Task Main(string[] args)

 

 


Configure Host ­
– This block creates and configures the host to run the application, this adds references to the PnP Core SDK, configures the default authentication method, as the simplest method of connecting to Microsoft 365 services, there are other ways to implement this, such as using an appsettings.json file or inline code, if you want more information about this - the PnP Core SDK documentation site contains the additional instructions.

 

 

// Setup the host
// This app uses interactive login
            
var host = Host.CreateDefaultBuilder()
            
.ConfigureServices((hostingContext, services) =>
{
  //    Add the PnP Core SDK library services
 services.AddPnPCore(options => {

    options.DefaultAuthenticationProvider = new InteractiveAuthenticationProvider(
        "f8023692-08de-48ea-8bef-d987f10e08d2", // Client Id
        "contoso..onmicrosoft.com", // Tenant Id
        new Uri("http://localhost"));  // Redirect Id
    });
 })

 // Let the builder know we're running in a console
 .UseConsoleLifetime()
 // Add services to the container
 .Build();

 // Start console host
 await host.StartAsync();

 

 

Note, the client ID shown above is the same as the ID as the Azure AD app, you set up earlier.


Setup Context – This block will create a context to connect to SharePoint supplying the URL to the site this will use the default authentication provider specified earlier – on running the app, this will open a window or tab to allow you to interactively log into your tenant. When authenticated, you are returned a context to perform further options using the connection.

 

 

// Connect to SharePoint
using (var scope = host.Services.CreateScope())
{
   // Obtain a PnP Context factory
   var pnpContextFactory = scope.ServiceProvider.GetRequiredService<IPnPContextFactory>();
 
  // Use the PnP Context factory to get a PnPContext for the given configuration
  using (var context = await pnpContextFactory.CreateAsync(new Uri("https://contoso.sharepoint.com/sites/pnpcoresdktestgroup")))
  {

 

 


Make a page – Now that you have connected and you have a context object, you can set to write code that interacts with the service.

 

 

// Create the page
var page = await context.Web.NewPageAsync();

// Configure the page header
// Check out for more detail https://pnp.github.io/pnpcore/using-the-sdk/pages-header.html
page.SetDefaultPageHeader();
page.PageHeader.LayoutType = PageHeaderLayoutType.CutInShape;
page.PageHeader.ShowTopicHeader = true;
page.PageHeader.TopicHeader = "Welcome";
page.PageHeader.TextAlignment = PageHeaderTitleAlignment.Center;

// adding sections to the page
page.AddSection(CanvasSectionTemplate.OneColumn, 1);

// Adding text control to the first section, first column
// Check out for more detail https://pnp.github.io/pnpcore/using-the-sdk/pages-webparts.html#working-with-text-parts
page.AddControl(page.NewTextPart("<p style=\"text-align:center\">" +
                                   "<span class=\"fontSizeSuper\">" +
                                      "<span class=\"fontColorRed\">" +
                                         "<strong>PnP Core SDK Rocks!</strong>" +
                                      "</span>" +
                                   "</span>" +
                                "</p>"), page.Sections[0].Columns[0]);

// Save the page
await page.SaveAsync("Awesomeness.aspx");
                    
// Publish the page
await page.PublishAsync();

 

 

The code fragment is a simple example of using the Modern Pages support, by doing the following:

  • Creating a modern page
  • Setting the header of the page
  • Adds a one column section to the page
  • Adds a text web part to the page with some simple formatting, to the new section in the first column.
  • Saving the page
  • Publishing the page

If you want to dive deeper into how to use the SDK when working with Modern Pages, there is documentation on the site that covers adding web parts, configuring the header, publishing and promoting pages and multi-lingual support.

 

Once written, Hit F5, log in and see the result:

Resulting page creation by the console appResulting page creation by the console app

What’s Next

So, you have written the app, what’s next, if you want a further examples and a video walkthrough, checkout the short video by Paolo Pialorsi (one of the major authors of the SDK) on PiaSys Tech Bites,  “Welcome PnP Core SDK” with a fantastic demo (no spoilers here) - https://www.youtube.com/watch?v=ozqN5-Yh5cM

 

Check out these great resources to help you build your solutions:

 

There is still plenty to do in the SDK, if you want to contribute to this open source repository, you are most welcome to, we have tagged areas in the issues list for areas we are looking for help with, please reach out either on social media, via GitHub to connect and support you getting started.

 

Enjoy!

%3CLINGO-SUB%20id%3D%22lingo-sub-2207918%22%20slang%3D%22en-US%22%3EGetting%20started%20with%20PnP%20Core%20SDK%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2207918%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--499404264%22%20id%3D%22toc-hId--499404265%22%3EIntroduction%3C%2FH2%3E%0A%3CP%3EPnP%20Core%20SDK%20is%20a%20library%20designed%20to%20help%20you%20work%20with%20Microsoft%20365%20services%20in%20your%20.NET%20projects%2C%20this%20currently%20focuses%20on%20SharePoint%20and%20Teams%20as%20part%20of%20the%20V1.0%20GA%20release.%20The%20PnP%20Core%20SDK%20is%20the%20successor%20to%20the%20PnP-Sites-Core%20project%20-%20the%20library%20that%20underpins%20well%20known%20tools%20such%20as%20the%20PnP%20Provisioning%20Engine%20and%20PnP%20PowerShell%2C%20and%20is%20designed%20to%20use%20the%20latest%20development%20techniques%20and%20standards%20such%20as%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E.Net%205%20and%20.Net%20Standard%202.0%20support%3C%2FSTRONG%3E%20%E2%80%93%20this%20has%20cross-platform%20support%20allowing%20you%20to%20build%20solutions%20for%20a%20wider%20range%20of%20platforms%2C%20greater%20performance%2C%20and%20a%20larger%20range%20of%20APIs.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EUnified%20object%20model%3C%2FSTRONG%3E%20-%20obscures%20the%20underlying%20API%20used%20to%20retrieve%20the%20data%2C%20so%20from%20a%20developer%20point%20of%20view%2C%20the%20SDK%20handles%20determining%20the%20best%20API%20to%20use%20e.g.%2C%20Graph%2C%20SharePoint%2C%20REST%20or%20CSOM%20meaning%20%3CEM%3Eyou%20can%20focus%20on%20writing%20your%20business%20logic%3C%2FEM%3E%20rather%20than%20dealing%20with%20working%20with%20the%20various%20APIs%20to%20access%20the%20features%20you%20need%20to%20consume.%20This%20yields%20a%20significantly%20faster%20response%20and%20huge%20performance%20benefits%20over%20the%20older%20CSOM%20method%20accessing%20SharePoint.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EBatching%20support%3C%2FSTRONG%3E%20at%20the%20API%20level%20to%20reduce%20the%20calls%20to%20the%20service%20with%20retry%20logic%20to%20handle%20cases%20such%20as%20service%20throttling.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-1988108569%22%20id%3D%22toc-hId-1988108568%22%3EImproved%20Quality%3C%2FH2%3E%0A%3CP%3EThe%20PnP%20Core%20SDK%20has%20a%20strong%20focus%20on%20quality%2C%20to%20help%20reduce%20bugs%20and%20issues%2C%20provide%20developers%20with%20better%20support%20working%20with%20the%20SDK%2C%20concentrating%2C%20and%20building%20on%20the%20following%20points%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EUnit%20testing%3C%2FSTRONG%3E%20%E2%80%93%20with%20a%20project%20goal%20to%20maintain%20over%20%3CSTRONG%3E80%25%20of%20the%20SDK%20covered%20by%20unit%20tests%3C%2FSTRONG%3E%2C%20we%20also%20as%20part%20use%20a%20new%20mocking%20framework%20that%20allows%20us%20to%20perform%20rapid%20tests%20without%20the%20dependency%20of%20the%20underlying%20services.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EImproved%20documentation%3C%2FSTRONG%3E%20%E2%80%93%20we%20have%20built%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fpnp%2Fcoresdk%2Fdocs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ea%20portal%20that%20contains%20all%20the%20API%20documentation%3C%2FA%3E%2C%20how%20to%20use%20the%20SDK%20and%20perform%20common%20operations%20with%20sample%20code%20to%20help%20developers%20use%20the%20SDK%20in%20their%20business%20logic.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ESamples%3C%2FSTRONG%3E%20%E2%80%93%20a%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fdemos%2FREADME.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Erange%20of%20samples%3C%2FA%3E%20initially%20focusing%20on%2C%20Console%20App%2C%20Web%20App%2C%20Azure%20Functions%2C%20Blazor%2C%20WPF%20and%20even%20an%20example%20on%20a%20Raspberry%20Pi%20%E2%80%93%20each%20demonstrating%20a%20working%20example%20using%20the%20SDK%20interacting%20with%20Microsoft%20365%20services.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EContributor%20guidance%3C%2FSTRONG%3E%20%E2%80%93%20we%20have%20included%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fcontributing%2Freadme.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Esupport%20documentation%20for%20contributors%3C%2FA%3E%20to%20explain%2C%20how%20to%20get%20setup%2C%20how%20to%20extend%20the%20models%20that%20work%20with%20SharePoint%20and%20the%20Graph%2C%20writing%20unit%20tests%20and%20supporting%20documentation.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThis%20is%20a%20starting%20point%2C%20and%20we%20are%20actively%20working%20on%20better%20ways%20of%20supporting%20developers%20with%20the%20use%20of%20the%20SDK%20and%20testing%20to%20ensure%20that%20SDK%20maintains%20a%20high%20standard%20of%20quality%20%E2%80%93%20of%20course%2C%20we%20welcome%20any%20feedback%2C%20issues%2C%20suggestions%20from%20the%20community%2C%20%3CSTRONG%3E%3CEM%3Eall%20are%20welcome%3C%2FEM%3E%3C%2FSTRONG%3E.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-180654106%22%20id%3D%22toc-hId-180654105%22%3EGetting%20started%20building%20an%20app%3C%2FH2%3E%0A%3CP%3EWe%20are%20next%20going%20to%20show%20you%2C%20the%20simplest%20method%20of%20creating%20a%20console%20app%20that%20interacts%20with%20Microsoft%20365%2C%20provides%20you%20with%20a%20login%20window%2C%20and%20creates%20a%20page%20in%20SharePoint%20using%20the%20awesome%20support%20for%20working%20with%20Modern%20Pages%20in%20the%20PnP%20Core%20SDK.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20before%20we%20start%20writing%20the%20application%2C%20we%20are%20going%20to%20need%20to%20setup%20a%20few%20things%20in%20Azure%20and%20SharePoint%3A%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-871215580%22%20id%3D%22toc-hId-871215579%22%3ESharePoint%20Site%3C%2FH3%3E%0A%3CP%3EFor%20the%20purposes%20of%20this%20example%2C%20we%20will%20use%20a%20Microsoft%20365%20Group%20connected%20team%2C%20please%20sure%20that%20you%20set%20one%20up%20for%20the%20application%20to%20connect%20to.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--936238883%22%20id%3D%22toc-hId--936238884%22%3EAzure%20AD%20App%3C%2FH3%3E%0A%3CP%3EThe%20application%20uses%20Azure%20AD%20app%20to%20authenticate%20into%20the%20services%20required%2C%20for%20this%20you%20we%20recommend%20creating%20your%20own%20Azure%20AD%20app%2C%20and%20there%20are%20tools%20that%20can%20assist%20with%20this%20either%20the%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fcli-microsoft365%2Fuser-guide%2Fusing-own-identity%2F%23register-azure-ad-application-in-your-tenant%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EMicrosoft%20365%20CLI%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fsharepoint-pnp%2Fregister-pnpazureadapp%3Fview%3Dsharepoint-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EPnP%20PowerShell%3C%2FA%3E%20are%20great%20at%20making%20it%20easy%20to%20setup%20your%20own%20Azure%20AD%20Apps%20%E2%80%93%20additionally%2C%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fusing-the-sdk%2Fconfiguring%2520authentication.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ewe%20also%20have%20documentation%20to%20help%20set%20up%20the%20app%3C%2FA%3E.%20Make%20sure%20you%20take%20a%20note%20of%20the%20Azure%20AD%20app%20-%20Application%20Id%2C%20you%20will%20need%20this%20later.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20test%20the%20app%20first%2C%20we%20recommend%20setup%20of%20a%20%E2%80%9Cdev%E2%80%9D%20tenant%20to%20test%20the%20application%20in%20a%20non-production%20environment%20%E2%80%93%20check%20out%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fmicrosoft-365-pnp-blog%2Fwhat-is-a-dev-tenant-and-why-would-you-want-one%2Fba-p%2F2036610%22%20target%3D%22_blank%22%3Ethis%20article%20to%20understand%20on%20how%20to%20get%20a%20free%20developer%20tenant%20from%20Microsoft%3C%2FA%3E.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1551273950%22%20id%3D%22toc-hId-1551273949%22%3EBuilding%20the%20Application%3C%2FH3%3E%0A%3CP%3ESo%2C%20let%E2%80%99s%20get%20going%20with%20using%20the%20SDK%2C%20so%20for%20this%20next%20section%2C%20we%20will%20show%20you%20how%20to%20get%20going%20in%20Visual%20Studio%20(btw%2C%20Visual%20Studio%20Code%20supported%20as%20well)%2C%20to%20get%20the%20packages%20and%20connect%20to%20the%20Microsoft%20365%20Services%20using%20a%20C%23%20Console%20Application.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%3A%20If%20you%20do%20not%20have%20visual%20studio%2C%20and%20you%20are%20using%20this%20for%20academic%2C%20open-source%2C%20or%20personal%20usage%2C%20you%20can%20%3CA%20href%3D%22https%3A%2F%2Fvisualstudio.microsoft.com%2Fvs%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Edownload%20Visual%20Studio%20Community%20edition%3C%2FA%3E%20to%20get%20going%2C%20this%20blog%20is%20using%20Visual%20Studio%202019%2C%20version%20V16.9.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20Visual%20Studio%2C%20create%20a%20new%20C%23%20Console%20Application%20(.NET%20core)%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Create%20a%20new%20project.png%22%20style%3D%22width%3A%20602px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263412i761218D228BE345E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Create%20a%20new%20project.png%22%20alt%3D%22Create%20a%20new%20visual%20studio%20project%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ECreate%20a%20new%20visual%20studio%20project%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E(Note%3A%20I%20have%20filtered%20the%20list%20using%20the%20dropdowns%20to%20find%20the%20project%20type%20quickly)%3C%2FP%3E%0A%3CP%3ESelect%20Next%2C%20and%20Enter%20Project%20Name%2C%20Location%20and%20Solution%20Name%20as%20your%20discretion%2C%3C%2FP%3E%0A%3CP%3EUnder%20additional%20information%2C%20please%20select%20.NET%205.0%20as%20the%20Target%20Framework%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22addtional%20information.png%22%20style%3D%22width%3A%20602px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263422i63D493F41D5B7C25%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22addtional%20information.png%22%20alt%3D%22Visual%20studio%20-%20select%20.NET%20version%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EVisual%20studio%20-%20select%20.NET%20version%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EVisual%20Studio%20will%20create%20a%20hello%20world%20project%20for%20you%2C%20as%20a%20starting%20place.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%20we%2C%20want%20to%20get%20the%20NuGet%20package%20for%20the%20PnP%20Core%20SDK%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ENuGet%20is%20a%20package%20manager%20tool%3C%2FA%3E%20that%20by%20Microsoft%20is%20an%20essential%20tool%20in%20modern%20development%20that%20allows%20you%20to%20download%2C%20create%2C%20share%2C%20useful%20libraries%20and%20packages%20to%20use%20in%20your%20.NET%20projects%20%E2%80%93%20%3CA%20href%3D%22https%3A%2F%2Fwww.nuget.org%2Fpackages%3Fq%3DPnP%2BCore%2BSDK%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ethis%20is%20where%20the%20PnP%20Core%20SDK%20packages%20are%20published%20to%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EContinuing%20in%20Visual%20Studio%2C%20right%20click%20on%20the%20solution%20and%20find%20the%20%E2%80%9CManage%20NuGet%20Packages%20for%20Solution%E2%80%9D%20option.%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorPaul%20Bullock_0%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Manage%20Nuget.png%22%20style%3D%22width%3A%20747px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263423i7F30ED4D41B83F38%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Manage%20Nuget.png%22%20alt%3D%22Option%20to%20manage%20NuGet%20packages%20in%20the%20solution%20right-click%20menu%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EOption%20to%20manage%20NuGet%20packages%20in%20the%20solution%20right-click%20menu%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EWhen%20the%20package%20manager%20opens%2C%20Click%20to%20Browse%20for%20Packages%20and%20Enter%20%E2%80%9CPnP%20Core%20SDK%E2%80%9D%20in%20the%20search%20bar%2C%20to%20show%20the%20two%20packages%20described%20earlier.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Nuget%20Packages.png%22%20style%3D%22width%3A%20752px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263424i97012334E7E5416E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Nuget%20Packages.png%22%20alt%3D%22Find%20the%20PnP%20Core%20SDK%20NuGet%20packages%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EFind%20the%20PnP%20Core%20SDK%20NuGet%20packages%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--256180513%22%20id%3D%22toc-hId--256180514%22%3E%3CSTRONG%3EAbout%20the%20versions%20and%20libraries%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EWhen%20searching%20for%20the%20NuGet%20packages%20you%20will%20see%20two%20options%2C%20these%20options%20are%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EPnP.Core%3C%2FSTRONG%3E%20%E2%80%93%20this%20includes%20the%20core%20library%20that%20interacts%20with%20the%20Microsoft%20365%20workloads%20such%20as%20SharePoint%20and%20Microsoft%20Graph.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EPnP.Core.Auth%3C%2FSTRONG%3E%20%E2%80%93%20includes%20the%20authentication%20library%20providing%20multiple%20methods%20in%20which%20to%20securely%20connect%20to%20Microsoft%20365%20using%20Azure%20Active%20Directory%20-%20this%20%3CEM%3Eincludes%20PnP.Core%20as%20a%20dependency%3C%2FEM%3E.%20In%20most%20cases%2C%20you%20will%20only%20need%20to%20use%20this%20one%20to%20get%20started.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EYou%20will%20need%20an%20additional%20NuGet%20Package%20called%20%E2%80%9CMicrosoft.Extensions.Hosting%E2%80%9D%20%E2%80%93%20this%20allows%20us%20to%20manage%20the%20services%20in%20the%20lifetime%20of%20running%20the%20app.%20For%20further%20information%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fcore%2Fextensions%2Fgeneric-host%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eplease%20refer%20the%20documentation%20around%20the%20generic%20host%20library%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20regards%20to%20the%20way%20versioning%20is%20done%20for%20the%20SDK%2C%20there%20are%20major%20releases%20which%20currently%20is%20v1.0.0%20and%20nightly%20releases%20e.g.%2C%20v1.0.1-nightly%20which%20are%20the%20prerelease%20versions%20allowing%20you%20to%20use%20the%20very%20latest%20build%20this%20would%20include%20any%20fixes%20and%20new%20features.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SDK%20Release%20versions.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263425i9D9D3E4255F36123%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SDK%20Release%20versions.png%22%20alt%3D%22PnP%20Core%20SDK%20release%20versions%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EPnP%20Core%20SDK%20release%20versions%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--2063634976%22%20id%3D%22toc-hId--2063634977%22%3ELet%E2%80%99s%20start%20writing%20some%20code%3C%2FH3%3E%0A%3CP%3EOnce%20you%20have%20added%20the%20NuGet%20packages%2C%20open%20the%20%3CSTRONG%3E%3CEM%3Eprogram.cs%3C%2FEM%3E%3C%2FSTRONG%3E%20file%2C%20this%20is%20the%20entry%20point%20that%20the%20application%20runs%20calling%20on%20the%20Main%20method%2C%20we%20need%20to%20add%20code%20to%20this%20to%20configure%20the%20connection%20to%20Microsoft%20365%20services%20and%20perform%20the%20page%20operations.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EChange%20the%20%3CSTRONG%3E%3CEM%3Eprogram.cs%3C%2FEM%3E%3C%2FSTRONG%3E%20file%20using%20the%20following%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Eusing%20System%3B%0A%0A%2F%2F%20Add%20the%20relevant%20using%20statements%20for%20PnP%20Core%0Ausing%20Microsoft.Extensions.DependencyInjection%3B%0Ausing%20Microsoft.Extensions.Hosting%3B%0Ausing%20PnP.Core.Model.SharePoint%3B%0Ausing%20PnP.Core.Services%3B%0Ausing%20System.Threading.Tasks%3B%0Ausing%20PnP.Core.Auth%3B%0A%0A%2F%2F%20Ensure%20you%20have%20added%20the%20NuGet%20packages%0A%2F%2F%20%20-%20PnP.Core.Auth%0A%2F%2F%20%20-%20Microsoft.Extensions.Hosting%0A%0Anamespace%20GettingStartedConsoleApp%0A%7B%0A%20%20%20%20class%20Program%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%2F%2F%20Update%20main%20method%20for%20asynchronous%20%0A%20%20%20%20%20%20%20%20static%20async%20Task%20Main(string%5B%5D%20args)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Setup%20the%20host%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20This%20app%20uses%20interactive%20login%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20host%20%3D%20Host.CreateDefaultBuilder()%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20.ConfigureServices((hostingContext%2C%20services)%20%3D%26gt%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20%20%20%20Add%20the%20PnP%20Core%20SDK%20library%20services%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20services.AddPnPCore(options%20%3D%26gt%3B%20%7B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20options.DefaultAuthenticationProvider%20%3D%20new%20InteractiveAuthenticationProvider(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22f8023692-08de-48ea-8bef-d987f10e08d2%22%2C%20%2F%2F%20Client%20Id%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22contoso.onmicrosoft.com%22%2C%20%2F%2F%20Tenant%20Id%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20Uri(%22http%3A%2F%2Flocalhost%22))%3B%20%20%2F%2F%20Redirect%20Id%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Let%20the%20builder%20know%20we're%20running%20in%20a%20console%0A%20%20%20%20%20%20%20%20%20%20%20%20.UseConsoleLifetime()%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Add%20services%20to%20the%20container%0A%20%20%20%20%20%20%20%20%20%20%20%20.Build()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Start%20console%20host%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20host.StartAsync()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Connect%20to%20SharePoint%0A%20%20%20%20%20%20%20%20%20%20%20%20using%20(var%20scope%20%3D%20host.Services.CreateScope())%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Obtain%20a%20PnP%20Context%20factory%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20pnpContextFactory%20%3D%20scope.ServiceProvider.GetRequiredService%3CIPNPCONTEXTFACTORY%3E()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Use%20the%20PnP%20Context%20factory%20to%20get%20a%20PnPContext%20for%20the%20given%20configuration%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20using%20(var%20context%20%3D%20await%20pnpContextFactory.CreateAsync(new%20Uri(%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2Fpnpcoresdktestgroup%22)))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20web%20%3D%20await%20context.Web.GetAsync()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Console.WriteLine(%24%22Title%3A%20%7Bweb.Title%7D%22)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Create%20the%20page%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20page%20%3D%20await%20context.Web.NewPageAsync()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Configure%20the%20page%20header%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Check%20out%20for%20more%20detail%20https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fusing-the-sdk%2Fpages-header.html%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20page.SetDefaultPageHeader()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20page.PageHeader.LayoutType%20%3D%20PageHeaderLayoutType.CutInShape%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20page.PageHeader.ShowTopicHeader%20%3D%20true%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20page.PageHeader.TopicHeader%20%3D%20%22Welcome%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20page.PageHeader.TextAlignment%20%3D%20PageHeaderTitleAlignment.Center%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20adding%20sections%20to%20the%20page%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20page.AddSection(CanvasSectionTemplate.OneColumn%2C%201)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Adding%20text%20control%20to%20the%20first%20section%2C%20first%20column%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Check%20out%20for%20more%20detail%20https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fusing-the-sdk%2Fpages-webparts.html%23working-with-text-parts%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20page.AddControl(page.NewTextPart(%22%3CP%20style%3D%22%5C%26quot%3Btext-align%3Acenter%5C%26quot%3B%22%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3CSPAN%20class%3D%22%5C%26quot%3BfontSizeSuper%5C%26quot%3B%22%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3CSPAN%20class%3D%22%5C%26quot%3BfontColorRed%5C%26quot%3B%22%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3CSTRONG%3EPnP%20Core%20SDK%20Rocks!%3C%2FSTRONG%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3C%2FSPAN%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3C%2FSPAN%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3C%2FP%3E%22)%2C%20page.Sections%5B0%5D.Columns%5B0%5D)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Save%20the%20page%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20await%20page.SaveAsync(%22Awesomeness.aspx%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Publish%20the%20page%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20await%20page.PublishAsync()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Cleanup%20console%20host%0A%20%20%20%20%20%20%20%20%20%20%20%20host.Dispose()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%3C%2FIPNPCONTEXTFACTORY%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20above%20sample%2C%20we%20look%20through%20the%20sections%20of%20the%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EAsync%3C%2FSTRONG%3E%26nbsp%3B%E2%80%93%20the%20PnP%20Core%20SDK%20is%20designed%20to%20work%20asynchronously%2C%20so%20we%20need%20to%20update%20the%20main%20method%20to%20include%20the%20%E2%80%9Casync%E2%80%9D%20keyword%20and%20%E2%80%9CTask%E2%80%9D%20return%20type%20to%20allow%20the%20code%20inside%20to%20run.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20%2F%2F%20Update%20main%20method%20for%20asynchronous%20%0A%20static%20async%20Task%20Main(string%5B%5D%20args)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CBR%20%2F%3EConfigure%20Host%20%C2%AD%3C%2FSTRONG%3E%E2%80%93%20This%20block%20creates%20and%20configures%20the%20host%20to%20run%20the%20application%2C%20this%20adds%20references%20to%20the%20PnP%20Core%20SDK%2C%20configures%20the%20default%20authentication%20method%2C%20as%20the%20simplest%20method%20of%20connecting%20to%20Microsoft%20365%20services%2C%20there%20are%20other%20ways%20to%20implement%20this%2C%20such%20as%20using%20an%20%3CEM%3Eappsettings.json%3C%2FEM%3E%20file%20or%20inline%20code%2C%20if%20you%20want%20more%20information%20about%20this%20-%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fusing-the-sdk%2Fconfiguring%2520authentication.html%23configuring-pnp-core-sdk-to-use-the-configured-application%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ethe%20PnP%20Core%20SDK%20documentation%20site%20contains%20the%20additional%20instructions%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%2F%2F%20Setup%20the%20host%0A%2F%2F%20This%20app%20uses%20interactive%20login%0A%20%20%20%20%20%20%20%20%20%20%20%20%0Avar%20host%20%3D%20Host.CreateDefaultBuilder()%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A.ConfigureServices((hostingContext%2C%20services)%20%3D%26gt%3B%0A%7B%0A%20%20%2F%2F%20%20%20%20Add%20the%20PnP%20Core%20SDK%20library%20services%0A%20services.AddPnPCore(options%20%3D%26gt%3B%20%7B%0A%0A%20%20%20%20options.DefaultAuthenticationProvider%20%3D%20new%20InteractiveAuthenticationProvider(%0A%20%20%20%20%20%20%20%20%22f8023692-08de-48ea-8bef-d987f10e08d2%22%2C%20%2F%2F%20Client%20Id%0A%20%20%20%20%20%20%20%20%22contoso..onmicrosoft.com%22%2C%20%2F%2F%20Tenant%20Id%0A%20%20%20%20%20%20%20%20new%20Uri(%22http%3A%2F%2Flocalhost%22))%3B%20%20%2F%2F%20Redirect%20Id%0A%20%20%20%20%7D)%3B%0A%20%7D)%0A%0A%20%2F%2F%20Let%20the%20builder%20know%20we're%20running%20in%20a%20console%0A%20.UseConsoleLifetime()%0A%20%2F%2F%20Add%20services%20to%20the%20container%0A%20.Build()%3B%0A%0A%20%2F%2F%20Start%20console%20host%0A%20await%20host.StartAsync()%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%2C%20the%20client%20ID%20shown%20above%20is%20the%20same%20as%20the%20ID%20as%20the%20Azure%20AD%20app%2C%20you%20set%20up%20earlier.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CBR%20%2F%3E%3C%2FSTRONG%3E%3CSTRONG%3ESetup%20Context%3C%2FSTRONG%3E%20%E2%80%93%20This%20block%20will%20create%20a%20context%20to%20connect%20to%20SharePoint%20supplying%20the%20URL%20to%20the%20site%20this%20will%20use%20the%20default%20authentication%20provider%20specified%20earlier%20%E2%80%93%20on%20running%20the%20app%2C%20this%20will%20open%20a%20window%20or%20tab%20to%20allow%20you%20to%20interactively%20log%20into%20your%20tenant.%20When%20authenticated%2C%20you%20are%20returned%20a%20context%20to%20perform%20further%20options%20using%20the%20connection.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%2F%2F%20Connect%20to%20SharePoint%0Ausing%20(var%20scope%20%3D%20host.Services.CreateScope())%0A%7B%0A%20%20%20%2F%2F%20Obtain%20a%20PnP%20Context%20factory%0A%20%20%20var%20pnpContextFactory%20%3D%20scope.ServiceProvider.GetRequiredService%3CIPNPCONTEXTFACTORY%3E()%3B%0A%20%0A%20%20%2F%2F%20Use%20the%20PnP%20Context%20factory%20to%20get%20a%20PnPContext%20for%20the%20given%20configuration%0A%20%20using%20(var%20context%20%3D%20await%20pnpContextFactory.CreateAsync(new%20Uri(%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2Fpnpcoresdktestgroup%22)))%0A%20%20%7B%3C%2FIPNPCONTEXTFACTORY%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CBR%20%2F%3E%3C%2FSTRONG%3E%3CSTRONG%3EMake%20a%20page%3C%2FSTRONG%3E%26nbsp%3B%E2%80%93%20Now%20that%20you%20have%20connected%20and%20you%20have%20a%20context%20object%2C%20you%20can%20set%20to%20write%20code%20that%20interacts%20with%20the%20service.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%2F%2F%20Create%20the%20page%0Avar%20page%20%3D%20await%20context.Web.NewPageAsync()%3B%0A%0A%2F%2F%20Configure%20the%20page%20header%0A%2F%2F%20Check%20out%20for%20more%20detail%20https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fusing-the-sdk%2Fpages-header.html%0Apage.SetDefaultPageHeader()%3B%0Apage.PageHeader.LayoutType%20%3D%20PageHeaderLayoutType.CutInShape%3B%0Apage.PageHeader.ShowTopicHeader%20%3D%20true%3B%0Apage.PageHeader.TopicHeader%20%3D%20%22Welcome%22%3B%0Apage.PageHeader.TextAlignment%20%3D%20PageHeaderTitleAlignment.Center%3B%0A%0A%2F%2F%20adding%20sections%20to%20the%20page%0Apage.AddSection(CanvasSectionTemplate.OneColumn%2C%201)%3B%0A%0A%2F%2F%20Adding%20text%20control%20to%20the%20first%20section%2C%20first%20column%0A%2F%2F%20Check%20out%20for%20more%20detail%20https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fusing-the-sdk%2Fpages-webparts.html%23working-with-text-parts%0Apage.AddControl(page.NewTextPart(%22%3CP%20style%3D%22%5C%26quot%3Btext-align%3Acenter%5C%26quot%3B%22%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3CSPAN%20class%3D%22%5C%26quot%3BfontSizeSuper%5C%26quot%3B%22%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3CSPAN%20class%3D%22%5C%26quot%3BfontColorRed%5C%26quot%3B%22%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3CSTRONG%3EPnP%20Core%20SDK%20Rocks!%3C%2FSTRONG%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3C%2FSPAN%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3C%2FSPAN%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3C%2FP%3E%22)%2C%20page.Sections%5B0%5D.Columns%5B0%5D)%3B%0A%0A%2F%2F%20Save%20the%20page%0Aawait%20page.SaveAsync(%22Awesomeness.aspx%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%2F%2F%20Publish%20the%20page%0Aawait%20page.PublishAsync()%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20code%20fragment%20is%20a%20simple%20example%20of%20using%20the%20Modern%20Pages%20support%2C%20by%20doing%20the%20following%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECreating%20a%20modern%20page%3C%2FLI%3E%0A%3CLI%3ESetting%20the%20header%20of%20the%20page%3C%2FLI%3E%0A%3CLI%3EAdds%20a%20one%20column%20section%20to%20the%20page%3C%2FLI%3E%0A%3CLI%3EAdds%20a%20text%20web%20part%20to%20the%20page%20with%20some%20simple%20formatting%2C%20to%20the%20new%20section%20in%20the%20first%20column.%3C%2FLI%3E%0A%3CLI%3ESaving%20the%20page%3C%2FLI%3E%0A%3CLI%3EPublishing%20the%20page%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EIf%20you%20want%20to%20dive%20deeper%20into%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpnpcore%2Fusing-the-sdk%2Fpages-intro.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehow%20to%20use%20the%20SDK%20when%20working%20with%20Modern%20Pages%3C%2FA%3E%2C%20there%20is%20documentation%20on%20the%20site%20that%20covers%20adding%20web%20parts%2C%20configuring%20the%20header%2C%20publishing%20and%20promoting%20pages%20and%20multi-lingual%20support.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20written%2C%20Hit%20F5%2C%20log%20in%20and%20see%20the%20result%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22result.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F263431i8319DE59D6A25B6E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22result.png%22%20alt%3D%22Resulting%20page%20creation%20by%20the%20console%20app%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EResulting%20page%20creation%20by%20the%20console%20app%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2074138080%22%20id%3D%22toc-hId--2074138081%22%3EWhat%E2%80%99s%20Next%3C%2FH2%3E%0A%3CP%3ESo%2C%20you%20have%20written%20the%20app%2C%20what%E2%80%99s%20next%2C%20if%20you%20want%20a%20further%20examples%20and%20a%20video%20walkthrough%2C%20checkout%20the%20short%20video%20by%20Paolo%20Pialorsi%20(one%20of%20the%20major%20authors%20of%20the%20SDK)%20on%20PiaSys%20Tech%20Bites%2C%26nbsp%3B%20%E2%80%9CWelcome%20PnP%20Core%20SDK%E2%80%9D%20with%20a%20fantastic%20demo%20(no%20spoilers%20here)%20-%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DozqN5-Yh5cM%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DozqN5-Yh5cM%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECheck%20out%20these%20great%20resources%20to%20help%20you%20build%20your%20solutions%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EFor%20understanding%20how%20the%20PnP%20Core%20SDK%20fits%20in%20the%20picture%20of%20the%20wave%20of%20uplifts%20by%20the%20team%20check%20out%20-%20%3CA%20href%3D%22https%3A%2F%2Fpractical365.com%2Fblog%2Fhow-the-new-wave-of-libraries-from-microsoft-365-pnp-will-change-the-way-you-modernize-sharepoint%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EHow%20the%20new%20wave%20of%20libraries%20from%20Microsoft%20365%20PnP%20will%20change%20the%20way%20you%20modernize%20SharePoint%20(practical365.com)%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EThe%20PnP%20Core%20SDK%20site%20with%20guidance%20on%20using%20the%20SDK%2C%20API%20level%20documentation%2C%20how%20to%20contribute%20and%20samples%20-%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fpnp%2Fcoresdk%2Fdocs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGetting%20started%20with%20the%20PnP%20Core%20SDK%20%7C%20PnP%20Core%20SDK%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EWant%20to%20contribute%2C%20have%20an%20issue%2C%20bug%2C%20feature%20suggestion%20%E2%80%93%20please%20engage%20with%20using%20the%20project%20site%20on%20GitHub%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fpnpcore%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Epnp%2Fpnpcore%20%7C%20github.com%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThere%20is%20still%20plenty%20to%20do%20in%20the%20SDK%2C%20if%20you%20want%20to%20contribute%20to%20this%20open%20source%20repository%2C%20you%20are%20most%20welcome%20to%2C%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fpnpcore%2Fissues%3Fq%3Dis%253Aissue%2Bis%253Aopen%2Blabel%253A%2522help%2Bwanted%2522%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ewe%20have%20tagged%20areas%20in%20the%20issues%20list%3C%2FA%3E%20for%20areas%20we%20are%20looking%20for%20help%20with%2C%20please%20reach%20out%20either%20on%20social%20media%2C%20via%20GitHub%20to%20connect%20and%20support%20you%20getting%20started.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EEnjoy!%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2207918%22%20slang%3D%22en-US%22%3E%3CP%3EPnP%20Core%20SDK%20is%20a%20library%20designed%20to%20help%20you%20work%20with%20Microsoft%20365%20services%20in%20your%20.NET%20projects%2C%20this%20currently%20focuses%20on%20SharePoint%20and%20Teams%20as%20part%20of%20the%20V1.0%20GA%20release.%20The%20PnP%20Core%20SDK%20is....%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2207918%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EGetting%20started%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Mar 19 2021 12:56 AM
Updated by: