244 questions
1
vote
1
answer
236
views
Adding modifiers to System.Text.Json serialization when using source generation
I'm currently using the following code to set up a System.Text.Json JsonSerializerOptions object that alphabetizes properties upon serialization:
public static readonly JsonSerializerOptions ...
1
vote
0
answers
83
views
Profile C# Source Generators?
I have a bunch of source generators and they are all doing stuff in the background but as the codebase they operate on grows I want to make sure that they are still scaling sensibly.
According to this ...
0
votes
0
answers
114
views
C# Source generator accessing code from "Referenced Project(s)"
I'm writing a source generator which will generate factories to create instances of object(s).
Since the source generator generates code that's related to tests, I'm going to install the source ...
1
vote
0
answers
12
views
Roslyn IIncrementalGenerator - Comparer not working - know where - not why
I'm having a problem with the comparer as it is generating a new object everytime I make a meaningless change (e.g. add a space) to the file that is being inspected. More specifically, it is ...
0
votes
1
answer
275
views
How to build Roslyn Source Generator pipeline that depends on config options passed from host?
I need to write a source generator that scans the project for one or another set of classes (marked with different attributes), then generates the same code from them (the second set of attributes is ...
0
votes
0
answers
158
views
How to detect an attribute property using a source generator?
I'm trying to learn and use source generator in C#, but I'm having few issues.
I want to make use of some C# new features, like generic attribute, and use it to generate custom code.
I have for ...
1
vote
0
answers
125
views
Source Generated Files Can't Use Namespaces In Unity
I'm trying to get a source generator working, but for some reason its failing to include the namespace it needs. The generated code looks like this:
using OwlTree; // namespace proxy factory is from
...
1
vote
1
answer
73
views
Find modifiers with roslyn at semantic level
I can get MemberDeclarationSyntax.Modifiers at syntaxic level, but once I'm at semantic level, dealing with ISymbol, I don't know how to get back the modifiers of such given ISymbol ?
In my use case, ...
0
votes
0
answers
87
views
Configure source-generated JSON serialization for all types in assembly
I'm building an ASP.NET Core Web API for AOT publishing and need to configure source-generated JSON serialization for it, as reflection-based serialization will not work for AOT.
According to ...
0
votes
0
answers
233
views
How to make System.Text.Json's Source Generation feature dynamic
Is there a way to make the process of registering types to serialise dynamic, i.e. not having to tediously write [JsonSerializable(typeof(<type goes here>))] for each type.
So far, I've tried to ...
1
vote
0
answers
58
views
Generate full property from a simple property with generator
I am trying to take a class like below with an [AutoSave] attribute:
[AutoSave]
public partial class GeneratedConfig : NotifiyingJsonSettings, IVersionable
{
[EnforcedVersion("1.0.0.0")]
...
1
vote
1
answer
505
views
IIncrementalGenerator Not Generating Code in Referencing Project
I have three c# projects, designed to use a custom attribute to generate code referencing a common class using a custom IIncremental Generator. I used and extended this guide from dotnet https://www....
3
votes
2
answers
2k
views
Error RS1035 "The symbol is banned for use by analyzers" while using GeneratorExecutionContext.AddSource method
Beginner to Roslyn Source Generators here.
I'm following the documentation on Source Generators by Microsoft. I have created a .NET Standard 2.0 Class Library, and set the following as the contents of ...
1
vote
1
answer
93
views
How to enable on-the-go builds in Visual Studio Community 2022
I am writing an application on Avalonia UI in Visual Studio Community 2022. However, as of recently I have encountered a problem. For example, I am writing code in a ViewModel file.
[...
1
vote
1
answer
169
views
Copying source file from a source generator into the compilation with RegisterPostInitializationOutput
I am authoring an incremental source generator which uses a marker attribute to control the source generation, which is configured via an enum parameter passed to the attribute's constructor, such as:
...
2
votes
1
answer
513
views
c# Source generator not working in pipeline
I have created a source generator that works perfectly on my local machine; however, when it's being built by our CI-CD pipeline (Azure devops - DotNetCoreCLI@2), it does not seem to work.
Here is the ...
1
vote
1
answer
119
views
SourceGenerator Intellisense
I'm currently trying to learn about source generators, and have implemented a very simple one.
[Generator]
public class KeysSourceGenerator : ISourceGenerator
{
public void Execute(...
1
vote
0
answers
160
views
C# source generator not run
I referred to this official tutorial: https://learn.microsoft.com/zh-cn/dotnet/csharp/roslyn-sdk/source-generators-overview , but it didn't work as expected.
The Source Generator project I created ...
0
votes
1
answer
145
views
I created a c# Roslyn source generator and a test, the generator works but the test doesn't find the same source
I created a simple source generator that works fine
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
...
0
votes
2
answers
711
views
Find all derived classes in a source generator
My source generator needs to find other classes that derive from the inspected class to know whether special code needs to be added. So far, I have only inspected the class to augment itself and ...
1
vote
1
answer
280
views
Detect nullable enum type in source generator
I'm writing a source generator that processes my model classes and adds some custom serialisation code for them. The model classes can have all sorts of property types. I'm currently interested in the ...
1
vote
1
answer
568
views
Build errors when using CommunityToolkit.MVVM with Visual Studio extensions
I'm getting build errors despite the SourceGenerator apparently working correctly. Example code:
namespace VisGit.ViewModels
{
public partial class MainViewModel: ObservableObject
{
...
6
votes
1
answer
1k
views
How to force Visual Studio to regenerate files generated using Roslyn incremental generators?
How can I tell Visual Studio to regenerate files that are generated using Roslyn's incremental generator?
Context: I have a solution with a project containing custom generators and another project ...
0
votes
1
answer
425
views
Intellisense not finding generated code in referenced project
I'm working on a large code base with multiple linked projects, so I've decided to write some source generators to auto-generate some boilerplate code. My project structure looks something like this:
...
0
votes
0
answers
68
views
Using Compilation at later stages in generation pipeline
My generator needs to find all types in referenced projects which meet a specific criteria and generate a class for each of them using their method return types.
Example input (in a referenced project,...