我已经为我的通用项目(它是一个 NuGet 包)安装了 AsyncUsageAnalyzers,并且我希望在依赖它的所有包/应用程序中强制执行这些规则。我更改了UseConfigureAwait规则的严重性,并创建了一个 .ruleset。
我在/sf/answers/1419023091/上读到我需要一个具有给定结构的 NuGet 包。该断言已在此处得到确认/sf/answers/3228079641/
我现在所拥有的:
构建/Common.ruleset
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="My common analyzer rules" Description="The rules that are enforced on all of my projects" ToolsVersion="10.0">
<Rules AnalyzerId="AsyncUsageAnalyzers" RuleNamespace="AsyncUsageAnalyzers">
<Rule Id="UseConfigureAwait" Action="Error" />
</Rules>
</RuleSet>
Run Code Online (Sandbox Code Playgroud)
构建/My.Package.Id.targets
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)Common.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
在我的 .csproj
<Import Project="build\My.Package.Id.targets" />
Run Code Online (Sandbox Code Playgroud)
我的问题是:既然我已经这样做了并且规则已正确应用于我的项目,我该如何build/在 NuGet 包内的build/文件夹内添加文件?我知道我可以用链接中提到的 .nuspec 文件来做到这一点,但我想用新的 .csproj 语法来做到这一点。
抱歉发帖太快了,我刚刚在我眼皮底下找到了解决方案:
在页面https://docs.microsoft.com/en-us/dotnet/core/tools/csproj#nuget-metadata-properties的评论中,MarkPflug 给出了翻译,并引用了 https://docs.microsoft。 com/en-us/nuget/schema/msbuild-targets#pack-scenarios供参考。
就我而言,我需要PackagePath按如下方式使用(Content也可以使用,但正如 Martin Ullrich 指出的那样,None这里是一个更好的选择):
<ItemGroup>
<None Include="build\**" Pack="True" PackagePath="build\" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4680 次 |
| 最近记录: |