Refitter.MSBuild
1.5.6
See the version list below for details.
dotnet add package Refitter.MSBuild --version 1.5.6
NuGet\Install-Package Refitter.MSBuild -Version 1.5.6
<PackageReference Include="Refitter.MSBuild" Version="1.5.6" />
<PackageVersion Include="Refitter.MSBuild" Version="1.5.6" />
<PackageReference Include="Refitter.MSBuild" />
paket add Refitter.MSBuild --version 1.5.6
#r "nuget: Refitter.MSBuild, 1.5.6"
#:package Refitter.MSBuild@1.5.6
#addin nuget:?package=Refitter.MSBuild&version=1.5.6
#tool nuget:?package=Refitter.MSBuild&version=1.5.6
MSBuild Tasks for Refitter
Refitter is available as custom MSBuild tasks that includes the Refitter CLI executable for generating a REST API Client using the Refit library. Refitter can generate the Refit interface from OpenAPI specifications. Refitter could format the generated Refit interface to be managed by Apizr (v6+) and generate some registration helpers too.
The MSBuild package includes a custom .target file which executes the RefitterGenerateTask custom task and looks something like this:
<Target Name="Refitter" BeforeTargets="BeforeBuild">
<RefitterGenerateTask ProjectFileDirectory="$(MSBuildProjectDirectory)"
DisableLogging="$(RefitterNoLogging)"/>
<ItemGroup>
<Compile Include="**/*.cs" />
</ItemGroup>
</Target>
The RefitterGenerateTask task will scan the project folder for .refitter files and executes them all. By default, telemetry collection is enabled, and to opt-out of it you must specify <RefitterNoLogging>true</RefitterNoLogging> in the .csproj <PropertyGroup>
.Refitter File format
The following is an example .refitter file
{
"openApiPath": "/path/to/your/openAPI", // Required
"namespace": "Org.System.Service.Api.GeneratedCode", // Optional. Default=GeneratedCode
"naming": {
"useOpenApiTitle": false, // Optional. Default=true
"interfaceName": "MyApiClient" // Optional. Default=ApiClient
},
"generateContracts": true, // Optional. Default=true
"generateXmlDocCodeComments": true, // Optional. Default=true
"generateStatusCodeComments": true, // Optional. Default=true
"addAutoGeneratedHeader": true, // Optional. Default=true
"addAcceptHeaders": true, // Optional. Default=true
"addContentTypeHeaders": true, // Optional. Default=true
"returnIApiResponse": false, // Optional. Default=false
"responseTypeOverride": { // Optional. Default={}
"File_Upload": "IApiResponse",
"File_Download": "System.Net.Http.HttpContent"
},
"generateOperationHeaders": true, // Optional. Default=true
"typeAccessibility": "Public", // Optional. Values=Public|Internal. Default=Public
"useCancellationTokens": false, // Optional. Default=false
"useIsoDateFormat": false, // Optional. Default=false
"multipleInterfaces": "ByEndpoint", // Optional. May be one of "ByEndpoint" or "ByTag"
"generateDeprecatedOperations": false, // Optional. Default=true
"operationNameTemplate": "{operationName}Async", // Optional. Must contain {operationName} when multipleInterfaces != ByEndpoint
"optionalParameters": false, // Optional. Default=false
"outputFolder": "../CustomOutput" // Optional. Default=./Generated
"outputFilename": "RefitInterface.cs", // Optional. Default=Output.cs for CLI tool
"additionalNamespaces": [ // Optional
"Namespace1",
"Namespace2"
],
"includeTags": [ // Optional. OpenAPI Tag to include when generating code
"Pet",
"Store",
"User"
],
"includePathMatches": [ // Optional. Only include Paths that match the provided regular expression
"^/pet/.*",
"^/store/.*"
],
"useDynamicQuerystringParameters": true, // Optional. Default=false
"usePolymorphicSerialization": false, // Optional. Default=false
"dependencyInjectionSettings": { // Optional
"baseUrl": "https://petstore3.swagger.io/api/v3", // Optional. Leave this blank to set the base address manually
"httpMessageHandlers": [ // Optional
"AuthorizationMessageHandler",
"TelemetryMessageHandler"
],
"transientErrorHandler": "Polly", // Optional. Value=None|Polly|HttpResilience
"maxRetryCount": 3, // Optional. Default=6
"firstBackoffRetryInSeconds": 0.5 // Optional. Default=1.0
},
"apizrSettings": { // Optional
"withRequestOptions": true, // Optional. Default=true
"withRegistrationHelper": true, // Optional. Default=false
"withCacheProvider": "InMemory", // Optional. Values=None|Akavache|MonkeyCache|InMemory|DistributedAsString|DistributedAsByteArray. Default=None
"withPriority": true, // Optional. Default=false
"withMediation": true, // Optional. Default=false
"withOptionalMediation": true, // Optional. Default=false
"withMappingProvider": "AutoMapper", // Optional. Values=None|AutoMapper|Mapster. Default=None
"withFileTransfer": true // Optional. Default=false
},
"codeGeneratorSettings": { // Optional. Default settings are the values set in this example
"requiredPropertiesMustBeDefined": true,
"generateDataAnnotations": true,
"anyType": "object",
"dateType": "System.DateTimeOffset",
"dateTimeType": "System.DateTimeOffset",
"timeType": "System.TimeSpan",
"timeSpanType": "System.TimeSpan",
"arrayType": "System.Collections.Generic.ICollection",
"dictionaryType": "System.Collections.Generic.IDictionary",
"arrayInstanceType": "System.Collections.ObjectModel.Collection",
"dictionaryInstanceType": "System.Collections.Generic.Dictionary",
"arrayBaseType": "System.Collections.ObjectModel.Collection",
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"propertySetterAccessModifier": "",
"generateImmutableArrayProperties": false,
"generateImmutableDictionaryProperties": false,
"handleReferences": false,
"jsonSerializerSettingsTransformationMethod": null,
"generateJsonMethods": false,
"enforceFlagEnums": false,
"inlineNamedDictionaries": false,
"inlineNamedTuples": true,
"inlineNamedArrays": false,
"generateOptionalPropertiesAsNullable": false,
"generateNullableReferenceTypes": false,
"generateNativeRecords": false,
"generateDefaultValues": true,
"inlineNamedAny": false,
"excludedTypeNames": [
"ExcludedTypeFoo",
"ExcludedTypeBar"
]
}
}
openApiPath- points to the OpenAPI Specifications file. This can be the path to a file stored on disk, relative to the.refitterfile. This can also be a URL to a remote file that will be downloaded over HTTP/HTTPSnamespace- the namespace used in the generated code. If not specified, this defaults toGeneratedCodenaming.useOpenApiTitle- a boolean indicating whether the OpenApi title should be used. Default istruenaming.interfaceName- the name of the generated interface. The generated code will automatically prefix this withIso if this set toMyApiClientthen the generated interface is calledIMyApiClient. Default isApiClientgenerateContracts- a boolean indicating whether contracts should be generated. A use case for this is several API clients use the same contracts. Default istruegenerateXmlDocCodeComments- a boolean indicating whether XML doc comments should be generated. Default istrueaddAutoGeneratedHeader- a boolean indicating whether XML doc comments should be generated. Default istrueaddAcceptHeaders- a boolean indicating whether to add accept headers [Headers("Accept: application/json")]. Default istruereturnIApiResponse- a boolean indicating whether to returnIApiResponse<T>objects. Default isfalseresponseTypeOverride- a dictionary with operation ids (as specified in the OpenAPI document) and a particular return type to use. The types are wrapped in a task, but otherwise unmodified (so make sure to specify or import their namespaces). Default is{}generateOperationHeaders- a boolean indicating whether to use operation headers in the generated methods. Default istruetypeAccessibility- the generated type accessibility. Possible values arePublicandInternal. Default isPublicuseCancellationTokens- Use cancellation tokens in the generated methods. Default isfalseuseIsoDateFormat- Set totrueto explicitly format date query string parameters in ISO 8601 standard date format using delimiters (for example: 2023-06-15). Default isfalsemultipleInterfaces- Set toByEndpointto generate an interface for each endpoint, orByTagto group Endpoints by their Tag (like SwaggerUI groups them).outputFolder- a string describing a relative path to a desired output folder. Default is./GeneratedoutputFilename- Output filename. Default isOutput.cswhen used from the CLI tool, otherwise its the .refitter filename. SoPetstore.refitterbecomesPetstore.cs.additionalNamespaces- A collection of additional namespaces to include in the generated file. A use case for this is when you want to reuse contracts from a different namespace than the generated code. Default is emptyincludeTags- A collection of tags to use a filter for including endpoints that contain this tag.includePathMatches- A collection of regular expressions used to filter paths.generateDeprecatedOperations- a boolean indicating whether deprecated operations should be generated or skipped. Default istrueoperationNameTemplate- Generate operation names using pattern. This must contain the string {operationName}. An example usage of this could be{operationName}Asyncto suffix all method names with Async. When using"multipleIinterfaces": "ByEndpoint", This is name of the Execute() method in the interfaceoptionalParameters- Generate non-required parameters as nullable optional parametersuseDynamicQuerystringParameters: Set totrueto wrap multiple query parameters into a single complex one. Default isfalse(no wrapping).dependencyInjectionSettings- Setting this will generated extension methods toIServiceCollectionfor configuring Refit clients. See https://github.com/reactiveui/refit?tab=readme-ov-file#dynamic-querystring-parameters for more information.baseUrl- Used as the HttpClient base address. Leave this blank to manually set the base URLhttpMessageHandlers- A collection ofHttpMessageHandlerthat is added to the HttpClient pipelinetransientErrorHandler- This is the transient error handler to use. Possible values areNone,Polly, andHttpResilience. Default isNonemaxRetryCount- This is the max retry count used in the Polly retry policy. Default is 6firstBackoffRetryInSeconds- This is the duration of the initial retry backoff. Default is 1 second
apizrSettings- Setting this will format Refit interface to be managed by Apizr. See https://www.apizr.net for more informationwithRequestOptions- Tells if the Refit interface methods should have a final IApizrRequestOptions options parameterwithRegistrationHelper- Tells if Refitter should generate Apizr registration helpers (extended with dependencyInjectionSettings set, otherwise static)withCacheProvider- Set the cache provider to be usedwithPriority- Tells if Apizr should handle request prioritywithMediation- Tells if Apizr should handle request mediation (extended only)withOptionalMediation- Tells if Apizr should handle optional request mediation (extended only)withMappingProvider- Set the mapping provider to be usedwithFileTransfer- Tells if Apizr should handle file transfer
codeGeneratorSettings- Setting this allows customization of the NSwag generated types and contractsrequiredPropertiesMustBeDefined- Default is true,generateDataAnnotations- Default is true,anyType- Default isobject,dateType- Default isSystem.DateTimeOffset,dateTimeType- Default isSystem.DateTimeOffset,timeType- Default isSystem.TimeSpan,timeSpanType- Default isSystem.TimeSpan,arrayType- Default isSystem.Collections.Generic.ICollection,dictionaryType- Default isSystem.Collections.Generic.IDictionary,arrayInstanceType- Default isSystem.Collections.ObjectModel.Collection,dictionaryInstanceType- Default isSystem.Collections.Generic.Dictionary,arrayBaseType- Default isSystem.Collections.ObjectModel.Collection,dictionaryBaseType- Default isSystem.Collections.Generic.Dictionary,propertySetterAccessModifier- Default is ``,generateImmutableArrayProperties- Default is false,generateImmutableDictionaryProperties- Default is false,handleReferences- Default is false,jsonSerializerSettingsTransformationMethod- Default is null,generateJsonMethods- Default is false,enforceFlagEnums- Default is false,inlineNamedDictionaries- Default is false,inlineNamedTuples- Default is true,inlineNamedArrays- Default is false,generateOptionalPropertiesAsNullable- Default is false,generateNullableReferenceTypes- Default is false,generateNativeRecords- Default is falsegenerateDefaultValues- Default is trueinlineNamedAny- Default is falseexcludedTypeNames- Default is empty
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.7.1 | 606 | 12/16/2025 |
| 1.7.1-preview.87 | 226 | 12/16/2025 |
| 1.7.0 | 2,964 | 11/6/2025 |
| 1.7.0-preview.86 | 156 | 11/6/2025 |
| 1.6.5 | 2,637 | 10/6/2025 |
| 1.6.5-preview.85 | 140 | 10/6/2025 |
| 1.6.5-preview.84 | 132 | 10/6/2025 |
| 1.6.5-preview.83 | 137 | 10/6/2025 |
| 1.6.5-preview.81 | 133 | 10/6/2025 |
| 1.6.4 | 864 | 9/23/2025 |
| 1.6.4-preview.80 | 145 | 9/20/2025 |
| 1.6.3 | 660 | 9/18/2025 |
| 1.6.3-preview.79 | 272 | 9/17/2025 |
| 1.6.3-preview.78 | 129 | 9/13/2025 |
| 1.6.3-preview.77 | 152 | 9/11/2025 |
| 1.6.2 | 1,177 | 8/18/2025 |
| 1.6.2-preview.76 | 155 | 8/13/2025 |
| 1.6.1 | 1,040 | 7/8/2025 |
| 1.6.1-preview.75 | 140 | 7/8/2025 |
| 1.6.0 | 1,616 | 6/17/2025 |
| 1.6.0-preview.74 | 328 | 6/10/2025 |
| 1.5.6 | 248 | 6/7/2025 |
| 1.5.6-preview.73 | 112 | 5/31/2025 |
| 1.5.5 | 1,553 | 5/4/2025 |
| 1.5.5-preview.70 | 79 | 5/30/2025 |
| 1.5.5-preview.69 | 158 | 4/30/2025 |
| 1.5.4 | 264 | 4/26/2025 |
| 1.5.3 | 2,838 | 3/30/2025 |
| 1.5.3-preview.68 | 288 | 3/23/2025 |
| 1.5.3-preview.67 | 408 | 1/30/2025 |
| 1.5.2 | 4,637 | 1/29/2025 |
| 1.5.1 | 207 | 1/25/2025 |
| 1.5.1-preview.66 | 108 | 1/25/2025 |
| 1.5.0 | 320 | 1/19/2025 |
| 1.5.0-preview.65 | 445 | 12/8/2024 |
| 1.5.0-preview.64 | 111 | 12/7/2024 |
| 1.5.0-preview.63 | 105 | 12/7/2024 |