@@ -45,7 +45,8 @@ private static string OnGeneratedCSProject(string path, string content)
4545 }
4646
4747 // Additional contents.
48- content = Regex . Replace ( content , "[\r \n ]+</Project>[\r \n ]*" , "\r \n <!-- C# Settings For Unity -->" ) ;
48+ content = Regex . Replace ( content , NewLine + AdditionalContentComment + ".*" + AdditionalContentComment , "" , RegexOptions . Singleline ) ;
49+ content = Regex . Replace ( content , "[\r \n ]+</Project>[\r \n ]*" , NewLine + AdditionalContentComment ) ;
4950 {
5051 content += NewLine + " <ItemGroup>" ;
5152 {
@@ -55,17 +56,17 @@ private static string OnGeneratedCSProject(string path, string content)
5556
5657 // Add analyzer packages.
5758 foreach ( var package in setting . AnalyzerPackages )
58- content = AddPackage ( content , package . Name , package . Version ) ;
59+ content = AddAnalyzer ( content , package . PackageId ) ;
5960 }
6061 content += NewLine + " </ItemGroup>" ;
6162
6263 // Add rule set files.
6364 content += NewLine + " <PropertyGroup>" ;
6465 {
6566 // Ruleset.
66- var rulesets = new [ ] { "Assets/Default.ruleset" } // Add default rule set for project.
67+ var rulesets = new [ ] { "Assets/Default.ruleset" } // Add default rule set for project.
6768 . Concat ( string . IsNullOrEmpty ( asmdefPath )
68- ? new [ ] { "Assets/" + assemblyName + ".ruleset" } // Add rule set for predefined assemblies (e.g. Assembly-CSharp.dll).
69+ ? new [ ] { "Assets/" + assemblyName + ".ruleset" } // Add rule set for predefined assemblies (e.g. Assembly-CSharp.dll).
6970 : Directory . GetFiles ( Path . GetDirectoryName ( asmdefPath ) , "*.ruleset" ) ) // Add rule sets for asmdef.
7071 . Where ( File . Exists ) ;
7172
@@ -74,7 +75,7 @@ private static string OnGeneratedCSProject(string path, string content)
7475 }
7576 content += NewLine + " </PropertyGroup>" ;
7677 }
77- content += NewLine + "<!-- C# Settings For Unity -->" + NewLine + NewLine + "</Project>" + NewLine ;
78+ content += NewLine + AdditionalContentComment + NewLine + "</Project>" + NewLine ;
7879
7980 return content ;
8081 }
@@ -88,13 +89,22 @@ private static string AddPackage(string content, string name, string version)
8889 return content ;
8990 }
9091
92+ private static string AddAnalyzer ( string content , string packageId )
93+ {
94+ var info = AnalyzerInfo . GetInstalledInfo ( packageId ) ;
95+ foreach ( var dll in info . DllFiles )
96+ content += NewLine + " <Analyzer Include=\" " + dll . Replace ( '/' , '\\ ' ) + "\" />" ;
97+ return content ;
98+ }
99+
91100 private static string AddRuleSet ( string content , string ruleset )
92101 {
93102 if ( File . Exists ( ruleset ) )
94103 content += NewLine + " <CodeAnalysisRuleSet>" + ruleset . Replace ( '/' , '\\ ' ) + "</CodeAnalysisRuleSet>" ;
95104 return content ;
96105 }
97106
98- private static string NewLine = "\r \n " ;
107+ private const string NewLine = "\r \n " ;
108+ private const string AdditionalContentComment = "<!-- C# Settings For Unity -->" ;
99109 }
100110}
0 commit comments