OpenAPITools / OpenAPITools/openapi-generator

[CSHARP] Bug - Nuget TLS1.2 Client Build fails

Open
#6,758 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Steps to reproduce

Build any csharp client without a nuget.exe on the machine.

Description

https://github.com/swagger-api/swagger-codegen/issues/10341
Code generation of CSharp Client does not work anymore. Nuget Download requests tls1.2 protocol.
See:
https://devblogs.microsoft.com/nuget/deprecating-tls-1-0-and-1-1-on-nuget-org/

Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS secure 

channel."

At line:1 char:1

+ (new-object System.Net.WebClient).DownloadFile('https://dist.nuget.or ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : WebException

'.\nuget.exe' is not recognized as an internal or external command,
operable program or batch file.
Swagger declaration file content or url

modules/swagger-codegen/src/main/resources/csharp/compile.mustache

Line 13:
if not exist ".\nuget.exe" powershell -Command "(new-object System.Net.WebClient).DownloadFile('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', '.\nuget.exe')"
.\nuget.exe install src\{{packageName}}\packages.config -o packages

Suggest a fix/enhancement

Line 13: Replace with protocol settings.

if not exist ".\nuget.exe" powershell -Command "[System.Net.ServicePointManager]::SecurityProtocol+=[System.Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', '.\nuget.exe')"
.\nuget.exe install src\{{packageName}}\packages.config -o packages

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/swagger-codegen/src/main/resources/csharp/compile.mustache and inspect line 13, where the generated build downloads nuget.exe through PowerShell. Reproduce a C# client build on a machine without nuget.exe, then verify that the generated build can download NuGet over TLS 1.2 and continue installing the packages.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
build-system, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.