How to deploy Azure WebJob using different configurations for different environments in Visual Studio - visual-studio

We have several Web Apps and WebJobs with different configurations for different environment, e.g. Test and Release.
Each WebJob is deployed to a Web App using "Publish as Azure WebJob" in Visual Studio.
We are using the Config Transform extension to transform the App.config that consist of different config sections, connection strings and app settings that needs to be transformed. This works fine for local Debug and for Release.
The problem is that when we use "Publish as Azure WebJob" there is no way to specify which configuration to use and Release is always built and published even if Test is selected inside Visual Studio.
We have also tried to deploy the WebJob together with the Web App but it almost always hangs, same as described in Stuck when publishing Web App to Azure with WebJob
We don't need to use config transform if that's not possible, e.g. we could configure directly in Azure. But I haven't found a way to configure config sections directly in Azure.

Yes this is a known VS tooling pain point that comes up often. The short answer is that web.config style transforms aren't supported for general application types like Console apps.
This has been discussed recently in the context of WebJobs in our public repo here. That issue also links to the VS User Voice issue for this. That item also links to the SlowCheetah VS extension which some users have said works for them. You might give that a try.
If that doesn't work for you, then you'll have to manually manage your settings via the app settings blade in the Azure portal.

I added a prebuild step to change the webjob-publishing-setting.json file and the app.config file depending on which Configuration is selected.
The webjob-publishing-settings.json only had the name. Then from Visual Studio 2019 I used "Publish as Azure WebJob" and that created a second webjob with the new name and new configuration.
Works great!

Related

Deploying VirtoCommerce.Manager to Azure from Visual Studio

I am working with Virto Commerce server 2.4.561 and I'm having a great deal of difficulty successfully publishing to Azure from Visual Studio. Based on the documentation provided, it's not clear to me what the appropriate method is. Most guidance related to Azure assumes that I am using Git deployment. But in this case I am not. I am coding locally on my dev machine and I would like to be able to use web deployment to deploy directly to Azure from Visual Studio. However, the guidance found here seems to suggest that if you want to do your own deployment, you need to use deploy.cmd. I'm not exactly sure why that is. I can only guess that it has something to do with how the modules need to be packaged up.
I am able to run deploy.cmd and it appears to succeed, but I end up with an artifacts folder with 2,000+ files and folders in it and I am left to use old-school FTP to sync all those files up with the Azure website. Is this how it is meant to be done? I have tried to deploy directly from Visual Studio to Azure, and it appears to succeed, but the site does not behave correctly. Specifically, the custom modules I've built don't load correctly.
What is the right way to do this?
There is a way to publish your custom module directly from Visual Studio, but you still need a working Virto Commerce in Azure beforehand, and the easiest way to set it up is to use the Deploy to Azure button in GitHub.
In the Azure portal create a new virtual application /MyModule with
physical path site\wwwroot\admin\Modules\MyModule. It will be used
for publishing a custom module.
Download the source code from GitHub with the same version as you have published to Azure, add your custom module to the solution and build it.
In Visual Studio right-click on your module project and select Publish.
On the Profile screen select Microsoft Azure Web Apps as a publish target and select your Azure Web App.
On the Connection screen select Web Deploy as a publish method and add /Module to the site name. So your site name should look like this: myvc/MyModule.
On the Preview screen click the Start Preview button and make sure the file list contains only files related to your module and the action is Add for each of them.
When you click the Publish button, Visual Studio will upload all module files to the physical directory configured for the virtual application myvc/MyModule. For subsequent publishing it will upload only modified files.
Update: You should restart the Web App via the Azure portal after publishing in order to load the new version of your code into the application. Thanks to N1njaB0b for reminding.

Set Up Continuous Integration From VSO to Azure, but Website does not deploy

