RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.62k stars 1.23k forks source link

Error "MSB4100: Expected "%(NSwagGenerateExceptionClasses)" to evaluate to a boolean instead of ..." #4810

Closed WolfgangHG closed 3 months ago

WolfgangHG commented 4 months ago

After updating a project from 13.20.0 to NSwag 14.0.3, I observe this error, and no cs file is generated:

C:\Users\<USERNAME>\.nuget\packages\nswag.apidescription.client\14.0.3\build\NSwag.ApiDescription.Client.targets(22,18): error MSB4100: Expected "%(NSwagGenerateExceptionClasses)" to evaluate to a boolean instead of "", in condition "!%(FirstForGenerator) OR !%(NSwagGenerateExceptionClasses)".

I reference a Yaml file.

I deleted and readded the csproj service reference, but there is no change:

  <ItemGroup>
    <OpenApiReference Include="anonymizedapi.yaml" CodeGenerator="NSwagCSharp" Namespace="Anonymized.Namespace" ClassName="AnonymizedApi" />
  </ItemGroup>

Does anybody have an idea? I don't want to post the yaml file here, as it is not free.

WolfgangHG commented 4 months ago

I could work around it by adding a switch "NSwagGenerateExceptionClasses" to the csproj file entry:

  <ItemGroup>
     <OpenApiReference Include="anonymizedapi.yaml" CodeGenerator="NSwagCSharp" Namespace="Anonymized.Namespace" ClassName="AnonymizedApi" NSwagGenerateExceptionClasses="true" />
  </ItemGroup>

But this should probably be the default, instead of reporting an error.

WolfgangHG commented 4 months ago

Also, the generated class names changed for two classes in the yaml file. Those seem to be "hard to guess" names, as they previously had a number after the class name ("Data2"). But the new name starts with a lower case ("data"), and this is something I don't like in a C# environment ;-).

spSlaine commented 4 months ago

Same issue, but in my case I do not want to generate exception classes. I did have the

<ItemGroup>
    <OpenApiReference Include="..\My.json" CodeGenerator="NSwagCSharp" ClassName="MyApiService" Link="OpenAPIs\My.json">
       <Options>/generateClientInterfaces:true /useBaseUrl:false /operationGenerationMode:SingleClientFromOperationId /generateExceptionClasses:false /exceptionClass:My.ApiException /excludedTypeNames:ProblemDetails,ValidationProblemDetails</Options>
    </OpenApiReference>
</ItemGroup>

Changed it to

<PropertyGroup>
    <NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
</PropertyGroup>
<ItemGroup>
    <OpenApiReference Include="..\My.json" CodeGenerator="NSwagCSharp" ClassName="MyApiService" Link="OpenAPIs\My.json">
       <Options>/generateClientInterfaces:true /useBaseUrl:false /operationGenerationMode:SingleClientFromOperationId /exceptionClass:My.ApiException /excludedTypeNames:ProblemDetails,ValidationProblemDetails</Options>
    </OpenApiReference>
</ItemGroup>
olegd-superoffice commented 3 months ago

Duplicate of #4633 ?

WolfgangHG commented 3 months ago

You are right, it works with 14.0.4. Closing this issue. I thought I had done a search for this error before, but maybe the other issue was closed shortly before I created this one.