Publish Azure Website to non-root folder from PowerShell - asp.net-mvc

I'm testing my assumptions at the moment. I have my Asp.Net MVC application located at www.myapp.com/app and a third-party CMS system on www.myapp.com/.
The web-site is set up like described in this answer
At the moment I can publish both of the applications separately and manually from Visual Studio and it works fine.
However, I'm trying to publish my application from a build server where I'm using Azure Power-Shell scriplets:
PS> Publish-AzureWebsiteProject -Name myApp -Package MyWebDeployPackage.zip
However, documentation does not mention if you can publish with this scriplet to a non-root folder.
Any way I can publish an application to ~/app from a command line?
UPD: I can publish from msbuild via
msbuild .\SolutionName.sln /p:DeployOnBuild=true /p:PublishProfile=ProfileName /p:Password=passwordForAzurePublishing /p:AllowUntrustedCertificate=true
Where ProfileName is a web-deploy profile configured to deploy to sub-folder of Azure Web-Site and Password is deployment password from Azure profile.
However this is not an optimal solution: to deploy to test and to production environment, I need to build the application twice, which I'd like to avoid: if I compile views, it takes 7-10 minutes (we have 800 views). Doing this twice is a waste of time.
UPD 2: Created an issue on Azure SDK Tools repository: https://github.com/Azure/azure-sdk-tools/issues/2667

I don't think this is possible from PowerShell, but I might be mistaken. Looking at their publish code here https://github.com/Azure/azure-sdk-tools/blob/master/src/ServiceManagement/Services/Commands.Utilities/Websites/WebsitesClient.cs#L1136-L1168
and also here https://github.com/Azure/azure-sdk-tools/blob/master/src/ServiceManagement/Services/Commands.Utilities/Websites/WebsitesClient.cs#L1218-L1229
they don't have a parameter for the app name, and the code in the second link builds the site name/slot manually.
I would say open an issue here https://github.com/Azure/azure-sdk-tools/issues for this and somebody from the Azure PowerShell team should look at it.

Related

Azure web app publish with Visual Studio - not including all files

I have an MVC project being published to Azure from Visual Studio as a web app. In the solution I have a project set up as a "plugin" which is used by the web application and installed using Unity DI. Locally this works but when I publish to azure the plugin files aren't being deployed. This is how my solution and project structure is setup:
Solution MyProject
>nuget
>...
>Plugins
>Plugin.Widget.GoogleAnalytics
>MyProject.Web
>Properties
>References
>...
>Plugins
>bin
>Plugin.Widget.GoogleAnalytics (excluded from project but copied to this directory after project is built above)
>Views
>...
Web.config
Running locally if I delete Solution MyProject/MyProject.Web/Plugins/Plugin.Widget.GoogleAnalytics after is compiled the plugin doesn't appear. If I copy the contents of Solution MyProject/Plugins/Plugin.Widget.GoogleAnalytics/bin back into Solution MyProject/MyProject.Web/Plugins/Plugin.Widget.GoogleAnalytics, the plugin reappears.
The problem is, when I publish to my azure web app, it doesn't include Solution MyProject/MyProject.Web/Plugins/Plugin.Widget.GoogleAnalytics. If I FTP that directory up from my computer is still doesn't load it after restarting the app.
I've tried to include Solution MyProject/MyProject.Web/Plugins/Plugin.Widget.GoogleAnalytics in the project but it causes compilation problems since it's supposed to be added by DI and it also doesn't work after publish.
Is there a way to include the necessary files (not included in the project) during a publish so what works locally will work on azure? Or is there another way to go about this.
If I don't check the option on publish to Remove additional files at destination it usually throws this error when the site tries to load:
Method not found: 'Microsoft.Practices.Unity.IUnityContainer MyProject.Core.ContainerManager.GetConfiguredContainer()'
I've tried to debug that but it's very difficult since it only happens on the azure web app.
I found this question but it didn't give any information for this issues.
EDIT
I was able to get the plugin to work on azure by following these steps.
1) Run in dev environment locally in Debug mode.
2) Publish to azure as debug build.
3) FTP web application plugin directory to azure.
4) Restart azure app. It runs in azure but it's a debug build.
5) Publish from local dev environment as release build.
After this, I was able to publish as release build and check Remove additional files at destination. This removes the plugins in azure. Then I FTP'd the web application plugin directory to azure and start and stop web app and it works. Maybe I can take the debug steps out of this but this is working now.
Heinrich,
Can you please try this below step and see it works.
Make sure you set the build action to Content and they will get deployed.
Try deploying in release mode.
Hope it helps.
MV

