{"id":1874,"date":"2020-05-25T10:32:40","date_gmt":"2020-05-25T09:32:40","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1874"},"modified":"2020-07-17T11:51:51","modified_gmt":"2020-07-17T10:51:51","slug":"scripting-add-in-packages","status":"publish","type":"post","link":"https:\/\/www.stuartroberts.net\/index.php\/2020\/05\/25\/scripting-add-in-packages\/","title":{"rendered":"Scripting Add-Ins for Deployment"},"content":{"rendered":"\n<p>Scripting the creation of SharePoint add-in packages is pretty straight forward. As I found there to be not very many posts on this topic, I thought I&#8217;d share how I implemented it.<\/p>\n\n\n\n<p>To create and deploy is also easy from a developers box, all of this is achievable from inside Visual Studio.<\/p>\n\n\n\n<p>The purpose of this post is to show how you would go about creating packages to be deployed on downstream environments.<\/p>\n\n\n\n<p>I&#8217;m not going to go into the creation of certificates or the add-in client id. I&#8217;m going to take it for granted that if you&#8217;ve got to this stage, you already know how to do all of that.<\/p>\n\n\n\n<p>Lets say you have a solution with one add-in and related web and you want to be able to script the creation of the packages to your UA environment.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2>Configure Add-In Profile<\/h2>\n\n\n\n<p>In Visual Studio, right click the add-in project and choose Publish. From the Publish your add-in page, choose New from the current profile drop down.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"602\" height=\"374\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Create-AddInProfile.png\" alt=\"\" class=\"wp-image-1880\" srcset=\"https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Create-AddInProfile.png 602w, https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Create-AddInProfile-300x186.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p>Populate the profile with the certificate details for the environment you&#8217;re wanting to package for and click Finish.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"584\" height=\"493\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Save-AddInProfile.png\" alt=\"\" class=\"wp-image-1883\" srcset=\"https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Save-AddInProfile.png 584w, https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Save-AddInProfile-300x253.png 300w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/figure>\n\n\n\n<h2>Configure Remote Web Profile<\/h2>\n\n\n\n<p>Next we need to configure the web part of the profile. Locate the web project for your add-in and right click it and once again then choose  Publish.<\/p>\n\n\n\n<p>At the top of the page that loads, click New to launch the <em>Pick a publish target<\/em> dialog. From there, select IIS, FTP, etc and then Create Profile.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"902\" height=\"601\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Create-WebProfile.png\" alt=\"\" class=\"wp-image-1884\" srcset=\"https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Create-WebProfile.png 902w, https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Create-WebProfile-300x200.png 300w, https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Create-WebProfile-768x512.png 768w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Change the <em>Publish method<\/em> to Web Deploy Package, then set a package location and the target web application path.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"685\" height=\"282\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Set-CustomProfile.png\" alt=\"\" class=\"wp-image-1885\" srcset=\"https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Set-CustomProfile.png 685w, https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/Set-CustomProfile-300x124.png 300w\" sizes=\"(max-width: 685px) 100vw, 685px\" \/><\/figure>\n\n\n\n<p>Click Next and choose the configuration profile for this build. Finally click save to complete the profile for this add-in and web.<\/p>\n\n\n\n<p>In the Solution Explorer pane, expand the Properties\\PublishProfiles folder within the web project. Here you&#8217;ll see the profile that you created above.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"317\" height=\"150\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/CustomWebProfile.png\" alt=\"\" class=\"wp-image-1886\" srcset=\"https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/CustomWebProfile.png 317w, https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/CustomWebProfile-300x142.png 300w\" sizes=\"(max-width: 317px) 100vw, 317px\" \/><\/figure>\n\n\n\n<p>If you open this file, you&#8217;ll see all of the settings you entered for the add-in and web projects.<\/p>\n\n\n\n<h2>Scripting Package Creation<\/h2>\n\n\n\n<p>We&#8217;ll be using msbuild to script the creation of the packages for the add-in<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n#Change to thefolder that contains the add-in project file\ncd &quot;C:\\location of the projects&quot;\n\n# Build and create the packages for the add-in and web\n&amp; &quot;C:\\path to msbuild\\msbuild&quot; \/t:addinproject.csproj \/p:IsPackaging=True \/p:DeployOnBuild=false \/property:Configuration=Release \/p:PublishDir=C:\\PublishFolder \/p:ActivePublishProfile=CustomProfile\n<\/pre><\/div>\n\n\n<div class=\"is-layout-flow wp-block-group\"><div class=\"wp-block-group__inner-container\">\n<figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>IsPackaging<\/td><td>Set to True to create the packages after the build<\/td><\/tr><tr><td>DeployOnBuild<\/td><td>We don&#8217;t want to deploy anywhere during this process, so set this to False<\/td><\/tr><tr><td>Configuration<\/td><td>The solution configuration name<\/td><\/tr><tr><td>PublishDir<\/td><td>The location to publish the packages to.<br>If you set this to C:\\Packages\\AddIn msbuild will create a folder called C:\\Packages\\AddIn1.0.0.0<br>Basically it appends the version of the add-in the this path<\/td><\/tr><tr><td>ActivePublishProfile<\/td><td>The name of the publishing profile that you created previously<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div><\/div>\n\n\n\n<p>Once packing has completed, go to the folder you provided for PublishDir above. Here you should see 6 files:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"344\" height=\"174\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/PackageFiles.png\" alt=\"\" class=\"wp-image-1887\" srcset=\"https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/PackageFiles.png 344w, https:\/\/www.stuartroberts.net\/wp-content\/uploads\/2020\/03\/PackageFiles-300x152.png 300w\" sizes=\"(max-width: 344px) 100vw, 344px\" \/><\/figure>\n\n\n\n<p>If you open the SetParameters.xml file you&#8217;ll see all the settings for the profile you targeted in the packaging process. This will be used when deploying with the web.deploy.cmd batch file.<\/p>\n\n\n\n<h2>Deploy the Web Application<\/h2>\n\n\n\n<p>To deploy the web site you&#8217;ll need Web Deploy installed. The latest version for this can be downloaded from <a rel=\"noreferrer noopener\" aria-label=\"here (opens in a new tab)\" href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=43717\" target=\"_blank\">here<\/a>, adding the location to the msdeploy.exe executable to the path environment variable.<\/p>\n\n\n\n<p>To test run the deployment, similar to running a cmdlet with -whatif<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nMyAddIn.Web.Deploy.cmd \/T\n<\/pre><\/div>\n\n\n<p>To perform the deployment:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nMyAddIn.Web.Deploy.cmd \/Y\n<\/pre><\/div>\n\n\n<p>There are also parameters here to specify the username and password, lots of info in the deploy-readme.txt file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scripting the creation of SharePoint add-in packages is pretty straight forward. As I found there to be not very many posts on this topic, I thought I&#8217;d share how I implemented it. To create and deploy is also easy from &hellip; <a href=\"https:\/\/www.stuartroberts.net\/index.php\/2020\/05\/25\/scripting-add-in-packages\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[96,3],"tags":[94,21,98,93,100],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-ue","_links":{"self":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1874"}],"collection":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1874"}],"version-history":[{"count":7,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1874\/revisions"}],"predecessor-version":[{"id":1934,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1874\/revisions\/1934"}],"wp:attachment":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}