dotnet build -c Release is similar to dotnet build, except it builds your application in Release mode, as opposed to Debug mode when you run dotnet build.
dotnet publish also builds your application in Release mode, but it also prepares your .NET application for deployment. This involves additional optimization (one example is trimming where unused code is removed, but it needs to be enabled using PublishTrimming in the csproj), copies all the necessary DLLs, and creates a publish output (publish directory).
dotnet publish can also be used to publish an application for a specific operating system only. In this example, the executable will be a Linux executable instead of the Windows exe:
dotnet publish --runtime linux-x64
You can also use dotnet publish for a self-contained deployment, where the application can run without having .NET installed (e.g. the entire .NET BCL and CLR libraries are copied over):
dotnet publish -c Release --runtime win-x64 --self-contained
Generally, dotnet publish is recommended to use over dotnet build -c Release if you're preparing to release the first or new version of your application.
buildstates: "With that in mind, the product ofdotnet buildisn't ready to be transferred to another machine to run. To create a version of the application that can be deployed, you need to publish it (for example, with thedotnet publishcommand)." (for .NET Core before 3.0), and for later versions: "This means that if there isn't any other publish-specific logic (such as Web projects have), the build output should be deployable."dotnet buildwill just compile your code,dotnet publishwill pack it into a folder that you can ship to customers. Sometimes the output ofbuildalready is enough to ship, sometimes you need to add further steps into your deploy-process.