Deploy published mvc application as Azure Web App programatically

I have published my MVC application and now I want to deploy the same as Azure Web App.
I want my customers to open a .bat file in which they will be prompted for Azure Publish Settings and deploy the application.
I dont want to do the below.
Deploy the solution directly from Visual Studio
Use MsDeploy or MSBuild to build the solution with publish profiles like the below and publish in Azure
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe "I:\MyProject\MyProject.sln" /p:DeployOnBuild=true /p:PublishProfile=Production /p:Password=Mu50vKJfDdKfGsFvj5erC0awdxAi /p:AllowUntrustedCertificate=true /p:VisualStudioVersion=12.0
Can anyone suggest a solution ?
Thanks,
R. Venkatesan
There are several tools you can use to deploy a web app from the command line :
Azure CLI : https://azure.microsoft.com/en-us/documentation/articles/web-sites-deploy/#cli
Web Deploy Command Line : https://azure.microsoft.com/en-us/documentation/articles/web-sites-deploy/#webdeploy
I would prefer use a custom script that use Azure CLI so your customer will be asked for login to Azure instead of providing publish settings file.
Hope this helps,
Julien

Build and Deploy a Web Application with TFS 2015 Build

We have just installed TFS 2015 (Update 1) on-premise and are trying to create a Continuous Integration/Build system using the new TFS Build system. The build works fine, and gives me a green light, but when I look at the default build it has only built the binaries from the bin directory, and there seems to be no easy way to deploy the app on-premise to a local server.
There are two deploy options for a filesystem copy, and a powershell script, and it would certainly be easy enough to use them to copy files to a new server, but since the build only built the binaries, I don't see a tool to gather up the Web artifacts (cshtml, images, scripts, css, etc..) for this.
After an exhaustive google search, I've only found one article which talks about this at:
http://www.deliveron.com/blog/building-websites-team-foundation-build-2015/
However, this uses WebDeploy and creates a rather messy deploy package.
How can I deploy the site (standard MVC web application, in fact my tests are using the default boilerplate site created by the create project wizard) complete with artifacts to a local server in the easiest possible way? I don't want to have to install WebDeploy on the servers, and would rather use PowerShell or something to deploy the final artifacts.
The build is just the standard Visual Studio build template, with 4 steps (Build, Test, Index & Publish, Publish Build Artifacts).
We use "Visual Studio Build" step and as Arguments for MSBuild we use following line:
/p:DeployOnBuild=True /p:PublishProfile=$(DeploymentConfiguration)
On Variables tab page DeploymentConfiguration has to be configured. It must be the Name of the publish Profile (filename of the pubxml file). If the file Name is Build.pubxml the publish profile is Build.
for example:
/p:DeployOnBuild=True /p:PublishProfile=Build
I wanted to add that Ben Day has an excellent write-up that helped us package quickly and then release to multiple environments through Release Manager.
His msbuild arguments look like this:
/p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=$(build.artifactstagingdirectory)\for-deploy\website
The difference between this and the accepted answer is that this parameter set stages everything in an artifacts folder, and then saves it as part of the build. We can then deploy exactly the same code repeatedly.
We capture the web.env.config files alongside the for-deploy folder and then use xdt transforms in the release process to ensure everything gets updated for whichever environment we're deploying to. It works well for all our web projects.
We use WebDeploy/MSDeploy for 40+ applications and love it. We do install WebDeploy on all our servers so we can deploy more easily but you could also use the Web Deploy On Demand feature which doesn't require WebDeploy be pre-installed.

Generating nuget-packages for Octopus Deploy and Azure Cloud Services

