2,928 questions
1
vote
1
answer
110
views
How to navigate to a definition of a Symbol located in the external assembly
I have a VS extension with a custom "Code Map" tool window. It displays specific code elements in a tree view control. The tree view nodes support navigation to symbol definition on a double ...
0
votes
0
answers
21
views
Set NuGet tags at build time using reflection
I've got an application that has hundreds of plugins available as Nuget packages in a private repo.
The application's "Plugin Search" feature relies (in part) on embedding some metadata ...
1
vote
1
answer
77
views
Can I add a menu button to my Roslyn Analyzer I wrote for VS2022?
I am writing a Roslyn analyzer for visual studio 2022. I need to add a tool menu button for some extra functionality. However, I seem to not be able to link up those two projects. When I run the ...
1
vote
0
answers
46
views
How to Enforce Compile-Time Errors for Non-.NET Standard Assemblies in a .NET Standard Project?
I'm migrating several projects from .NET Framework to .NET Standard 2.0. As part of this migration, I need to ensure that all project references assemblies that are compatible with .NET Standard. ...
0
votes
2
answers
74
views
How to avoid build errors on "suggestions"?
I have a .NET 8 project I'm trying to build.
I get so many errors.
For example,
Now, in the editor, this "error" is set to "suggestion."
Here's my Code Style settings.
And ...
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;
...
2
votes
1
answer
122
views
Detect array 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 ...
0
votes
1
answer
84
views
Get caller information in C# for multiple calls on same line
On C# you can get some information about the caller of a method via the [Caller*] attributes. You can get the member name, file path and line number of the caller. But what happens when the method is ...
3
votes
1
answer
331
views
How to ban an entire namespace with BannedApiAnalyzers?
I am trying to ban the usage of Newtonsoft.Json package in my codebase, and I am trying to use the BannedApiAnalyzers Nuget package (latest stable version, 3.3.4).
My problem is that while I am able ...
0
votes
0
answers
108
views
How can I verify types passed to method at design or compile time?
I'm in a situation where there are many generated types from different domains/projects/systems, but there's a lot of overlap between them.
In the past I've used things like Automapper to provide some ...
0
votes
1
answer
754
views
Intellisense not seeing source generated from a local C# source generator
I have a solution which contains 4 projects. One of them is a Roslyn source generator, one is a class library which uses the source generator, one is a testing project which also uses the source ...
0
votes
0
answers
105
views
Operation is not supported in Roslyn (Scripting API) when published AOT
The goal is to create a simple test application that enables the loading of a script and accesses a predefined static class and outputs a value from this class to the console.
Version Used:
4.10.0-3....
1
vote
1
answer
219
views
C# detect primary constructor with Roslyn
I'm trying to analyse the primary constructor of a class but I can't find how. It should be possible to find it in the syntax tree, I don't want to create the semantic model.
The code is pretty ...
-1
votes
1
answer
83
views
Package-References to Roslyn not working when calling from native App
I have a problem generating C# code dynamically when the calling process is a native Win32 C++ application.
To narrow down the problem, I have created the following test projects:
DynCodeDll: .net5 ...
1
vote
1
answer
155
views
Roslyn and .net5
I try to use the Roslyn-compiler to compile some sourcecode at runtime. To do so I did
public static void compile()
{
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code);
}
Of course this ...
1
vote
1
answer
570
views
Source generators get the referencing project path - retrieve useful value from IncrementalValueProvider<string>
In order to execute some logic with a source generator on some files (image files more precisely) based on the folders structure of the targeted/referencing project, I need to get the path/directory ...
-1
votes
1
answer
275
views
Using Roslyn and .NET Core : how do I resolve "type or namespace name "Forms" does not exist in the namespace 'System.Windows'
I am developing a system that uses Roslyn to do runtime compilation of C# code.
I am adding assemblies using this code, passing the fully qualified assembly file name to the method.
public bool ...
0
votes
1
answer
995
views
Memory Leak caused by Roslyn, how do I contain it?
So I have this NET6.0 console application that acts as a sort of bridge between other apps for UDP messages.
To define how to send data out of my application have this profile system that consists in ...
0
votes
0
answers
139
views
Roslyn INamedTypeSymbol.ContainingNamespace.Name an empty string
I have an attribute I'm generating that contains a couple of constructor arguments, a string and a Type, and I'd really like to get the namespace of the Type, because I need to include that in the ...
1
vote
1
answer
82
views
No CS0184 warning for impossible check
Why does testB in this example not give a "warning CS0184: The given expression is never of the provided ('MyClass2') type" the same way that testA does?
class Program
{
void Main()
{...
3
votes
1
answer
649
views
C# runtime compilation complains The type 'Object' is defined in an assembly that is not referenced
I am trying to use Roslyn to compile C# code at runtime. My compilation function is as follows:
using System.Collections.Immutable;
using Basic.Reference.Assemblies;
using Microsoft.CodeAnalysis;
...
0
votes
0
answers
61
views
What is the equivalent of c# syntax analysis in razor?
I wanted to know if it exists an equivalent of Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree for razor or cshtml documents.
My goal is to generate razor document dynamically, and I don't want to do ...
0
votes
1
answer
160
views
Roslyn SemanticModel symbol resolution not working reliably
I'm writing a program that needs to analyze C# code and figure out, for each method invocation, exactly what method of what class is being called. The appropriate tools for this job would seem to be ...
0
votes
1
answer
907
views
Getting '"Microsoft.CSharp.Core.targets" was not found' when compiling with Microsoft.Build.Execution.BuildManager.DefaultBuildManager
I have a set of projects that successfully compile and build on Visual Studio 2022.
I'd like to build them programmatically. For this purpose, I created a builder project, that makes use of Microsoft....
1
vote
1
answer
252
views
SourceGenerator: Attribute NamedArguements is empty
I'm trying to build my first source generator, the source generator is designed to register hangfire recurring jobs and a basic version is working similar to the. You can see this on the master branch ...