> For the complete documentation index, see [llms.txt](https://til.cazzulino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.cazzulino.com/dotnet/nuget/packaging-transitive-analyzers-with-nuget.md).

# Packaging transitive analyzers with NuGet

Consider the scenario of [ThisAssembly](https://github.com/kzu/ThisAssembly) and its referenced packages: the main package is essentially a meta-package so that anyone wanting to leverage all the codegen in all the ThisAssembly.\* packages can reference a single one. By default, NuGet pack will create a package that declares the project reference dependencies like so:

```markup
    <dependencies>
      <group targetFramework=".NETStandard2.0">
        <dependency id="ThisAssembly.AssemblyInfo" version="42.42.42" exclude="Build,Analyzers" />
        <dependency id="ThisAssembly.Metadata" version="42.42.42" exclude="Build,Analyzers" />
        <dependency id="ThisAssembly.Project" version="42.42.42" exclude="Build,Analyzers" />
        <dependency id="ThisAssembly.Strings" version="42.42.42" exclude="Build,Analyzers" />
      </group>
    </dependencies>
```

Note all those `exclude`. Not good since now it means projects referencing this package will not get the transitive analyzers, which are precisely the point of this meta-package.

The fix is [highly non-obvious](https://github.com/NuGet/Home/issues/3697#issuecomment-342983009): you must explicitly state that *none* of the referenced project assets are to be flagged as private:

```markup
  <ItemGroup>
    <ProjectReference Include="../ThisAssembly.AssemblyInfo/ThisAssembly.AssemblyInfo.csproj" PrivateAssets="none" />
    <ProjectReference Include="../ThisAssembly.Metadata/ThisAssembly.Metadata.csproj" PrivateAssets="none" />
    <ProjectReference Include="../ThisAssembly.Project/ThisAssembly.Project.csproj" PrivateAssets="none" />
    <ProjectReference Include="../ThisAssembly.Strings/ThisAssembly.Strings.csproj" PrivateAssets="none" />
  </ItemGroup>
```

This properly allows the transitive build and analyzer assets to be properly installed on the referencing project.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://til.cazzulino.com/dotnet/nuget/packaging-transitive-analyzers-with-nuget.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
