question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Source Generator for C# 9

See original GitHub issue

Any plans on creating a source generator package as a next-gen NSwag.MSBuild for C# code generation? Sounds like it would be less faff to set up in a project (no <Exec ...> tags just a package reference, could auto-discover *.nswag files) and eliminate the irritating phantom file changes I often see to my generated client files in git.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:8

github_iconTop GitHub Comments

3reactions
HavenDVcommented, Oct 19, 2021

I implemented this for personal use, maybe it will be useful to someone as well: https://github.com/HavenDV/H.NSwag.Generator

Usage:

Install-Package H.NSwag.Generator
<ItemGroup>
  <AdditionalFiles Include="openapi.nswag" />
</ItemGroup>
0reactions
HavenDVcommented, Mar 4, 2022
  • The generated file is not under your source control, which means you don’t see when and how the generated code changes after an update of NSwag

I recently came across an article on how to overcome this problem: https://andrewlock.net/creating-a-source-generator-part-6-saving-source-generator-output-in-source-control/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing C# Source Generators - .NET Blog
A Source Generator is a piece of code that runs during compilation and can inspect your program to produce additional files that are...
Read more >
amis92/csharp-source-generators: A list of C# ...
C# Source Generators is a Roslyn compiler feature introduced in C#9/.NET 5. It lets C# developers inspect user code and generate new C#...
Read more >
4 ways to generate code in C# — Including Source ...
A Source Generator is a piece of code that runs during compilation and can inspect your program to produce additional files that are...
Read more >
Building a Source Generator for C# - InfoQ
Source generators are a good way to reduce the amount of repetitive code that needs to be written. Plan your source generator by...
Read more >
Episode 15: C#9 Source Generators with Jason Bock ...
In this episode, I was joined by Jason Bock to chat about the new C#9 source generators! Writing code that writes code! We...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found