C#C
C#2y ago
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>

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>


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

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

If I were evaluate this the following would be returned, as expected
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"
      }
    ]
  }
}

When trying to access this from the source generator only the first two elements are returned from
AdditionalTextsProvider
.
Was this page helpful?