简体   繁体   中英

How do I create an Azure Website and SQL Database programmatically?

Thanks for looking.

I have a need to be able to create new Azure website and database instances from a Windows forms application I have created as an internal-use tool.

I am not sure if there is a C# API for this or if I need to use Powershell or some other CLI, but I would appreciate any advice.

All of the searching I have done on the subject has not turned up a simple, direct explanation as to how to do this or if it is even possible.

Using Azure Resource Manager (ARM) API's is the way to go these days - especially with your scenario. You've probably seen documentation that uses the old Service Management API's to do this. You could still do this, but I would strongly discourage it. ARM is where the investment in automation is landing going forward.

For your particular scenario, there is actually a tutorial here .

If you are using Visual Studio 2013 or 2015, then you can also use the ARM templates that it provides. For example, from Visual Studio, select File > New > Project and choose the Azure Resource Group project template.

在此处输入图片说明

The next window in the new project dialog is where you can select from some common deployment templates, such as what you are looking for, which is a Web App + SQL Database .

在此处输入图片说明

This project will contain the ARM template that describes your environment and a script that you can use to invoke ARM to deploy it.

To deploy the environment, right-click on the project in Visual Studio and select Deploy. Fill in the parameters that the template provides and you are on your way. If you look in the script that is generated (Deploy-AzureResourceGroup.ps1), you will see at the bottom of the script a call to New-AzureResourceGroup . What this does is basically merge your ARM template and parameters together and then sends them to Azure Resource Manager to provision the environment. In other words, you have everything here to automate this without having to do it from Visual Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM