Azure / azure-functions-vs-build-sdk

MSBuild task for Azure Functions
MIT License
95 stars 64 forks source link

Suppress the connection warning message when using Managed Identity #524

Open shibayan opened 3 years ago

shibayan commented 3 years ago

When using Managed Identity in Binding / Trigger, you need to specify a nested value prefixed with the connection name. (Example: <CONNECTION_NAME_PREFIX>__serviceUri)

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference#connection-properties

Function Build SDK does not take nested values into account, so even if you add the correct settings to local.settings.json, it will warn you that the connection cannot be found, which is an unnecessary warning.

Build warning

C:\Users\shibayan\.nuget\packages\microsoft.net.sdk.functions\3.0.13\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): 
warning : Function [Function2]: cannot find value named 'CosmosConnection' in local.settings.json that matches 'connection' property set on 'cosmosDBTrigger'

Repro code

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "CosmosConnection__accountEndpoint": "https://***.documents.azure.com:443/"
  }
}
public class Function2
{
    [FunctionName("Function2")]
    public void Run([CosmosDBTrigger(
                        databaseName: "SampleDB",
                        containerName: "TodoItem",
                        Connection = "CosmosConnection",
                        LeaseContainerName = "leases")]
                    IReadOnlyList<TodoItem> items, ILogger log)
    {
        if (items != null && items.Count > 0)
        {
            log.LogInformation("Documents modified " + items.Count);
            log.LogInformation($"First document Id = {items[0].Id}, Title = {items[0].Title}");
        }
    }
}
mattchenderson commented 2 years ago

This looks like it comes from:

https://github.com/Azure/azure-functions-vs-build-sdk/blob/b0e54a832a92119e00a2b1796258fcf88e0d6109/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs#L261

Related changes had to be made to the Core Tools, although those could force the process to exit, while this seems to just be warning level. This should still be fixed. Core Tools PRs for reference in case it's useful in resolution:

huytranbandlab commented 1 year ago

Hello, this issue still happens on version 4.1.3

akimotochan commented 5 months ago

@mattchenderson still happening at 4.3.0 :(

Any guidance?