How to get a stylecop ruleset trough nuget in a .net standard project
我们正在尝试为我们所有的项目提供一个带有 stylecop 规则集的 nuget 包。
我们获得了项目中的文件,但规则集并未应用于我们的项目。它仍然使用 minimimumrecomended.ruleset。
我们现在拥有的是:
Custom.stylecop.props
1
2 3 4 5 6 |
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <RunCodeAnalysis>true</RunCodeAnalysis> <CodeAnalysisRuleSet>Custom.StyleCop.ruleset</CodeAnalysisRuleSet> </PropertyGroup> </Project> |
custom.stylecop.targets
1
2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <AdditionalFiles Include="$(MSBuildThisFileDirectory)//Content//stylecop.json"> <Link>stylecop.json</Link> </AdditionalFiles> </ItemGroup> </Project> |
Custom.stylecop.nuspec
1
2 3 4 5 6 7 8 |
<contentFiles>
<files include="Content/stylecop.json" buildAction="EmbeddedResource" /> </contentFiles> …. <files> <file src="build//**" target="build" /> <file src="Content/stylecop.json" target="contentFiles" /> </files> |
有没有人在 github 上有任何想法或示例,我们可以在哪里找到示例,因为我们找不到任何示例。
我们通过以下方式解决了这个问题:
代码分析.props
1
2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)..//CodeAnalysis.ruleset</CodeAnalysisRuleSet> </PropertyGroup> <ItemGroup> <AdditionalFiles Include="$(MSBuildThisFileDirectory)..//stylecop.json" /> </ItemGroup> </Project> |
代码分析.nuspec
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>CodeAnalysis</id> <version>1.0.0</version> <description>Roslyn analyzers, rule sets and additional configuration to be used for Code Analysis</description> </authors> <owners></owners> <dependencies> |
在我们的 Xamarin.Forms 项目中,修复是手动编辑 .NET Standard
1
2 3 |
<PropertyGroup>
<CodeAnalysisRuleSet>..//stylecop.ruleset</CodeAnalysisRuleSet> </PropertyGroup> |
1
2 3 4 |
<ItemGroup>
<AdditionalFiles Include="..//stylecop.json" /> <AdditionalFiles Include="..//stylecop.ruleset" /> </ItemGroup> |
参考
https://github.com/dotnet/roslyn/blob/master/docs/compilers/Rule Set Format.md
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/269652.html