swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.01k stars 6.03k forks source link

[CSharp] Can't build client using "build.bat" #6022

Closed beatcracker closed 7 years ago

beatcracker commented 7 years ago
Description

Building C# client using build.bat script fails with error:

The 'Newtonsoft.Json 10.0.3' package requires NuGet client version '2.12' or above,
but the current NuGet version is '2.8.60717.93'.
Swagger-codegen version
Swagger declaration file content or url

Any declaration will do. I'm using this swagger.yaml for XKCD.

Command line used for generation
java.exe -jar swagger-codegen-cli.jar generate -i swagger.yml -l csharp -o .\xkcd.com\CSharp --additional-properties packageGuid={ab9bd294-3842-5c1e-910c-591fc59f3009}
Steps to reproduce
  1. Generate C# client
  2. Try to build it using build.bat
Suggested fix

If nuget.exe doesn't exist in current directory, build.bat downloads it from https://nuget.org/nuget.exe, which has NuGet v. 2.8.60717.93.

Replacing nuget.exe with v. 4.1.0 downloaded from https://dist.nuget.org/win-x86-commandline/latest/nuget.exe fixes this issue.

wing328 commented 7 years ago

@beatcracker thanks for reporting the issue. Please file a PR with the suggested fix when you've time and we'll review accordingly.

beatcracker commented 7 years ago

Relevant issues:

List of affected files

modules/swagger-codegen/src/main/resources/csharp/compile-mono.sh.mustache:wget -nc https://nuget.org/nuget.exe;
modules/swagger-codegen/src/main/resources/csharp/compile.mustache:if not exist ".\nuget.exe" powershell -Command "(new-object System.Net.WebClient).DownloadFile('https://nuget.org/nuget.exe', '.\nuget.exe')"
modules/swagger-codegen/src/main/resources/csharp/mono_nunit_test.mustache:wget -nc https://nuget.org/nuget.exe
modules/swagger-codegen/src/main/resources/csharp/mono_nunit_test.mustache:wget -nc https://nuget.org/nuget.exe
modules/swagger-codegen/src/main/resources/CsharpDotNet2/compile-mono.sh.mustache:wget -nc https://nuget.org/nuget.exe;

Compatibility warning

NuGet 2.x users Because there are a few breaking changes introduced in NuGet 3.2, https://nuget.org/nuget.exe points to the latest stable NuGet 2.x release to prevent CI systems from potentially breaking at this time.

Solution

Assuming that we wouldn't hit any compatibility issues:

With fallback: