private void InternalExecute() { _packages.Clear(); if (string.IsNullOrEmpty(Url)) { throw new ArgumentException("Url"); } if (IsSharePointOnline) { if (string.IsNullOrEmpty(UserName)) { throw new ArgumentException("UserName"); } if (string.IsNullOrEmpty(UserPassword)) { throw new ArgumentException("UserPassword"); } } var spService = new SharePointService(); spService.WithSharePointContext(Url, UserName, UserPassword, IsSharePointOnline, context => { var repoFolder = AppDomain.CurrentDomain.BaseDirectory; var repo = PackageRepositoryFactory.Default.CreateRepository(repoFolder); // create manager with empty repo to avoid connectivity var packageManager = new DefaultMetaPackSolutionPackageManager(repo, context); //var packages = packageManager.LocalRepository.GetPackages(); var packages = packageManager.LocalRepository.Search( string.Empty, Enumerable.Empty <string>(), this.PreRelease); packages = packages.GroupBy(p => p.Id) .Select(g => g.OrderByDescending(p => p.Version).FirstOrDefault()); packages = packages.Where(p => p != null); foreach (var package in packages) { _packages.Add(package); Out.WriteLine(package.GetFullName()); } }); }
protected virtual MetaPackSolutionPackageManagerBase CreatePackageManager(IPackageRepository repo, ClientContext context) { var packageManager = new DefaultMetaPackSolutionPackageManager(repo, context); // add options packageManager.SolutionOptions.Add(new OptionValue { Name = DefaultOptions.SharePoint.Api.Id, Value = this.SharePointApi }); packageManager.SolutionOptions.Add(new OptionValue { Name = DefaultOptions.SharePoint.Edition.Id, Value = this.SharePointEdition }); packageManager.SolutionOptions.Add(new OptionValue { Name = DefaultOptions.SharePoint.Version.Id, Value = this.SharePointVersion }); packageManager.SolutionOptions.Add(new OptionValue { Name = DefaultOptions.Site.Url.Id, Value = context.Url }); packageManager.SolutionOptions.Add(new OptionValue { Name = DefaultOptions.User.Name.Id, Value = UserName }); packageManager.SolutionOptions.Add(new OptionValue { Name = DefaultOptions.User.Password.Id, Value = UserPassword }); if (!string.IsNullOrEmpty(ToolId)) { packageManager.SolutionToolPackage = new SolutionToolPackage { Id = ToolId, Version = ToolVersion }; } return(packageManager); }
private void InternalExecute() { if (string.IsNullOrEmpty(Source)) { throw new ArgumentException("Source"); } if (string.IsNullOrEmpty(Id)) { throw new ArgumentException("Id"); } if (string.IsNullOrEmpty(Url)) { throw new ArgumentException("Url"); } if (IsSharePointOnline) { if (string.IsNullOrEmpty(UserName)) { throw new ArgumentException("UserName"); } if (string.IsNullOrEmpty(UserPassword)) { throw new ArgumentException("UserPassword"); } } var spService = new SharePointService(); spService.WithSharePointContext(Url, UserName, UserPassword, IsSharePointOnline, context => { // connect to remote repo Out.WriteLine("Connecting to NuGet repository:[{0}]", Source); var repo = PackageRepositoryFactory.Default.CreateRepository(Source); IPackage package = null; if (!string.IsNullOrEmpty(Version)) { Out.WriteLine("Fetching package [{0}] with version [{1}]", Id, Version); package = repo.FindPackage(Id, new SemanticVersion(Version)); } else { Out.WriteLine("Fetching the latest package [{0}]", Id); package = repo.FindPackage(Id); } if (package == null) { Out.WriteLine("Cannot find package [{0}]. Throwing exception.", Id); throw new ArgumentException("package"); } else { Out.WriteLine("Found remote package [{0}].", package.GetFullName()); } Out.WriteLine("Checking local package [{0}]", Id); // create manager with repo and current web site var packageManager = new DefaultMetaPackSolutionPackageManager(repo, context); //var localPackage = packageManager.LocalRepository.FindPackage(package.Id, package.Version, true, true); var localPackages = packageManager.LocalRepository.FindPackagesById(package.Id); var localPackage = localPackages.OrderByDescending(p => p.Version) .FirstOrDefault(); if (localPackage != null) { Out.WriteLine("Found local package [{0}] with version [{1}]", localPackage.Id, localPackage.Version); } if (localPackage == null) { Out.WriteLine("Cannot find local package. Performing install..."); } else { if (localPackage.Version < package.Version) { Out.WriteLine("Local package version is behind remote one: [{0}] < [{1}]", localPackage.Version, package.Version); } else { Out.WriteLine("Local package version greater or equal remote one: [{0}] >= [{1}]. No update is required.", localPackage.Version, package.Version); return; } } Out.WriteLine("Installing package [{0}] to SharePoint web site...", package.GetFullName()); // install package packageManager.InstallPackage(package, false, PreRelease); Out.WriteLine("Completed installation. All good!"); }); }
private void Internal_Deploy_SolutionPackage( MetaPackServiceContext regressionContext, RegressionDeploymentProfile regressionProfile) { var packagingService = regressionContext.PackagingService; var deploymentService = regressionContext.DeploymentService; // create new solution package for this deployment var ciSolutionPackage = CreateNewSolutionPackage(packagingService, regressionProfile.ModelLevel); UpdatePackageVersion(ciSolutionPackage); var packageId = ciSolutionPackage.Id; var packageVersion = ciSolutionPackage.Version; // push to repo PushPackageToCIRepository(ciSolutionPackage, null, packagingService); // find var ciPackage = FindPackageInCIRepository(packageId, packageVersion); Assert.IsNotNull(ciPackage, "Solution package"); var solutionOptions = new List <OptionValue>(); WithCIRepositoryContext(ciNuGetRepository => { // actual deployment callback Action <ClientContext, IPackage, List <OptionValue> > metapackDeployment = (clientContext, package, options) => { var packageManager = new DefaultMetaPackSolutionPackageManager(ciNuGetRepository, clientContext); // configura options packageManager.SolutionOptions.AddRange(options); // install package packageManager.InstallPackage(package, false, false); }; if (regressionProfile.Sandbox == RegressionSandbox.O365) { var siteUrl = O365RootWebUrl; var userName = O365UserName; var userPassword = O365UserPassword; // checking correct model if (regressionProfile.ModelLevel == RegressinModelLevel.Site) { siteUrl = O365RootWebUrl; } else if (regressionProfile.ModelLevel == RegressinModelLevel.Web) { siteUrl = O365RootWebUrl; } else if (regressionProfile.ModelLevel == RegressinModelLevel.Subweb) { siteUrl = O365SubWebUrl; } else { throw new NotImplementedException( string.Format("Unsupported ModelLevel type:[{0}]", regressionProfile.ModelLevel)); } // csom related options solutionOptions.Add(DefaultOptions.SharePoint.Api.CSOM); solutionOptions.Add(DefaultOptions.SharePoint.Edition.Standard); solutionOptions.Add(DefaultOptions.SharePoint.Version.O365); solutionOptions.Add(new OptionValue { Name = DefaultOptions.Site.Url.Id, Value = siteUrl }); solutionOptions.Add(new OptionValue { Name = DefaultOptions.User.Name.Id, Value = userName }); solutionOptions.Add(new OptionValue { Name = DefaultOptions.User.Password.Id, Value = userPassword }); WithCIO365ClientContext(siteUrl, userName, userPassword, context => { metapackDeployment(context, ciPackage, solutionOptions); }); } else if (regressionProfile.Sandbox == RegressionSandbox.SharePoint) { if (regressionProfile.API == RegressionAPI.CSOM) { // csom related options solutionOptions.Add(DefaultOptions.SharePoint.Api.CSOM); solutionOptions.Add(DefaultOptions.SharePoint.Edition.Standard); solutionOptions.Add(DefaultOptions.SharePoint.Version.SP2013); var siteUrl = SP2013RootWebUrl; // checking correct model if (regressionProfile.ModelLevel == RegressinModelLevel.Site) { siteUrl = SP2013RootWebUrl; } else if (regressionProfile.ModelLevel == RegressinModelLevel.Web) { siteUrl = SP2013RootWebUrl; } else if (regressionProfile.ModelLevel == RegressinModelLevel.Subweb) { siteUrl = SP2013SubWebUrl; } else { throw new NotImplementedException( string.Format("Unsupported ModelLevel type:[{0}]", regressionProfile.ModelLevel)); } solutionOptions.Add(new OptionValue { Name = DefaultOptions.Site.Url.Id, Value = siteUrl }); WithCISharePointClientContext(siteUrl, context => { metapackDeployment(context, ciPackage, solutionOptions); }); } else if (regressionProfile.API == RegressionAPI.SSOM) { // csom related options solutionOptions.Add(DefaultOptions.SharePoint.Api.SSOM); solutionOptions.Add(DefaultOptions.SharePoint.Edition.Standard); solutionOptions.Add(DefaultOptions.SharePoint.Version.SP2013); var siteUrl = SP2013RootWebUrl; // checking correct model if (regressionProfile.ModelLevel == RegressinModelLevel.Site) { siteUrl = SP2013RootWebUrl; } else if (regressionProfile.ModelLevel == RegressinModelLevel.Web) { siteUrl = SP2013RootWebUrl; } else if (regressionProfile.ModelLevel == RegressinModelLevel.Subweb) { siteUrl = SP2013SubWebUrl; } else { throw new NotImplementedException( string.Format("Unsupported ModelLevel type:[{0}]", regressionProfile.ModelLevel)); } solutionOptions.Add(new OptionValue { Name = DefaultOptions.Site.Url.Id, Value = siteUrl }); WithCISharePointClientContext(siteUrl, context => { metapackDeployment(context, ciPackage, solutionOptions); }); } else { throw new NotImplementedException( string.Format("Unsupported API type:[{0}]", regressionProfile.API)); } } else { throw new NotImplementedException( string.Format("Unsupported Sandbox type:[{0}]", regressionProfile.Sandbox)); } }); }
public void Install_Package() { // create SharePoint client contex under which MetaPack will be working var siteUrl = "http://contoso-intranet.local"; using (var clientContext = new ClientContext(siteUrl)) { // you can use it with SharePointOnlineCredentials for O365 // as well as NetworkCredential for SP2013 // context.Credentials = new NetworkCredential(userName, securePassword); // context.Credentials = new SharePointOnlineCredentials(userName, securePassword); // create package manager providing client context and NuGet Gallery to work with // for instance, as following: // nuget.org - https://packages.nuget.org/api/v2 // myget.org - https://www.myget.org/F/subpointsolutions-staging/api/v2/package var nuGetRepository = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2"); var packageManager = new DefaultMetaPackSolutionPackageManager(nuGetRepository, clientContext); // get your NuGet package by its ID var nuGetPackage = nuGetRepository.FindPackage("Contoso.Intranet.SiteFields.PnP"); // configure additional options // deployment provider such as PnP or SPMeta2 uses these flags to understand: // - SharePoint version (SP2013, SP2016, O365 // - SharePoint API (CSOM, SSOM for SPMeta2 and CSOM for PnP) // - SharePoint Edition (Standard / Foundation for SPMeta2) var solutionOptions = new List <OptionValue>(); solutionOptions.Add(DefaultOptions.SharePoint.Api.CSOM); solutionOptions.Add(DefaultOptions.SharePoint.Edition.Standard); solutionOptions.Add(DefaultOptions.SharePoint.Version.O365); // target site Url on which youe solution will be deployed solutionOptions.Add(new OptionValue { Name = DefaultOptions.Site.Url.Id, Value = siteUrl }); // provide username/password if needed // deployment provider will use these in conjunction with CSOM deployment // to connect to O365 or local SharePoint via CSOM // if SharePoint version was O365, then SharePointOnlineCredentials will be used // if SharePoint version was Sp2013/2016, then NetworkCredential will be used // if no username/password is provided, then defaultcreds will be used as if you were on SharePoint box itself solutionOptions.Add(new OptionValue { Name = DefaultOptions.User.Name.Id, Value = "*****@*****.**" }); solutionOptions.Add(new OptionValue { Name = DefaultOptions.User.Password.Id, Value = "pass@word1" }); packageManager.SolutionOptions.AddRange(solutionOptions); // install package // metapack will resolve and install all the things for you packageManager.InstallPackage(nuGetPackage, false, false); } }