0

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.

Ramesh
  • 438
  • 4
  • 13
  • `$(AssemblyName)` is a reference to an MSBuild property. References to properties on the command line will not be recognized. MSBuild doesn't evaluate the values in the `/property` switch for property references. – Jonathan Dodds Aug 15 '23 at 11:10

1 Answers1

0

The command line /property switch doesn't evaluate the values for property references. A value like $(AssemblyName).sarif will be taken as a literal. The property reference will not be expanded.

Instead create a Directory.Build.props file in the solution folder (or a folder that contains all the project folders) with the following content:

<Project>
 <PropertyGroup>
   <ErrorLog>$(AssemblyName).sarif</ErrorLog>
 </PropertyGroup>
</Project>
Jonathan Dodds
  • 2,654
  • 1
  • 10
  • 14