@@ -45,7 +45,8 @@ private static string OnGeneratedCSProject(string path, string content)
45
45
}
46
46
47
47
// 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 ) ;
49
50
{
50
51
content += NewLine + " <ItemGroup>" ;
51
52
{
@@ -55,17 +56,17 @@ private static string OnGeneratedCSProject(string path, string content)
55
56
56
57
// Add analyzer packages.
57
58
foreach ( var package in setting . AnalyzerPackages )
58
- content = AddPackage ( content , package . Name , package . Version ) ;
59
+ content = AddAnalyzer ( content , package . PackageId ) ;
59
60
}
60
61
content += NewLine + " </ItemGroup>" ;
61
62
62
63
// Add rule set files.
63
64
content += NewLine + " <PropertyGroup>" ;
64
65
{
65
66
// 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.
67
68
. 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).
69
70
: Directory . GetFiles ( Path . GetDirectoryName ( asmdefPath ) , "*.ruleset" ) ) // Add rule sets for asmdef.
70
71
. Where ( File . Exists ) ;
71
72
@@ -74,7 +75,7 @@ private static string OnGeneratedCSProject(string path, string content)
74
75
}
75
76
content += NewLine + " </PropertyGroup>" ;
76
77
}
77
- content += NewLine + "<!-- C# Settings For Unity -->" + NewLine + NewLine + "</Project>" + NewLine ;
78
+ content += NewLine + AdditionalContentComment + NewLine + "</Project>" + NewLine ;
78
79
79
80
return content ;
80
81
}
@@ -88,13 +89,22 @@ private static string AddPackage(string content, string name, string version)
88
89
return content ;
89
90
}
90
91
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
+
91
100
private static string AddRuleSet ( string content , string ruleset )
92
101
{
93
102
if ( File . Exists ( ruleset ) )
94
103
content += NewLine + " <CodeAnalysisRuleSet>" + ruleset . Replace ( '/' , '\\ ' ) + "</CodeAnalysisRuleSet>" ;
95
104
return content ;
96
105
}
97
106
98
- private static string NewLine = "\r \n " ;
107
+ private const string NewLine = "\r \n " ;
108
+ private const string AdditionalContentComment = "<!-- C# Settings For Unity -->" ;
99
109
}
100
110
}
0 commit comments