4
votes

I have installed AsyncUsageAnalyzers for my common project (which is a NuGet package), and I want the rules to be enforced in all of my packages/applications that depends on it. I have changed the severity of the UseConfigureAwait rule, and a .ruleset has been created.

I have read on https://stackoverflow.com/a/20271758/2663813 that I needed to have a NuGet package with a given structure. That assertion has been confirmed here https://stackoverflow.com/a/46115423/2663813

What I have now:

build/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>

build/My.Package.Id.targets

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)Common.ruleset</CodeAnalysisRuleSet>
    </PropertyGroup>
</Project>

In my .csproj

<Import Project="build\My.Package.Id.targets" />

My question is : Now that I've done that and that the rules are correctly applied on my project, how do I add the files under build/ inside the NuGet package, inside the build/ folder? I know that I could do that with a .nuspec file as mentionned in the links, but I'd like to do that with the new .csproj syntax.

1

1 Answers

7
votes

Sorry for posting too quickly, I just found the solution right under my eyes:

In the page https://docs.microsoft.com/en-us/dotnet/core/tools/csproj#nuget-metadata-properties , in the comments, MarkPflug gives the translation, and quotes https://docs.microsoft.com/en-us/nuget/schema/msbuild-targets#pack-scenarios for reference.

In my case, I need to use PackagePath as follows (Content would also work, but as Martin Ullrich pointed out, None is a better choice here):

  <ItemGroup>
    <None Include="build\**" Pack="True" PackagePath="build\" />
  </ItemGroup>