I have an azure website that I have successfully linked to a team project in VSO. When I go to the "deployments" tab of this site in azure management, it says:
The team project is linked. Visual Studio Online will build and deploy
your project to Windows Azure on your next check-in.
Below, it gives options to check in from VS2012 or 2010. I am using VS 2013.
In VS, I am able to check in changes and see those changes building in the cloud in the team explorer. My expectation is that after the changes build, they should be auto deployed to the website. This is not happening. I have made several checkins, and none are deployed to the website. It's probably that I have something configured incorrectly, but I'm not sure how to debug this.
In the Build Settings I am using the TFvcContinuousDeploymentTemplate.12.xaml build process template. One thing I did notice is that the under the Deployment Parameters, I noticed that Windows Azure Deployment Environment is empty, but if I try to populate that I'm not sure what to enter for "Web site name" or "Webspace" under the web site radio buttom.
I have followed instructions on these websites to no avail:
http://azure.microsoft.com/en-us/documentation/articles/cloud-services-continuous-delivery-use-vso/
http://channel9.msdn.com/Events/Build/2014/3-584
http://www.visualstudio.com/en-us/get-started/deploy-to-azure-vs.aspx
How can I check on the status of the deployment? How can I make sure that the project/solution is correctly configured to deploy/publish and not just build?
Some additional info:
To set up the continuous deploy, I goto azure management portal, click websites, open the website in question. Click the Deployments tab. It says "The team project is linked, Visual studio online will build and deploy your project to Windows Azure on your next check in". Under YOUR SERVER is lists the correct visual studio online URL for my source project (https://------.visualstudio.com). This is my first time trying CD. It has not successfully deployed yet, but the build is working. Every time I check in changes, a cloud build is triggered and it is successful.
I'm new to this, so I am likely making some unfounded assumption, but after going through the instructions multiple times I'm not sure what I can be missing.
Thank you!
l19 has the right idea in the comment responding to my post. I needed to specify a Windows Azure Deployment Environment. The website name is the name of the website. Webspace is a bit trickier, and unfortunately the documentation link in visual studio redirects to a not found page. This has to be precise (e.g., "west us" won't work). I was able to figure out the proper string by creating a new project from azure and associating it with vso from the start. In this case, the build definition was correctly configured. I opened the Windows Azure Deployment Environment and saw that the webspace was set to "eastuswebspace", so I used the same string in my real build definition and it worked.

WCF IIS configuration and Visual Studio 2010 debug configuration

I am trying to set up my WCF service (.svc) to work in Visual Studio 2010 (pressing F5 to debug), but also to have multiple configurations for each environments (DEV, QA, UAT & Prod). When I originally built the WCF it was used purely in Visual Studio 2010 using .Net version 4 and debugging the service was easy enough by adding a WinForm application to pass in the values needed. When it was time to test the service on a server, I used the Publish feature to put the files on the DEV server and noticed that since it was using IIS that a web.config was created in the base directory.
So now that we are moving on to QA and UAT I need to make sure we have the configuration files for each environment as the Uri's change as well as various other values. Now after searching for a few days on Google, I have tried to use the XDT Transformations, but without having a third party add-in like SlowCheetah, this does not seem to work as it is only built for Web Applications. I have also tried to set up a post-build event to copy different configs:
copy "$(ProjectDir)Config\web.$(ConfigurationName).config" "$(ProjectDir)web.config" /Y
The copy process is set in the Build Events --> Post-build event command line textbox, however this does not seem to work when I use the publish method. I am ok with using multiple config files and copying them, I just have not had success with this.
The XDT makes the most sense to me and would be my preference if I could get it working. The main issue I am having is that it needs to work in Visual Studio, but also to work via IIS on the servers without having to go through a bunch of steps per environment. This is a company rule that I have to follow as well as not having a third party plug-in/add-in.
Is it possible to run the service in IIS and create a servicehost via code? I don't think it is as I believe the MSDN docs say that IIS creates it for you no matter what. Part of my reason wanting to do different configs is so that the page the user gets when they view the .svc file in the browser has the correct Uri in it not the machine name version.
TIA
EDIT: Setting up a dev web.config and including it in the project and then setting it to Build Action: Content fixes the copy method, so technically I have it working as long as I have completely different web.config files for each environment and an app.config for debugging (F5 in Visual Studio).

How do I debug my Azure web role in Visual Studio 2012?

I know this is probably something really stupid, but I've been searching google for 2 hours to figure this out.
I have a new test Azure app that I would like to debug in Visual Studio. If I set the startup project to the Web Role (MVC) project, I can hit breakpoints in VS, but it's not running in the emulator so all of my Azure calls fail.
If I set the startup project to the Cloud project, the emulator starts, then Visual Studio ends debugging and my web role is never launched.
What am I missing here? How do I launch my web page and still have access to the emulator?
(Side note.. why isn't there a Visual Studio 2012 tag??)
Although this doesn't answer your question directly, I always make sure that my projects run outside of the emulator. If for nothing else, this just greatly improves the efficiency of your development.
To avoid the issue of the Azure calls failing, one very basic practice you can use is to use a Dependency Injection framework (such as Unity or others) and create a LocalConfigurationManager and a AzureConfigurationManager which both implement some interface like IConfigurationManager, then if your code needs to ask Azure for an instance number, or config setting, etc... the LocalConfigurationManager can just return a hard coded number/setting, and the real AzureConfigurationManager will actually call Azure.
The trick is to use the Web.Debug.Config and Web.Prod.Config files (or perhaps just use the #IF DEBUG C# precompiler statement) to change the implementation depending on the build config.
I have just created a Azure project with an MVC Web Role and I was able to hit a breakpoint in a controller action without any issues. Some things to check:
Do you have a WebRole.cs file in your MVC project containing a class derived from RoleEntryPoint?
Is there a node in the Roles folder of the Azure project representing your MVC project?
When you run the Azure project does the Compute and Storage emulator icon show up in the Notification Area of the taskbar?
Does the ServiceDefinition.csdef file in your Azure project contain a Web Role node with an attribute matching your MVC project name?
WebRole name="MvcWebRole1" vmsize="Small"
As a quick test try creating a new Azure project with a MVC Web Role, add a controller with a single action that returns a view and put a breakpoint in there. Then set your Azure project as the "Startup Project". If everything is working correctly you should hit the breakpoint when you debug the Azure project.
I un-installed and re-installed all my Azure SDK's, to no avail.
This link
Debugging Azure: Error attaching the debugger to the IIS worker proccess
told me where to look for the error that was causing it to fail, which led me to this link:
http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/07fe087e-4ac3-4c4f-bd62-4fccff4afd45
The ACL on the Windows Azure registry entries were not in "canonical order".
All you have to do is fix that and this error goes away.
These are the steps I took:
1.) regedit, navigate to HKLM\Software\Microsoft\Windows\Windows Azure
2.) Right-click, choose "Permissions". You will get a warning that the
security information is incorrect and you get a button labelled "Re-Order".
Click this and the security information then shows up as normal.
3.) Follow the same steps for the Windows Azure AppFabric and Windows Azure Emulator
registry entries in the list after the Windows Azure entry.
Problem Solved!
Note that I found the key under HKLM\Software\Microsoft\Windows Azure, not under Windows\Windows Azure.

Configuration File Transformation with Azure Worker Roles

I've just been upgrading an Azure project to Visual Studio 2010 and have been taking advantage of the new XML configuration transformation feature that is built into VS2010 web projects. It seems to work great with Azure web roles. I even managed to get the Azure project service configuration file to do a similar thing by following the instructions here.
However, I can't seem to get configuration transformation working for the lone worker role in my Azure project. I know that VS2010 only has built-in support for config transformation with web roles, but I found a good article describing how to get config transformations working with non-web projects. I've followed the instructions and it works - but only to a point. It successfully spits out the correct .config file (with appropriate transformations) into the worker role project's own bin directory, but it doesn't pick this new .config file up when it's put into the cloud package.
I suspect there's some MSBuild trickery needed to get this to work, but I don't know MSBuild very well, so am appealing to any gurus out there for help and/or samples :)
I have found the best way to do this is to use msbuild. I usually do this with a separate msbuild file outside my solution so I keep the local dev settings separate from the production settings. You can find out more here. I then can run the build to change the settings and upload the project to Azure. I can also run this to change the settings and then run deploy through VS if I need to debug the problem. I also have a target in the msbuild file that then can revert everything back to local. It would be nice to have these things in VS (which I have asked for from the product team). The sample project is on github.
This is also explained in the book we wrote in the Life Cycle chapter.

Resources