5

I'm setting up some DevOps for my site, and so far I've used the following command for deployment on two ASP.NET Core apps, with success:

dotnet publish ProjectName.csproj /p:PublishProfile="PublishProfileName" /p:Password=password

I've just created an Azure Function, using the V2 runtime and .NET Core 2.1, as suggested for all new projects (see here https://azure.microsoft.com/en-us/blog/introducing-azure-functions-2-0/), but if I use the same command, I find that it only publishes it to a local folder and doesn't seem to deploy the project to Azure.

If I use the MSBuild equivalent, it seems to also miss out the deployment stage.

I'm guessing its to do with the project type in some way not having the appropriate build targets, but I'm not sure how to track this further.

I can download the publish settings from Azure, import them into Visual studio and publish through VS, so it seems like if the VS path works, this might be a regression or bug in the tooling somewhere, rather than something unsupported?

I'm using:

  • Visual Studio 15.8.8 +28010.2048
  • Azure Functions and Web Jobs Tools 15.9.02046.0

If I shouldn't be using dotnet publish with Azure functions, what should I be using instead for command line CD? I've seen references to the Azure Function CLI tools, but I'd prefer not to have to install a package manager on our build agents if it can be done through other tooling.

Andy
  • 2,859
  • 2
  • 33
  • 68
  • 2
    If publishing works from VS, then just use MSBuild to deploy. That's the way I publish our functions. msbuild /p:DeployOnBuild=True /p:PublishProfile=somename.pubxml /p:Configuration=Release – Svend Oct 29 '18 at 15:39
  • @Svend, thanks for the command line. See, this is the odd thing, I tried your command line, and still, it seems to skip the actual deployment to azure. The last logs from MSBuild is that it gets to Publish which outputs it to a local folder, then _GenerateFunctionsAndCopyContentFiles which seems to move some more folders, then Done. Surely this means there's a bug/regression in my version of Visual Studio? I'd re-install, but I don't really have that much time spare! :) – Andy Oct 30 '18 at 07:33
  • @Svend, even more odd, I was creating a repro to log an issue against MSBuild or VS, and it seems if I create a clean function project in a new solution, the command line works. If I use the same command line in a new project in my existing solution, it skips the deployment! Getting somewhere I guess. – Andy Oct 30 '18 at 07:59
  • You most likely have something fouled up in a csproj file. Try to compare the project files and see if something is missing from one or the other. I'll eat my hat if you're dealing with a "legit" msbuild/vs bug. – Svend Oct 30 '18 at 09:08
  • The csproj files were the same (or similar enough) by the way. Same NuGet packages and versioning too. – Andy Oct 30 '18 at 09:22
  • So, I tried your command line again in the original project, and it does work (embarrassed) but there are things that I note, which I think may have confused me on my way: 1) If you miss-spell the publish profile name, it will silently skip deployment (no warning or error). 2) If you use 'dotnet publish', it will always skip deployment (clean project or otherwise.) 3) if you don't specify /p:DeployOnBuild=True, it'll skip deployment. So all in all, inconsistent with deploying an ASP.NET Core project, but whether this inconsistency is a bug or regression is perhaps down to interpretation. :) – Andy Oct 30 '18 at 09:28
  • In general, there's alot of "bad" turf between the classic .NET scene (of which MSBuild is part of), and NETCore parts which are cross-platform by default. I'm personally not a fan of MS creating CLIs for all their Azure bullshit, instead of just using MSBuild for it all (and I suspect it's still used undernearth, check out the obj dir and look at the generated contents in there, mighty MSBuildish) – Svend Oct 30 '18 at 14:00

3 Answers3

5

In the end, with the help of the answers and comments (thanks all), I have an MSBuild command line that is working to deploy my .NET Core 2.1 Function project:

msbuild /p:DeployOnBuild=True /p:PublishProfile=somename.pubxml /p:Configuration=Release

It is, however, worth noting the following:

General .NET Core publishing notes

  1. If you miss-spell the publish profile name, it will silently skip deployment (no warning or error).

Differences between ASP.NET Core and .NET Core Functions deployment

  1. If you use 'dotnet publish', it will always skip deployment.

  2. If you don't specify /p:DeployOnBuild=True, it'll skip deployment.

Andy
  • 2,859
  • 2
  • 33
  • 68
  • 1
    Normally if you want to use the DeployOnBuild property, you might want to only invoke it for a [specific project, instead of ALL eligible projects](https://stackoverflow.com/questions/16891530/publish-one-web-project-from-solution-with-msbuild). And yes, MSBuild is not "user friendly". It's what VS.IDE uses undernearth the UI, so this is quite capable (and worth learning IMO) – Svend Oct 30 '18 at 13:56
1

If you do not want to have "a package manager" on your build agents you have to option to make a zip deploy of your function app. Details can be found on the MSDN here:

https://docs.microsoft.com/en-us/azure/azure-functions/deployment-zip-push#rest

Sebastian Achatz
  • 558
  • 3
  • 14
  • Thanks for the link, I think I saw this in passing, but I'll take another look. Curiously, it mentions "Azure Functions has the full range of continuous deployment and integration options that are provided by Azure App Service.". It seems not in my case, given the same deployment command line doesn't work. :) – Andy Oct 29 '18 at 15:03