Is it mandatory to have the Visual Studio installed on the build
server?
It's not necessary. Msbuild package only is enough for your requirement when you're building and publishing in server.
1.Please try using command like msbuild xx.sln(or xx.csproj) /t:rebuild
to check if there's any extra info from the build process.
(Make sure you're installed required corresponding SDK, .net core or .net framework...)
2.Since you're using msbuild for VS2019, please check if you have a Web folder in path C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\v16.0
.
The publish-related targets file and assemblies are under that folder. So if you can build but can't publish, the files in it may be missing or broken in your server.
If the Web folder not exists, please make sure you've installed this workload:

If the Web folder exists and your project targets .net core
instead of .net framework
, please also try installing this workload:
After that check if the issue goes away. You may also need to repair the build tools package if something is broken. More details about how to install the corresponding workload by UI or command-line see here.