I've been trying for a week to deploy a webrole to Azure Clous Services without quite getting there.
Here is my setup:
I've got a cloud solution with a cloud project and a MVC application (standard no changes to template yet). Its under source control in Visual Studio Online.
I'm using octopack to try generating the nuget package
I'm using the buildt in nuget repo from Octopus
The Octopus server and tentacle is hosted on a VM in azure
I've created a step-template for my deployment step (see this article)
My plan:
I'd like to have a CI build to a dev-service and a seperate build to push my project to the staging environment and roll it onto the production environment using Octopus.
My problem:
The packages that are produced by Octopack seems to not contain what they should. And I've tried to play around with the nuspec file included in my webrole to get it just right. Something ends up missing either way i try.
Have anyone gotten this to work? I'd appreciate any tips pointing me in the right direction as I've slowly been running out of ideas. So i turn to you my fellow nerdlings for some much needed help.
Regards
ZiGGstern
Correct me if I'm wrong but it looks like you're in need of the octo.exe to automate deployments after build within Visual Studio/TFS Online to your target environments.
I'm trying to focus on this statement:
I'd like to have a CI build to a dev-service and a seperate build to
push my project to the staging environment and roll it onto the
production environment using Octopus.
You can configure within your build-template, using the "Post-Deploy Script Path" a PowerShell script to call the Octo.exe (with an API Key) and fire off a deployment for your desired environment(s). You can customize this per build if you so choose. I've used this method by creating a folder within the root of my Solution (I call it 'Tools' but the name doesn't matter). Within that Tools folder, I add a PowerShell script AND the octo.exe. The PS script fires the Octo.exe which makes a call to my Octopus Server and with the "create release" option, I'm able to automatically deploy to whatever environment AFTER my build finishes within TFS. Make sure to always include those files (right-click in VS and in file properties select 'always copy').
I'm not quite sure why your NuGet packages would not be configured correctly, but that should be remedied first. Your question is trying to ask for two things and it's not clear which is more important to you; NuGet package or the Deployment from CI build. Having said that, I think you need to give more details on why you think your NuGet package is inadequate or not working correctly for your Azure services.
Please note, the site you supplied is using a custom PowerShell script in the form of a step template. It may be best to try the default Azure step within Octopus first before using a customized script. Just a thought.
Read more about the Octo.exe here: http://docs.octopusdeploy.com/pages/viewpage.action?pageId=360596

Deploying Web Applications using Team Build and Web Deploy

So, here is the deal. In web app project settings I configured a deployment package which includes all content files along with IIS settings for the site & app pool. Now, when i go to Team Build build config, I use the following arguments to deploy the site.
/p:UseWPP_CopyWebApplication=True
/p:PipelineDependsOnBuild=False
/p:DeployOnBuild=True
/p:DeployTarget=MsDeployPublish
/p:CreatePackageOnPublish=True
/p:MSDeployPublishMethod=WMSVC
/p:MSDeployServiceUrl=https://<servername>:8172/MsDeploy.axd
/p:AllowUntrustedCertificate=True
/p:DeployIisAppPath="mysite.com"
/p:UserName=<domain>\<user>
/p:Password=<password>
While this actually works, the deployment will fail if "mysite.com" site doesn't exist on the destination server or if the app pool isn't set up correctly (i.e. ASP.NET version mismatch). So i find myself creating this stuff manually before i can deploy anything from Team Build. Is there a way to automate this? Am i missing some kind of argument switch? I guess another way to phrase this question, is why do i have to set all this up when the package includes all of IIS settings and should just deploy.
Thanks for any help/explanation.
EDIT:
I'm not entirely sure if this is true, but i believe i will not be able to do create site/app pool. From my understanding of things, Team Build uses msbuild to talk to msdeploy and that link is very limited in what it can do. So, I may be looking at changing the build workflow template to execute the command line to deploy the package (?).
Check out the TechNet documentation on the iisApp provider at
http://technet.microsoft.com/en-us/library/dd569054(WS.10).aspx. Of the four parameters, these are the ones you'd probably be interested in:
managedRuntimeVersion
skipAppCreation

Resources