autorest.csharp: csharp generator v3 does not generate .Net clients

I was prompted to upgrade AutoRest to latest. Generated code now targets Azure only

autorest readme.md

contents of readme.md

input-file: https://internal.site/api/swagger/docs/v0
output-folder: ..\..\OpenApi\Generated
add-credentials: true
use-internal-constructors: true
sync-methods: none
csharp:
  namespace: OpenApi

Expected behavior Auto-generated code targeting .NET

Additional context I didn’t see anything anywhere about support for generating clients targeting .NET having been dropped. The only pointer I found was about using version=previous, if having problems with current version. What do I need to add to make sure vanilla .NET clients are being generated, using V3?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

@timotheeguerin is correct. V3 generator depends on Azure.Core and we do not have any plan to support non Azure template.

Hey, just checking in one year later, I am having the exact same issues, using this tool looks impossible to me outside an Azure environment. The documentation only shows azure-arm flavor of client initialization and nothing on how to provide those constructor parameters, namely ClientDiagnostics and HttpPipeline

Would appreciate input on this

PS. @ShivangiReja the repo you provided, does not initialize and use the generated client, or am I missing something?

Any updates on this? We are actively using AutoRest to generate internal clients and if it is confirmed that non-Azure template will be dropped we will have to plan switch now, instead of using --v2 flag for some time.

@aanufriyev and @NelsonLamprecht:

V3 generator depends on Azure.Core and we do not have any plan to support non Azure template.

I meant we depend on Azure.Core and we don’t have any plan to support Microsoft.Rest.ClientRuntime(non Azure) library.

@timotheeguerin is correct. V3 generator depends on Azure.Core and we do not have any plan to support non Azure template.

Confirming that this package is now only for consuming azure rest services and not any rest services? If so, I think it would be helpful for users to remove the section in the readme about “Use outside of the azure-sdk-net repo” and boldly proclaim autorest.csharp is not to be used to generate clients for non azure resources which appears to be a deviation from the proclaimed goals on the base autorest page: “The AutoRest tool generates client libraries for accessing RESTful web services”.

Maybe this package should be renamed autorest.csharp-azure since they are comingled?

How interesting @ShivangiReja, thank you. I really like the way the generated code looks now in V3.

@timotheeguerin the generated code targets azure, not plain .net. The client generated depends on Azure libraries, not on Microsoft.Rest.ClientRuntime. Meanwhile I headed over to csharp generator issues https://github.com/Azure/autorest.csharp/issues/1029 and it is admitted V3 is missing vanilla .NET support, if I get that epic right.

  • V2
namespace ServiceClient.OpenApi
{
    using Microsoft.Rest;
    using Microsoft.Rest.Serialization;
    using Models;
    using Newtonsoft.Json;
    using System.Collections;
    using System.Collections.Generic;
    using System.Net;
    using System.Net.Http;

    public partial class AuthDataAPI : ServiceClient<AuthDataAPI>, IAuthDataAPI
  • V3
using System;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Core.Pipeline;
using ServiceClient.OpenApi.Models;

namespace ServiceClient.OpenApi
{
    internal partial class AuthRestClient
    {
        private Uri endpoint;
        private ClientDiagnostics _clientDiagnostics;
        private HttpPipeline _pipeline;

        /// <summary> Initializes a new instance of AuthenticationRestClient. </summary>
        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
        /// <param name="endpoint"> server parameter. </param>
        public AuthRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null)

There doesn’t seem to be any way out of generating that Azure targeting code.

V3 generator also generates .csproj check here, it references Azure.Core and Microsoft.Azure.AutoRest.CSharp. That’s where these parameters come from.