Skip to content

Add Ivy.Analyser NuGet package to all package demo projects #401

@nielsbosma

Description

@nielsbosma

Problem

All 52 package demo projects in packages-demos/ use PackageReference Include="Ivy" but don't include the Ivy.Analyser NuGet package. Since these are user-facing examples, they should demonstrate best practices including analyzer usage.

Solution

Add the Ivy.Analyser NuGet package reference to each .csproj file under packages-demos/, matching the pattern used in Ivy-Templates:

<PackageReference Include="Ivy.Analyser" Version="1.*">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

This should be added to the existing <ItemGroup> containing the Ivy PackageReference in each project.

Projects to update (52)

All .csproj files under packages-demos/:
asposebarcode, aspose-ocr, aspose-words, barcodelib, bogus, closedxml, constructs, cronos, csvhelper, diffengine, diffplex, dnsclient, enums-net, epplus, exceldatareader, fastmember, fluentdatetime, fuzzysharp, github, handlebars-net, HtmlAgilityPack, humanizer, ibannet, jwt, magick-net-q16-anycpu, mapster, microsoft-semantickernel, mimemapping, miniexcel, naudio, newtonsoft-json, nodatime, ollamasharp, openai, puppeteersharp, qrcoder, questpdf, restsharp, scriban, serialize-linq, sharpyaml, shopifysharp, simmetrics-net, smartformat-net, stripe-net, superpower, timezonenames, ulid, unitsnet, xlparser, yamldotnet, zstring

Suggested approach

A script can add the reference to all projects at once:

Get-ChildItem -Path "packages-demos" -Recurse -Filter "*.csproj" | ForEach-Object {
    $content = Get-Content $_.FullName -Raw
    if ($content -notmatch 'Ivy\.Analyser') {
        $content = $content -replace '(<PackageReference Include="Ivy" Version="[^"]*"\s*/>)', @'
$1
    <PackageReference Include="Ivy.Analyser" Version="1.*">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
'@
        Set-Content $_.FullName $content
    }
}

Verification

Build a few representative projects after adding:

dotnet build packages-demos/bogus/BogusExample.csproj
dotnet build packages-demos/openai/OpenAIExample.csproj
dotnet build packages-demos/humanizer/HumanizerExample.csproj

Then fix any analyzer warnings/errors that surface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions