Building ASP.NET-Core 3.1 with .NET-Standard 2.0 projects leads to conflicting Microsoft.AspNetCore.Mvc.Analyzers assemblies
visual studio uses MSBuild to build your solution file, so you can try MSBuild %yoursolutionfile%
to build your solution, on the other hand, dotnet build
typically builds a single project instead of solution.
to answer your second question, if you do find that your dependency is required and can not be ignored in dotnet build for 3.1 version, yes a multitarget setup should work, you can follow this link to build a multitarget application https://docs.microsoft.com/en-us/dotnet/core/tutorials/libraries#how-to-multitarget