Please refer to the Introduction to PnP Core Component and OfficeDevPnP.Core for more details. I have created a Console Application and added SharePointPnPCore2016 NuGet package for the SharePoint 2016 version.
Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.SharePoint.Client;
  7. using OfficeDevPnP.Core;
  8. using OfficeDevPnP.Core.Extensions;
  9. using Microsoft.SharePoint.Client.Taxonomy;
  10. namespace SP2016PnPCoreComponentDemo
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. // Input Parameters
  17. string siteUrl = "http://c7395723754/";
  18. string userName = "administrator";
  19. string password = "xxxxxxxx";
  20. string domain = "AD2012";
  21. Guid featureID = new Guid("961d6a9c-4388-4cf2-9733-38ee8c89afd4");
  22. OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
  23. try
  24. {
  25. // Get the client context
  26. using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))
  27. {
  28. // Check if faeture is activated in web
  29. if (ctx.Web.IsFeatureActive(featureID))
  30. {
  31. // Deactivate the feature in web
  32. ctx.Web.DeactivateFeature(featureID);
  33. }
  34. else
  35. {
  36. // Activate the feature in web
  37. ctx.Web.ActivateFeature(featureID);
  38. }
  39. }
  40. }
  41. catch (Exception ex)
  42. {
  43. Console.WriteLine("Error Message: " + ex.Message);
  44. }
  45. }
  46. }
  47. }