protected override void ExecuteCmdlet() { if (!System.IO.Path.IsPathRooted(Path)) { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); } if (System.IO.File.Exists(Path)) { try { var bytes = System.IO.File.ReadAllBytes(Path); TeamsUtility.AddAppAsync(HttpClient, AccessToken, bytes).GetAwaiter().GetResult(); } catch (GraphException ex) { if (ex.Error != null) { throw new PSInvalidOperationException(ex.Error.Message); } else { throw new PSInvalidOperationException(ex.Message); } } } else { new PSArgumentException("File not found"); } }
protected override void ExecuteCmdlet() { var isValidCommSite = Tenant.IsValidCommSite(PortalUrl); ClientContext.ExecuteQueryRetry(); if (!isValidCommSite.Value) { throw new PSInvalidOperationException("The site specified is not a Communication Site"); } var packageName = Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, $"{AppName}.zip"); if (System.IO.File.Exists(packageName) && (Force || ShouldContinue($"File {packageName} exists. Overwrite?", string.Empty))) { System.IO.File.Delete(packageName); } var uri = new Uri(PortalUrl); var host = uri.Host; var searchUrlPath = host; if (uri.LocalPath.Contains("/teams") || uri.LocalPath.Contains("/sites")) { var match = Regex.Match(uri.LocalPath, "^\\/[^\\/]+\\/[^\\/]+"); if (match.Success) { searchUrlPath = host + match.Value; } } if (!System.IO.Path.IsPathRooted(ColoredIconPath)) { ColoredIconPath = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, ColoredIconPath); } if (!System.IO.File.Exists(ColoredIconPath)) { throw new PSArgumentException($"File {ColoredIconPath} does not exist."); } if (!System.IO.Path.IsPathRooted(OutlineIconPath)) { OutlineIconPath = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, OutlineIconPath); } if (!System.IO.File.Exists(OutlineIconPath)) { throw new PSArgumentException($"File {OutlineIconPath} does not exist."); } var modifiedPortalUrl = string.Empty; if (PortalUrl.Contains("?")) { modifiedPortalUrl = PortalUrl + "&app=portals"; } else { modifiedPortalUrl = PortalUrl + "?app=portals"; } if (!ParameterSpecified(nameof(PrivacyPolicyUrl))) { WriteWarning("Privacy Policy link not provided, adding Microsoft privacy link"); } if (!ParameterSpecified(nameof(TermsAndUsagePolicyUrl))) { WriteWarning("Terms and Usage policy link not provided. Adding Microsoft Terms Of Use link."); } var guid = Guid.NewGuid(); var coloredIconFileName = new System.IO.FileInfo(ColoredIconPath).Name; var outlineIconFileName = new System.IO.FileInfo(OutlineIconPath).Name; var appManifest = new AppManifest(); appManifest.Id = guid; appManifest.PackageName = $"com.microsoft.teams.{AppName}"; appManifest.Developer.Name = CompanyName; appManifest.Developer.WebSiteUrl = CompanyWebSiteUrl; appManifest.Developer.PrivacyUrl = PrivacyPolicyUrl; appManifest.Developer.TermsOfUseUrl = TermsAndUsagePolicyUrl; appManifest.Icons.Color = coloredIconFileName; appManifest.Icons.Outline = outlineIconFileName; appManifest.Name.Short = AppName; appManifest.Name.Long = AppName; appManifest.Description.Short = Description; appManifest.Description.Long = LongDescription; appManifest.AccentColor = AccentColor; appManifest.IsFullScreen = true; appManifest.StaticTabs.Add(new AppManifest_Tab() { EntityId = $"sharepointportal_{guid}", Name = $"Portals-{AppName}", ContentUrl = $"https://{host}/_layouts/15/teamslogon.aspx?spfx=true&dest={modifiedPortalUrl}", WebSiteUrl = $"https://{host}/_layouts/15/teamslogon.aspx?spfx=true&dest={PortalUrl}", SearchUrl = $"https://{searchUrlPath}/_layouts/15/search.aspx?q={{searchQuery}}" }); appManifest.ValidDomains.Add(host); appManifest.ValidDomains.Add("*.login.microsoftonline.com"); appManifest.ValidDomains.Add("*.sharepoint.com"); appManifest.ValidDomains.Add("*.sharepoint-df.com"); appManifest.ValidDomains.Add("spoppe-a.akamaihd.net"); appManifest.ValidDomains.Add("spoprod-a.akamaihd.net"); appManifest.ValidDomains.Add("resourceeng.blob.core.windows.net"); appManifest.ValidDomains.Add("msft.spoppe.com"); appManifest.WebApplicationInfo.Add("id", "00000003-0000-0ff1-ce00-000000000000"); appManifest.WebApplicationInfo.Add("resource", $"https://{host}"); var output = JsonSerializer.Serialize(appManifest); if (!System.IO.File.Exists(packageName)) { var tempFolder = Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempFolder); System.IO.File.WriteAllText(System.IO.Path.Combine(tempFolder, "manifest.json"), output); System.IO.File.Copy(ColoredIconPath, System.IO.Path.Combine(tempFolder, coloredIconFileName)); System.IO.File.Copy(OutlineIconPath, System.IO.Path.Combine(tempFolder, outlineIconFileName)); ZipFile.CreateFromDirectory(tempFolder, System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, $"{AppName}.zip")); Directory.Delete(tempFolder, true); } else { throw new PSInvalidOperationException("Cannot create package"); } WriteObject($"Teams app created: {System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, $"{AppName}.zip")}"); if (!NoUpload) { var bytes = System.IO.File.ReadAllBytes(System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, $"{AppName}.zip")); TeamsUtility.AddAppAsync(HttpClient, GraphAccessToken, bytes).GetAwaiter().GetResult(); WriteObject($"Teams app uploaded to teams app Store."); } }