@@ -510,7 +510,9 @@ List<ResponseFileData> responseFilesData
510510
511511 targetFrameWork . Value = GetTargetFrameworkVersion ( netSettings ) ;
512512
513- AddCommonProperties ( assembly , responseFilesData , project ) ;
513+ var otherArguments = GetOtherArgumentsFromResponseFilesData ( responseFilesData ) ;
514+
515+ AddCommonProperties ( assembly , responseFilesData , project , otherArguments ) ;
514516
515517 // we have source files
516518 if ( assembly . sourceFiles . Length != 0 )
@@ -595,6 +597,19 @@ Assembly reference in assembly.assemblyReferences.Where(
595597 project . Add ( assemblyRefItemGroup ) ;
596598 }
597599
600+ {
601+ var analyzersRefItemGroup = new XElement ( "ItemGroup" ) ;
602+
603+ var analyzers = RetrieveRoslynAnalyzers ( assembly , otherArguments ) ;
604+ foreach ( var item in analyzers )
605+ {
606+ analyzersRefItemGroup . Add ( new XElement ( "Analyzer" ,
607+ new XAttribute ( "Include" , item ) ) ) ;
608+ }
609+
610+ project . Add ( analyzersRefItemGroup ) ;
611+ }
612+
598613 if (
599614 m_AssemblyNameProvider . ProjectGenerationFlag . HasFlag (
600615 ProjectGenerationFlag . Analyzers
@@ -749,11 +764,10 @@ static string HandleEditorReference(string referencePath)
749764 private void AddCommonProperties (
750765 Assembly assembly ,
751766 List < ResponseFileData > responseFilesData ,
752- XElement builder
767+ XElement builder ,
768+ ILookup < string , string > otherArguments
753769 )
754770 {
755- var otherArguments = GetOtherArgumentsFromResponseFilesData ( responseFilesData ) ;
756-
757771 // Language version
758772 var langVersion = GenerateLangVersion ( otherArguments [ "langversion" ] , assembly ) ;
759773
@@ -856,6 +870,16 @@ ILookup<string, string> otherResponseFilesData
856870 . ToArray ( ) ;
857871 }
858872
873+ string [ ] RetrieveRoslynAnalyzers ( Assembly assembly , ILookup < string , string > otherArguments )
874+ {
875+ return otherArguments [ "analyzer" ] . Concat ( otherArguments [ "a" ] )
876+ . SelectMany ( x => x . Split ( ';' ) )
877+ . Concat ( assembly . compilerOptions . RoslynAnalyzerDllPaths )
878+ . Select ( MakeAbsolutePath )
879+ . Distinct ( )
880+ . ToArray ( ) ;
881+ }
882+
859883 private static string MakeAbsolutePath ( string path )
860884 {
861885 return Path . IsPathRooted ( path ) ? path : Path . GetFullPath ( path ) ;
0 commit comments