-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deploy: christianhelle/refitter@156b995
- Loading branch information
1 parent
e8e43bf
commit 0a02017
Showing
5 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title> </title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta name="title" content=" "> | ||
|
||
|
||
<link rel="icon" href="../favicon.ico"> | ||
<link rel="stylesheet" href="../public/docfx.min.css"> | ||
<link rel="stylesheet" href="../public/main.css"> | ||
<meta name="docfx:navrel" content="../toc.html"> | ||
<meta name="docfx:tocrel" content="toc.html"> | ||
|
||
|
||
|
||
|
||
<meta name="docfx:docurl" content="https://github.com/christianhelle/refitter/blob/main/docs/docfx_project/articles/msbuild.md/#L1"> | ||
<meta name="loc:inThisArticle" content="In this article"> | ||
<meta name="loc:searchResultsCount" content="{count} results for "{query}""> | ||
<meta name="loc:searchNoResults" content="No results for "{query}""> | ||
<meta name="loc:tocFilter" content="Filter by title"> | ||
<meta name="loc:nextArticle" content="Next"> | ||
<meta name="loc:prevArticle" content="Previous"> | ||
<meta name="loc:themeLight" content="Light"> | ||
<meta name="loc:themeDark" content="Dark"> | ||
<meta name="loc:themeAuto" content="Auto"> | ||
<meta name="loc:changeTheme" content="Change theme"> | ||
<meta name="loc:copy" content="Copy"> | ||
<meta name="loc:downloadPdf" content="Download PDF"> | ||
|
||
<script type="module" src="./../public/docfx.min.js"></script> | ||
|
||
<script> | ||
const theme = localStorage.getItem('theme') || 'auto' | ||
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme) | ||
</script> | ||
|
||
</head> | ||
|
||
<body class="tex2jax_ignore" data-layout="" data-yaml-mime=""> | ||
<header class="bg-body border-bottom"> | ||
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation"> | ||
<div class="container-xxl flex-nowrap"> | ||
<a class="navbar-brand" href="../index.html"> | ||
<img id="logo" class="svg" src="../images/logo.png" alt=""> | ||
|
||
</a> | ||
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation"> | ||
<i class="bi bi-three-dots"></i> | ||
</button> | ||
<div class="collapse navbar-collapse" id="navpanel"> | ||
<div id="navbar"> | ||
</div> | ||
</div> | ||
</div> | ||
</nav> | ||
</header> | ||
|
||
<main class="container-xxl"> | ||
<div class="toc-offcanvas"> | ||
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel"> | ||
<div class="offcanvas-header"> | ||
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button> | ||
</div> | ||
<div class="offcanvas-body"> | ||
<nav class="toc" id="toc"></nav> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="content"> | ||
<div class="actionbar"> | ||
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents"> | ||
<i class="bi bi-list"></i> | ||
</button> | ||
|
||
<nav id="breadcrumb"></nav> | ||
</div> | ||
|
||
<article data-uid=""> | ||
|
||
<h2 id="msbuild">MSBuild</h2> | ||
<p>A common scenario for generating code from OpenAPI specifications is to do it at build time. This can be achieved using MSBuild tasks. An example of such an approach would be to include a <code>.refitter</code> file in the projects directory and execute the Refitter CLI from pre-build events</p> | ||
<pre><code class="lang-xml"><Target Name="Refitter" AfterTargets="PreBuildEvent"> | ||
<Exec WorkingDirectory="$(ProjectDir)" Command="refitter --settings-file .refitter --skip-validation" /> | ||
</Target> | ||
</code></pre> | ||
<p>The snippet above requires that Refitter is installed on the machine as a globally available dotnet tool. This might not be the case if you're running on a build agent from a CI/CD environment. In this case you might want to install Refitter as a local tool using a manifest file, as described in <a href="https://learn.microsoft.com/en-us/dotnet/core/tools/local-tools-how-to-use?WT.mc_id=DT-MVP-5004822">this tutorial</a></p> | ||
<pre><code class="lang-xml"><Target Name="Refitter" AfterTargets="PreBuildEvent"> | ||
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" /> | ||
<Exec WorkingDirectory="$(ProjectDir)" Command="refitter --settings-file .refitter --skip-validation" /> | ||
</Target> | ||
</code></pre> | ||
<p>The <code>dotnet build</code> process does will probably not have access to the package repository in which to download Refitter from, this is at least the case with Azure Pipelines and Azure Artifacts. To workaround this, you can provide a separate <code>nuget.config</code> that only uses <code>nuget.org</code> as a <code><packageSource></code>.</p> | ||
<p>Something like this:</p> | ||
<pre><code class="lang-xml"><?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> | ||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" /> | ||
</packageSources> | ||
</configuration> | ||
</code></pre> | ||
<p>You might want to place the <code>nuget.config</code> file in another folder to avoid using it to build the .NET project, then you can specify this when executing <code>dotnet tool restore</code></p> | ||
<pre><code class="lang-xml"><Target Name="Refitter" AfterTargets="PreBuildEvent"> | ||
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore --configfile refitter/nuget.config" /> | ||
<Exec WorkingDirectory="$(ProjectDir)" Command="refitter --settings-file .refitter --skip-validation" /> | ||
</Target> | ||
</code></pre> | ||
<p>In the example above, the <code>nuget.config</code> file is placed under the <code>refitter</code> folder.</p> | ||
<h3 id="refittermsbuild-package">Refitter.MSBuild package</h3> | ||
<p>Refitter ships with an MSBuild custom task that is distributed as a NuGet package and includes the Refitter CLI binary. This will simplify generating code from OpenAPI specifications at build time.</p> | ||
<p>To use the package, install <code>Refitter.MSBuild</code></p> | ||
<pre><code class="lang-xml"><ItemGroup> | ||
<PackageReference Include="Refitter.MSBuild" Version="1.5.0" /> | ||
</ItemGroup> | ||
</code></pre> | ||
<p>The MSBuild package includes a custom <code>.target</code> file which executes the <code>RefitterGenerateTask</code> custom task and looks something like this:</p> | ||
<pre><code class="lang-xml"><Target Name="Refitter" BeforeTargets="BeforeBuild"> | ||
<RefitterGenerateTask ProjectFileDirectory="$(MSBuildProjectDirectory)" | ||
DisableLogging="$(RefitterNoLogging)"/> | ||
<ItemGroup> | ||
<Compile Include="**/*.cs" /> | ||
</ItemGroup> | ||
</Target> | ||
</code></pre> | ||
<p>The <code>RefitterGenerateTask</code> task will scan the project folder for <code>.refitter</code> files and executes them all. By default, telemetry collection is enabled, and to opt-out of it you must specify <code><RefitterNoLogging>true</RefitterNoLogging></code> in the <code>.csproj</code> <code><PropertyGroup></code></p> | ||
|
||
</article> | ||
|
||
<div class="contribution d-print-none"> | ||
<a href="https://github.com/christianhelle/refitter/blob/main/docs/docfx_project/articles/msbuild.md/#L1" class="edit-link">Edit this page</a> | ||
</div> | ||
|
||
<div class="next-article d-print-none border-top" id="nextArticle"></div> | ||
|
||
</div> | ||
|
||
<div class="affix"> | ||
<nav id="affix"></nav> | ||
</div> | ||
</main> | ||
|
||
|
||
<footer class="border-top text-secondary"> | ||
<div class="container-xxl"> | ||
<div class="flex-fill"> | ||
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span> | ||
</div> | ||
</div> | ||
</footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
{"items":[{"name":"CLI Tool","href":"cli-tool.html","topicHref":"cli-tool.html"},{"name":"Source Generator","href":"source-generator.html","topicHref":"source-generator.html"},{"name":".refitter file format","href":"refitter-file-format.html","topicHref":"refitter-file-format.html"},{"name":"Using the generated code","href":"using-the-generated-code.html","topicHref":"using-the-generated-code.html"},{"name":"Examples","href":"examples.html","topicHref":"examples.html"},{"name":"XML Code Documentation","href":"xml-code-docs.html","topicHref":"xml-code-docs.html"}]} | ||
{"items":[{"name":"CLI Tool","href":"cli-tool.html","topicHref":"cli-tool.html"},{"name":"Source Generator","href":"source-generator.html","topicHref":"source-generator.html"},{"name":"MSBuild","href":"msbuild.html","topicHref":"msbuild.html"},{"name":".refitter file format","href":"refitter-file-format.html","topicHref":"refitter-file-format.html"},{"name":"Using the generated code","href":"using-the-generated-code.html","topicHref":"using-the-generated-code.html"},{"name":"Examples","href":"examples.html","topicHref":"examples.html"},{"name":"XML Code Documentation","href":"xml-code-docs.html","topicHref":"xml-code-docs.html"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters