There is option in c# compiler for getting code analysis log using errorlog option, refer https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/errors-warnings
if we give just string it works but $(ProjectName) or $(AssemblyName) does not work it treat it as string instead project property
msbuild mysolution.sln /property:ErrorLog=$(AssemblyName).sarif
above command generate log file as $(AssemblyName).sarif instead MyProject.sarif
How to correctly use errolog switch to get project name prepended to log file name string.