Skip to main content

Creating Azure Websites and Resource Groups from Visual Studio

Author by Christopher Mank

As an application developer, one of the most handy features you'll find in Visual Studio is its integration with Microsoft Azure. When building out a new website and database backend, you can create these Azure resources directly from Visual Studio. While this is a really nice feature, it currently does not give you the ability to create or specify which Azure Resource Group you want to add these new resources to. As a refresher, Resource Groups are container objects that let you group different Azure resources together and manage them as a whole. So when you want to create a new Azure Website, database and other resources, here is what happens when you create them directly from Visual Studio.
  1. From Visual Studio, right-click your Project and select Publish. This will open the Publish Web dialog. When you click the "Microsoft Azure Website" button, you will be prompted to select an existing site or create a new one. As you can see in the screenshot below, we can create a new site and database at the same time.Create Azure Website from Visual Studio
  2. Once we click on the Create button, the resources will be created in Azure. As you can see below, Visual Studio will create a default Resource Group for each object based on the type of object (e.g. SQL, Website, etc.) and the location (e.g. Central US, East US, etc.). If a default Resource Group already exists with that naming convention, the object will be added to that existing Resource Group. Here is a look at the Resource Groups that Visual Studio created from step #1.Default SQL Azure Resource GroupDefault Web Azure Resource Group
This is a really great feature, but the downside is that as of the writing of this post, there is no easy way to move Azure resources around into different Resource Groups or rename Resource Groups. There are some PowerShell cmdlets that let you do this but they are a bit limited and can take some time to work through the nuances. So what's a better way? Create the Azure resources upfront via the Azure portal and then publish your site and database to those new resources. Here's how.
  1. From the New button in the bottom-left, create a new Web App and specify a new Resource Group to add it to.Create Azure Website from Azure Portal
  2. From the New button in the bottom-left, create a new SQL Database and add it to the same Resource Group you created in #1.Create Azure Database from Azure Portal
  3. If we now look at the "MyDemoSite12345" Resource Group, we will now see the resources we just created. Isn't it beautiful?Azure Resource Group
  4. Flip back over to Visual Studio and now when you go to Publish your site, instead of creating a new one, we can select the site and database we just created in the Azure portal.Publish Website to Existing Azure Site in Visual Studio
And there you have it. I am confident that Microsoft will eventually provide the ability to rename or move resources around in Resource Groups. Until that happens, here is a simple way to get it done. Well done, Christopher

Christopher Mank

Systems Architect