© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
5 replies
Byron

Source Generator AdditionalFiles Batching missing metadata

Hey folks,

I am working with a source generator that wraps NSwag to generate clients and servers based on OpenApi spesefications. I have each project that wants to have generated client add the following Item.

<ItemGroup>
     <GeneratedApiServerContracts Include="$(OpenApiBasePath)openapi.yml" /> <-- clients
    <GeneratedApiClientContracts Include="$(OpenApiBasePath)openapi.yml" /> <-- servers
</ItemGroup>
<ItemGroup>
     <GeneratedApiServerContracts Include="$(OpenApiBasePath)openapi.yml" /> <-- clients
    <GeneratedApiClientContracts Include="$(OpenApiBasePath)openapi.yml" /> <-- servers
</ItemGroup>

I have both of these custom items defined with the following
<ItemDefinitionGroup>
    <GeneratedApiClientContracts>
        <Namespace>$(RootNamespace)</Namespace>
        <NSwagGenerateClient>true</NSwagGenerateClient>
    </GeneratedApiClientContracts>
    <GeneratedApiServerContracts>
        <Namespace>$(RootNamespace)</Namespace>
        <NSwagGenerateServer>true</NSwagGenerateServer>
    </GeneratedApiServerContracts>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
    <GeneratedApiClientContracts>
        <Namespace>$(RootNamespace)</Namespace>
        <NSwagGenerateClient>true</NSwagGenerateClient>
    </GeneratedApiClientContracts>
    <GeneratedApiServerContracts>
        <Namespace>$(RootNamespace)</Namespace>
        <NSwagGenerateServer>true</NSwagGenerateServer>
    </GeneratedApiServerContracts>
</ItemDefinitionGroup>


I then merge these two items into an
AdditionalFiles
AdditionalFiles
item so that it could be read by the source generator.

<AdditionalFiles Include="@(GeneratedApiClientContracts)"/>
<AdditionalFiles Include="@(GeneratedApiServerContracts)"/>
<AdditionalFiles Include="@(GeneratedApiClientContracts)"/>
<AdditionalFiles Include="@(GeneratedApiServerContracts)"/>

If I were evaluate this the following would be returned, as expected
dotnet msbuild -getItem:AdditionalFiles 
dotnet msbuild -getItem:AdditionalFiles 


// trimed extra metadata for brevity. 
{
  "Items": {
    "AdditionalFiles": [
      {
        "Identity": "D:\\dev\\gdw\\cadet\\cadet.service\\nswag\\openapi.nswag",
        "NSwagConfig": "true"
      },
      {
        "Identity": "D:\\dev\\gdw\\cadet\\cadet.service\\api\\api-gateway\\openapi.yml",
        "Namespace": "ApiGateway",
        "NSwagGenerateClient": "true"
      },
      {
        "Identity": "D:\\dev\\gdw\\cadet\\cadet.service\\api\\api-gateway\\openapi.yml",
        "Namespace": "ApiGateway",
        "NSwagGenerateServer": "true"
      }
    ]
  }
}
// trimed extra metadata for brevity. 
{
  "Items": {
    "AdditionalFiles": [
      {
        "Identity": "D:\\dev\\gdw\\cadet\\cadet.service\\nswag\\openapi.nswag",
        "NSwagConfig": "true"
      },
      {
        "Identity": "D:\\dev\\gdw\\cadet\\cadet.service\\api\\api-gateway\\openapi.yml",
        "Namespace": "ApiGateway",
        "NSwagGenerateClient": "true"
      },
      {
        "Identity": "D:\\dev\\gdw\\cadet\\cadet.service\\api\\api-gateway\\openapi.yml",
        "Namespace": "ApiGateway",
        "NSwagGenerateServer": "true"
      }
    ]
  }
}

When trying to access this from the source generator only the first two elements are returned from
AdditionalTextsProvider
AdditionalTextsProvider
.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ Access AdditionalFiles in source generator
C#CC# / help
3y ago
source generator
C#CC# / help
3y ago
❔ Source generator & protobuf
C#CC# / help
4y ago
Source generator not working?
C#CC# / help
12mo ago