Azure Functions not be overwritten by new content published from VS?

azure functions tools for visual studio 2019
create azure function in visual studio 2015
azure functions core tools
azure functions running locally but not in azure
deploy azure function from visual studio code
debug azure functions visual studio 2017
run azure functions locally
azure function v1 vs v2

I have an Azure Function App with an HTTP Trigger that receives an automated HTTP message, logs the message to Blob storage, and then returns a simple XML SOAP envelope response that acknowledges receipt of the HTTP message. Here is the code. The commented out code is other ways I've tried to get this to work but which was also unsuccessful.

When I test this code locally it works properly and returns the XML response. However, when I publish it to Azure it simply returns "200" in the response body. In a previous iteration of this function I was returning that "200" string in the body so I wonder if I'm simply failing to publish to Azure properly. I have checked the Azure Activity Logs and see updates to my app that correspond to my publishing attempts.

I am running .Net 4.6.1 and .Net SDK 1.0.11

using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Blob;

namespace MyFunctionsApp
{
    public static class MyNotifications
    {
        [FunctionName("MyHttpTrigger")]
        public static async Task<HttpResponseMessage> MyHttpTrigger(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req,
            [Blob("my-notifications", Connection = "StorageConnectionString")] CloudBlobContainer container,
            TraceWriter log)
        {
            log.Info("The MyHttpTrigger function was triggered.");
            var blobName = $"{DateTime.UtcNow.ToString("o")}-{CreateGuid()}";

            var blockBlobReference = container.GetBlockBlobReference(blobName);
            using (Stream stream = await req.Content.ReadAsStreamAsync())
            {   
                await blockBlobReference.UploadFromStreamAsync(stream);
            }

            // Tried using a StringBuilder to assemble my XML response in case there was an error with my formatting (double quotes etc...).
            StringBuilder xmlBuilder = new StringBuilder();
            xmlBuilder.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            xmlBuilder.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">");
            xmlBuilder.Append("<soapenv:Body>");
            xmlBuilder.Append("<ReceiveNotificationResponse xmlns=\"http://apps.myapp.net/services/subscribers\" />");
            xmlBuilder.Append("</soapenv:Body>");
            xmlBuilder.Append("</soapenv:Envelope>");


            // Tried writing the XML response inline.
            //var xmlResponse = @"<?xml version=""1.0"" encoding=""utf-8""?>
            //            <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
            //            <soapenv:Body>
            //                <ReceiveNotificationResponse xmlns=""http://apps.MyAppName.net/services/subscribers"" />
            //            </soapenv:Body>
            //            </soapenv:Envelope>
            //        ";
            var response = new HttpResponseMessage
            {
                //StatusCode = HttpStatusCode.OK,
                Content = new StringContent(xmlBuilder.ToString(), Encoding.UTF8, "text/xml")

                // Tried reading the XML response from a .xml file
                // Content = new StringContent(File.ReadAllText("../../../../MyFunctionsApp/XmlResponseMessage.xml")),
            };

            // Set additional headers
            //response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
            //response.Content.Headers.ContentType.CharSet = "utf-8";
            //response.Content.Headers.Add("Content-Type", "text/xml");
            return response;
        }

        private static Guid CreateGuid()
        {
            Guid guid = Guid.NewGuid();
            return guid;
        }
    }
}

Incorrect response from Azure Expected response as returned when locally testing

P.S There are some inconsistencies with naming in this code since I removed some identifying information. Please ignore that.

EDIT: I resolved this issue but I still am not sure how to overcome it. The issue was, as expected, the code I was publishing was not overwriting the code on Azure. I deleted my app and re-published and it began working with the below code. I would place this as the answer however I'm not sure how to overcome this challenge without resorting to deleting my app everytime I need to make a change, which is obviously not recommended.


Since you have identified the problem is that files seem not to be overwritten after publish, try to set delete existing files in publish profile.

On publish panel, click Manage Profile settings... and then check Remove additional files at destination.

Note that it's a potential solution since I haven't met similar problems and even without Remove additional files at destination, the sample project you provide can be updated(i.e. from 200 to xml content) as expected on my side.

BTW, update Microsoft.NET.Sdk.Functions to latest(1.0.24 right now) in case we meet some problem due to outdated SDK.

Function App Publishing Removes Existing Functions · Issue , When publishing a C# v2 function app through Visual Studios 2017, any existing function in that function app that is not present in the VS  Azure Web Deploy “Publish Failed” crash ide Fixed In: Visual Studio 2019 version 16.0 visual studio 2017 version 15.8 windows 10.0 Fixed In: Visual Studio 2019 version 16.0 Preview 5 wgaanderse reported Aug 20, 2018 at 01:05 PM


Could you try returning ContentResult instead? e.g.

StringBuilder xmlBuilder = new StringBuilder();

// ... build xml....

return new ContentResult
{
    Content = xmlBuilder.ToString(),
    ContentType = @"application/xml",
    StatusCode = StatusCodes.Status200OK
};

Develop Azure Functions using Visual Studio, Table of contents Publish your Azure Functions project directly to Azure, and create Azure resources From the Visual Studio menu, select File > New > Project. The function app name must be valid as a C# namespace, so don't use function app in Azure are overwritten by files from the local project. Publish to Azure. Visual Studio Code lets you publish your Functions project directly to Azure. In the process, you create a function app and related resources in your Azure subscription. The function app provides an execution context for your functions. The project is packaged and deployed to the new function app in your Azure subscription.


Add media type like below in the return,

return new OkObjectResult(xmlDoc) { ContentTypes = new Microsoft.AspNetCore.Mvc.Formatters.MediaTypeCollection { @"application/xml" } };

Develop Azure Functions by using Visual Studio Code, Don't mix local development and portal development for a single function app. You can develop functions locally and publish them to Azure without When you publish from Visual Studio Code to a new function app in Publishing to an existing function app overwrites the content of that app in Azure. The Azure Functions project template in Visual Studio creates a project that you can publish to a function app in Azure. You can use a function app to group functions as a logical unit for easier management, deployment, scaling, and sharing of resources. From the Visual Studio menu, select File > New > Project.


Migrating Applications to the Cloud with Azure: Re-architect and , Don't forget to replace [your account] with your Outlook username and [your password] put a message on a queue, read the file and process its contents, and so on. So, when you create a new function and make it trigger on existing blob though: this will overwrite the functions that are already in your Function App,  A publish settings file is created by Azure App Service, and then it can be imported into Visual Studio. Note If you just need to copy a Visual Studio publishing profile ( *.pubxml file) from one installation of Visual Studio to another, you can find the publishing profile, <profilename>.pubxml , in the \<projectname>\Properties\PublishProfiles


Work with Azure Functions Core Tools, Learn how to code and test Azure functions from the command prompt or When you create and publish functions from a local project, you should not try to open the host.json file and update its contents to match the following code: In version 2.x, when you run func new you are prompted to choose a  The Azure Functions project template in Visual Studio creates a project that you can publish to a function app in Azure. You can use a function app to group functions as a logical unit for easier management, deployment, scaling, and sharing of resources. From the Visual Studio menu, select File > New > Project.


Integrating Serverless Architecture: Using Azure Functions, Cosmos , Using Azure Functions, Cosmos DB, and SignalR Service Rami Vemula is not holding the configuration during the publish activity from Visual Studio. details of Importance="High" Text="Overwriting extensions.json file with one from build. In Visual Studio Code, press F1 to open the command palette. In the command palette, search for and select Azure Functions: Open in portal. Choose your function app, and press Enter. The function app page opens in the Azure portal. In the Overview tab, select the named link next to Resource group.