加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在.net标准项目中获得一个stylecop规则集

发布时间:2020-12-15 22:53:20 所属栏目:百科 来源:网络整理
导读:我们正在尝试使用stylecop规则集为我们的所有项目提供nuget包. 我们获取项目中的文件,但规则集不适用于我们的项目.它仍然使用minimimumrecomended.ruleset. 我们现在拥有的是: Custom.stylecop.props Project ToolsVersion="4.0" xmlns="http://schemas.mic
我们正在尝试使用stylecop规则集为我们的所有项目提供nuget包.
我们获取项目中的文件,但规则集不适用于我们的项目.它仍然使用minimimumrecomended.ruleset.

我们现在拥有的是:

Custom.stylecop.props

<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

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <AdditionalFiles Include="$(MSBuildThisFileDirectory)Contentstylecop.json">
      <Link>stylecop.json</Link>
    </AdditionalFiles>
  </ItemGroup>
</Project>

Custom.stylecop.nuspec

<contentFiles>
    <files include="Content/stylecop.json" buildAction="EmbeddedResource" />
</contentFiles>
....
<files>
    <file src="build**" target="build" />
    <file src="Content/stylecop.json" target="contentFiles" />
</files>

有没有人在github上有任何想法或例子,我们可以找到一个例子,因为我们找不到任何.

解决方法

在我们的Xamarin.Forms项目中,修复是一个编辑.NET Standard .csproj文件的手动过程.如果有更好的方法,请告诉我!

>首先,在文本编辑器中打开.NET Standard项目(_Notepad)
>然后添加< CodeAnalysisRuleSet> …< / CodeAnalysisRuleSet>在< PropertyGroup>内

<PropertyGroup>
    <CodeAnalysisRuleSet>..stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

>(可选)如果要在项目中访问这些文件,可以使用< AdditionalFiles ... />创建一个ItemGroup.

<ItemGroup>
    <AdditionalFiles Include="..stylecop.json" />
    <AdditionalFiles Include="..stylecop.ruleset" />
</ItemGroup>

参考

https://github.com/dotnet/roslyn/blob/master/docs/compilers/Rule%20Set%20Format.md

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读