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 上有任何想法或示例,我们可以在哪里找到示例,因为我们找不到任何示例。
- 不幸的是,我们暂时停止了该项目,并计划在 1 到 2 个月内重新投入时间。当我们找到一个工作解决方案时,我会在这里发布。
- 乔伊,很抱歉删除了我之前的评论。在下面找到了这个现在对我有用的解决方案。谢谢你这么快回来!
- 乔伊,当你有机会时,你能试试看下面的回复是否能解决你的问题吗?谢谢
- 我星期四要回去工作我会测试它是否有效
我们通过以下方式解决了这个问题:
代码分析.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 .csproj 文件的过程。如果有更好的方法,请告诉我!
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
- 这是适用于该 1 项目的解决方案。我们希望它在安装我们创建的 nuget 包后自动包含自己。
- @joey,你和我都是。不幸的是,这些是我们从 StyleCopAnalyzers 组中获得的牌。值得庆幸的是,使用我们的 Xamarin.Forms 产品,我们只有少数项目需要这种手动按摩来达到我们的目标
来源:https://www.codenong.com/52742473/