This post is a follow-up from this How to create nuget package with Stylecop Analyzer and custom ruleset?
I am currently working on a nuget package with custom analyzers, a stylecop.json, and a Custom.ruleset with referencing to stylecop analyzer. This package serves as a consistent style guideline in all our team projects.
I have created my solution based on the Visual studio template Analyzer with Code Fix (.NET Standard).
I removed the .CodeFixes, .Test and .VSIX project and moved the CodeFixes into the main Analyzer.csproj project. Those work fine.
Now I want to add a stylecop.json and a Custom.ruleset to my nuget package, which also checks for warnings and highlight them in the project where the nuget package will be installed.
I added the references in the .csproj files like so:
MyAnalyzer.csproj
<ItemGroup><None Include="stylecop.json" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath="content"/><None Include="Custom.ruleset" CopyToOutputDirectory="PreserveNewest" Pack="true" PackagePath="content"/></ItemGroup>
MyAnalyzer.Package.csproj
<ItemGroup><ProjectReference Include="..\MyAnalyzer\MyAnalyzer.csproj" /></ItemGroup><ItemGroup><Content Include="..\MyAnalyzer\stylecop.json" Pack="true" PackagePath="contentFiles/any/any/stylecop.json" /><Content Include="..\MyAnalyzer\Custom.ruleset" Pack="true" PackagePath="contentFiles/any/any/Custom.ruleset" /></ItemGroup><ItemGroup><None Include="..\MyAnalyzer\stylecop.json" Pack="true" PackagePath="content/stylecop.json" /><None Include="..\MyAnalyzer\Custom.ruleset" Pack="true" PackagePath="content/Custom.ruleset" /></ItemGroup>
Sadly this does not work.To generate the .nupkg file I do:
\MyAnalyzer> dotnet build -c Release\MyAnalyzer.Package> dotnet build -c Release\MyAnalyzer.Package> dotnet pack -c Release\MyAnalyzer.Package> copy bin\Release\MyAnalyzer.1.0.1.nupkg C:\LocalNuGetFeed\MyTestProject> dotnet add package MyAnalyzer --version 1.0.1 --source C:\LocalNuGetFeed
If I look at the .nuspec file inside the generated .nupkg it looks like this:
<?xml version="1.0" encoding="utf-8"?><package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"><metadata><id>MyAnalyzer</id><version>1.0.2</version> ...<contentFiles><files include="any/any/stylecop.json" buildAction="Content" /><files include="any/any/Custom.ruleset" buildAction="Content" /></contentFiles></metadata></package>
The PackageReference in my testProject after adding the nuget package is this:
<PackageReference Include="MyAnalyzer" Version="1.0.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets><PrivateAssets>all</PrivateAssets></PackageReference>
I tried to research this specific case, but I had no luck. Does someone have any idea on what to try?