This is an obscure and head-scratching problem. As pointed out by John Rutherford above, it shouldn't be necessary and isn't practical to create a "temp" web app on all the build servers. This is a compile-time issue, not a run-time issue, so IIS shouldn't even be involved.
Here's the answer; there's a fair amount to it. Credit to the many other people who have also researched this in various ways.
I am using everything up to date as of July, 2021: visual studio 2019, new build server 2019 with latest build tools and updates from visual studio 2019 installer.
- The offending line in the .csproj is
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
If you read the spec for the AspNetCompiler clause, you'll see that VirtualPath, while required, is only used if PhysicalPath isn't present. In fact, I verified that PhysicalPath wasn't present using this directive inside the MvcBuildViews target:
<Message Text="WebProjectOutputDir=$(WebProjectOutputDir)" />
and sure enough, WebProjectOutputDir was blank. That's the genesis of the misleading "/temp is not a valid IIS application" or "Failed to map the path /temp" error messages from ASPNETCOMPILER.
- The problem is that your build server doesn't have the right build targets to create a web deploy package. You can see this if you look at the output - you'll see it stop right after the build, with no output (or error message) for the web deploy package task. This has been described here:
https://stackoverflow.com/questions/6409549/web-deploy-packaging-not-working-on-my-build-server
and here:
https://stackoverflow.com/questions/2607428/msbuild-target-package-not-found/6413635#6413635
Against all reason, the only solution I found that worked consistently was to copy
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\v16.0\Web
and
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications
to
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0
on the build server (yes, I'm using MSBuild 16, go figure).
It has also been suggested that adding the nuget package
MSBuild.Microsoft.VisualStudio.Web.targets
solves the problem. It does, but it's a pretty rough thing to have to do to every web project in a large system.
You shouldn't have to do this, of course, but at least you, the build server administrator, can fix it for everyone. I can't see this as anything other than a bug, or at best a miscommunication.