Dotnet build and dotnet publish differ in Azure DevOps workflows in the following ways:
Dotnet build:
The application is compiled, and the required binaries (DLLs) and other files are produced.
Usage: Usually employed to verify that the code compiles correctly and to look for issues throughout the build process.
Compiled code has been produced, but it hasstill needs to be been prepared for deployment.
dotnet publish:
Its goal is to get the application ready for deployment by compiling the code and copying the required files, including configuration files, dependencies, and runtime-specific binaries.
Use: Employed when the program is prepared for deployment to a server, cloud service, or container.
Output: Produces a package that is either framework-dependent or self-contained and contains all the components required for the application to function.
In conclusion, the code is compiled using dotnet build and then ready for deployment by incorporating all required runtime dependencies using dotnet publish.