Follow below steps to create function app via console application:
- Create a Service Principal in Azure:
Open Active Directory=> App Registrations=>create new Registration=> Register a new application.

Go to overview of the newly registered app => copy the client id & Tenant id

And Navigate to Certificates & Secrets, create a new secret and copy the secret value, it'll be used as client_secret.

Try below code to create an Azure function App via console application:
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
clientId: "<your-client-id>",
clientSecret: "<your-client-secret>",
tenantId: "<your-tenant-id>",
environment: AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
// resource group creation
var resourceGroupName = "<resource-group-name>";
var region = Region.AsiaSouthEast;
var resourceGroup = await azure.ResourceGroups.Define(resourceGroupName)
.WithRegion(region)
.CreateAsync();
Console.WriteLine("Resource group created.");
// storage account
var storageAccountName = "<storage-account-name>";
var storageAccount = await azure.StorageAccounts.Define(storageAccountName)
.WithRegion(region)
.WithExistingResourceGroup(resourceGroup)
.CreateAsync();
Console.WriteLine("Storage account created.");
// function app
var functionAppName = "<function-app-name>";
var functionApp = await azure.AppServices.FunctionApps.Define(functionAppName)
.WithRegion(region)
.WithExistingResourceGroup(resourceGroup)
.WithExistingStorageAccount(storageAccount)
.WithRuntimeVersion("~3")
.CreateAsync();
Console.WriteLine("Function app created.");
// you can Deploy the function code from a zip file
var zipFilePath = "functionapp.zip";
using (var fileStream = File.OpenRead(zipFilePath))
{
await functionApp.ZipDeployAsync(fileStream);
}
Console.WriteLine("Function code deployed.");
var functionName = "HelloWorld";
// Get the function URL and key
var function = await functionApp.GetFunctionAsync(functionName);
var url = function.Url;
var key = await function.GetMasterKeyAsync();
Console.WriteLine($"The function URL is: {url}?code={key}");
}
}
}