Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

host.json seems to be compiled in the bin folder, not at root level.

Open TheeJamesLee opened this issue 9 years ago • 11 comments

Hi,

Using VS 2017 Preview 15.3 with Azure Functions Tooling. Create a Functions App with a couple of Http trigger functions. Apply a change to the host.json.

{
  "http": {
    "routePrefix": ""
  }
}

Followed the general build steps for building on Visual Studio Team Services and MSBuild arguments

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"

and deploying on a functions web app. All good, except... the host.json doesn't get packaged at the same level as the folders (with the function names) that hold each function.json file. meaning the host.json file changes will not come into effect on the web app. I may simply be just overlooking where it is set, but I can't seem to find it anywhere and wonder now if it is internal...

Was found because on a web app, the host.json file is at the root of the server... the host.json file that I edited seems to always be compiled into the bin folder....

So when compiled with that msbuild argument (can't remember the doc I found it on, sorry), I have the following structure;

Release

  • net461 --- PubTmp ----- Out -------- {FunctionNameFolder} ---------- function.json -------- bin ---------- host.json + compiled data.

When that is deployed onto a web app from the Out folder, the host.json is not at the right level (ie, should be outside the bin folder).

Any guidance appreciated, thanks.

TheeJamesLee avatar Jul 10 '17 21:07 TheeJamesLee

The only workaround I found for this (using the 1.0.0-alpha6 version of Microsoft.NET.Sdk.Functions) was to not create a packaged zip for deployment and let it use the publish in visual studio to upload the file using the command line,

In my VSTS build job I replaced the command you had with /p:DeployOnBuild=false, deleted the "Push to Azure Web App" step, let my unit tests run, then after the unit tests do another build step but this time with the parameters /p:DeployOnBuild=true /p:PublishProfile=AzureFunctionsProfile where AzureFunctionsProfile is the name of the profile created inside visual studio when you publish.

One thing I did have to manually hack is inside the AzureFunctionsProfile.pubxml file I had to delete the <_SavePWD>True</_SavePWD> entry and replace it with a <Password>(SNIP)</Password> and fill in the password you can get from inside the file you get by clicking "Download Publish Profile" from the azure portal on the page for the function app.

leftler avatar Jul 11 '17 14:07 leftler

@leftler okay, at least that's an option. I'm actually building these out with ARM templates so completely avoiding the local publish profiles and as far as possible manual hacks - because then we need to remember to do them for every app...

This isn't blocking me currently, because the current process I have building and releasing works fine... I only found it because I needed to match an existing api in a port and needed to remove the api/ prefix. To get round that, I just jumped onto the app service editor and that's when I noticed the host.json issue (copied what I needed to the root host.json) and that got me through. Because for me those settings are likely to be changed rarely... it just feels nicer than hacking an otherwise smooth build process.

@lindydonna , you've been very active around Functions and the sample projects recently. Have you had this host.json issue deploying onto azure through a VSTS agent?

TheeJamesLee avatar Jul 11 '17 14:07 TheeJamesLee

@TheeJamesLee I'm the program manager for the Visual Studio Functions integration (so please provide feedback to me!)

Make sure that you're using the alpha6 version of the NuGet package. That resolves the host.json issue.

lindydonna avatar Jul 11 '17 19:07 lindydonna

@TheeJamesLee actually, thanks to your post showing how i was messing up my build arguments I have ARM deployments working now and don't need to do the work-around anymore.

leftler avatar Jul 11 '17 20:07 leftler

@lindydonna spot on, was still on the alpha3 package on that solution where I needed the change. Thank you!

TheeJamesLee avatar Jul 11 '17 20:07 TheeJamesLee

@TheeJamesLee Thanks for following up!

lindydonna avatar Jul 11 '17 21:07 lindydonna

@leftler Have you tried following the steps here? https://blogs.msdn.microsoft.com/appserviceteam/2017/06/01/deploying-visual-studio-2017-function-projects-with-vsts/

lindydonna avatar Jul 12 '17 00:07 lindydonna

@lindydonna I had not seen that blog post, I was using the Azure Web App template instead of the ASP.NET Core (.NET Framework) template.

leftler avatar Jul 12 '17 20:07 leftler

@leftler Yes, definitely use the ASP.NET core one. Otherwise you'll have to customize the msbuild command line.

lindydonna avatar Jul 12 '17 20:07 lindydonna

@lindydonna one snag I am running in to. If I have more than one project in my solution I want to publish using that template only generates a single zip file for the whole solution. I would like a zip per publish target, but I can do that easily enough using multiple build steps and specifying specific projects instead of just letting it do all of them in a single build.

leftler avatar Jul 12 '17 21:07 leftler

@leftler I would ask the VSTS team, as this is not my area of expertise. Post on https://developercommunity.visualstudio.com/spaces/21/index.html.

lindydonna avatar Jul 12 '17 21:07 lindydonna