I am trying to deploy two web apps from the same Git repo to two different Azure App Service apps. I am using the Deployment Console in each App Service app to build and deploy the apps. To select which app to deploy to which App Service app, I am specifying an application setting inside the Azure portal for each app, called PROJECT. which then points to the csproj for the app to build and deploy. This works fine!
However, my problem then lies in telling the build service to use the newest version of MSBuild. It defaults to v. 14, which does not work with the SDK style csproj files. I tried setting another application setting called MSBUILD_PATH to %MSBUILD_1670_DIR%\MSBuild.exe, but the deploy script Kudu generates only uses the MSBUILD_PATH for the build step, and not the NuGet restore step, so it still fails, with the output:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Using custom deployment setting for MSBUILD_PATH custom value is '%MSBUILD_1670_DIR%\MSBuild.exe'.
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0.23107.0 built by: D14REL' from 'D:\Program Files (x86)\MSBuild\14.0\Bin'.
Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'. Input files: D:\home\site\repository\ProReception.UnitTest\ProReception.UnitTest.csproj.
Failed exitCode=1, command=nuget restore "D:\home\site\repository\ProReception.sln"
An error has occurred during web site deployment.
Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'. Input files: D:\home\site\repository\ProReception.UnitTest\ProReception.UnitTest.csproj.\r\nD:\Program Files (x86)\SiteExtensions\Kudu\98.40824.5897\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
The template for the build script is this one: https://github.com/projectkudu/KuduScript/blob/master/lib/templates/deploy.batch.aspnet.wap.template#L10 - and the NuGet restore command does not specify the -MSBuildPath.
So, the suggested fix is to add your own deploy.cmd script to your repo, but how do I do that without hardcoding the project to build? (since I have two projects).
To make this even more difficult: One of the web apps is an old ASP.NET MVC site running on .NET 4.7.1, and the other is a newer ASP.NET Core site running on .NET 6. So ideally they need different deploy scripts.
How can I use different deploy scripts for each app?
OK, I came up with a temporary solution and created a
deploy.cmdscript that is able to deploy either app. It looks at thePROJECTenvironment variable, to determine which app to deploy.Here is the complete script, in case it helps someone else: