However, I want to be able to specify the exact path to msbuild like:
dotnet C:\name\msbuild.exe. (Adding it to the path is not an option)
Actually, dotnet msbuild does not have an option to specify which version of MSBuild to use. And MSBuild of dotnet.exe is updated with the Version of the NET Core SDK.
And as far as I know, the latest Net Core 3.+ SDK uses MSBuild 16.+ which is the latest MSBuild. So if you want to use the latest MSBuild on your windows server container, you should install the latest version of Net Core.
Note: In this way, you can only use MSBuild 16.+which supports building the old projects.
Besides, you can also install Build Tool for VS2019 or Build Tool for VS2017 to build your projects on your windows server container. Please refer to this link.
It is a lightweight build command-line tool that can be thrown away from the vs installation. When you start to install it, you need to select the related Build workload.
Build Tool for VS2017 is MSBuild 15 while Build Tool for VS2019 is MSBuild 16. You can install both of them.
Then after you finish installing it, you should launch Build Tool and then you can build them with command line msbuild xxx.xxproj -t:target.
C:\name\msbulid.exe. No need to involvedotnet. But really, this sounds like an XY Problem. Why are you trying to use a specific msbuild?Dotnet msbuilddoes not have an option to specify the msbuild version. And if you want to use different versions of msbuild, you could useBuild Tool for VS2017(msbuild 15.0) or Build Tool for VS0219(msbuild 16.0)which is a lightweight build command-line tool that can be thrown away from the vs installation. See this link. And then you can call one of them based on requirements to use the specific version-----------msbuild xxx.xxproj -t:build.