2,928 questions
0
votes
1
answer
178
views
Roslyn Analyzer: How to handle a side effect of renaming classes
I'm writing a Roslyn analyzer that renames classes matching a certain pattern. The rename "fix" successfully renames the class, but in my unit test (which uses in-memory source which oddly ...
1
vote
1
answer
282
views
generate incoming call graph
I'm trying to pretty print the method calls until a specific method
for example let's take "DisplayHelp" from this simple random repository
I expect for something like
Shell.ctor -> ...
0
votes
1
answer
146
views
Roslyn: How to get .NET6.0 code compiled into one exe
I'm trying to compile this C# code:
using System;
namespace test
{
internal static class Program
{
static void Main()
{
Console....
0
votes
0
answers
66
views
Can't get Roslyn compiled executable working
I'm compiling this code with Visual Studio and with Roslyn (programically).
This is .NET 6.0 code.
using System;
namespace test
{
internal static class Program
{
...
1
vote
1
answer
490
views
Roslyn compiler does not see references
I'm trying to create a .NET 6.0 app that will be able to compile another .NET 6.0 app. The problem is Roslyn does not seem to see references.
These are some of the errors I received from Roslyn:
...
0
votes
1
answer
755
views
MSBuildWorkspace. The tools version "Current" is unrecognized
When I load certain old project into MSBuildWorkspace I get the Diagnostic error:
Msbuild failed when processing the file "...SomeProj.csproj" with
message: The tools version "Current&...
2
votes
1
answer
166
views
why is cmp + je in every method in C# JIT assembly code in Debug build
When you put a simple class.
public sealed class C {
public static void M() {
}
}
into https://sharplab.io/
it translates to (with annotations from me): (source)
C.M()
L0000: push ebp ...
1
vote
0
answers
97
views
Microsoft.CodeAnalysis: how do I ReplaceNodes into nodes of different NameSyntax type?
.NET Framework 4.6.1 (and I should not change version)
I'm fixing a code that translates one language from one version into a newer one.
For this a property named like "LastBarIndexPainted" ...
0
votes
1
answer
238
views
How can I qualify symbols within a Roslyn syntax with a CSharpSyntaxRewriter?
I'm writing a Roslyn source generator, where I need to grab the initializer from the VariableDeclaratorSyntax.Initializer of a field, and echo it back into a generated file.
For example, if I wrote ...
-1
votes
2
answers
221
views
how can i get MetadataReference from nupkg package in dotnet
I want get MetadataReference from nupkg package in dotnet
//https://learn.microsoft.com/zh-cn/nuget/reference/nuget-client-sdk
using FileStream inputStream = new FileStream("C:\\...
0
votes
1
answer
96
views
RoslynAnalyzer throws casting errors during build
I'm trying to build NLog in Visual Studio 2019 (Community edition, if that's relevant). NLog is not building due to the casting error below. I've searched the code for the "TypeParameterSymbol&...
2
votes
1
answer
239
views
Generate a 'readonly record struct' using Roslyn
I can't generate a readonly record struct using Roslyn.
My code:
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
var tree = SyntaxFactory.CompilationUnit()
.AddMembers(
...
1
vote
1
answer
63
views
CIL shows `box` ops when the generic type is constrained to a class
I have the following method:
public static bool EquivalentTo<T>(this T? current, T? compare)
where T : class
{
if (current is null && compare is null)
// both are null
...
0
votes
0
answers
201
views
How can I detect if C# compiler (Roslyn) is running to get IDE diagnostics on VSCode instead of explicit dotnet building?
Is there a csproj target or property that I can use to differentiate the automatic compilation that Roslyn LSP runs to give me diagnostics on VSCode from actual explicit build compilation?
I need to ...
4
votes
1
answer
521
views
Creating executable assembly at runtime
How can I compile a single code, as a string, into a working and standalone .exe file? I tried three different things:
CSharpCodeProvider: This works fine, but I need it for newer .NET 7 and this ...
2
votes
2
answers
276
views
In a C# Roslyn Analyzer, can I detect if a given Diagnostic is enabled?
I'm writing a Roslyn analyzer which detects certain patterns in the code that we don't like, and raising a Diagnostic (the specifics are irrelevant here).
However, detecting said patterns is ...
0
votes
0
answers
113
views
How to use the OpenAIClient in a Roslyn Analyzer without DiagnosticScopeFactory blocking it?
Im trying to write a Roslyn Analyzer which searches in code comments for some kind of hashtags and generates a Gpt prompt from it using the codefix lightbulb.
However when sending the gpt request I ...
1
vote
2
answers
941
views
How to get directly referenced projects in a Roslyn analyzer?
I have some C# projects that should have some configurations in the project that references them. I'd like to write a Roslyn analyzer(DiagnosticAnalyzer) to check if those directly referenced projects ...
0
votes
1
answer
124
views
Get shared project ".shproj" from a solution with Roslyn
I have a solution where I have a Shared Project of extension ".shproj"
I need to add a class to the project with Roslyn, but when I look in the list of projects, It does not contain the ...
1
vote
3
answers
4k
views
How to remove or turn off Roslyn Analyzer in VS Code?
Maybe it's from the recent VS Code update, It suddenly pops up..
it's highlighting some of my non-error codes in a blue line and sometimes it translucent some of my variables that doesn't have an ...
2
votes
2
answers
498
views
Source Generator Running on Indirectly Associated Projects
I have built an incremental source generator and packaged it into a nuget package to be consumed by a different solution. I have referenced it in my 'Models' project. The issue is that the Models ...
0
votes
1
answer
121
views
In Roslyn ToMinimalDisplayString method, what does 'position' argument mean?
I'm looking at this method in ISymbol:
string ToMinimalDisplayString(SemanticModel semanticModel, int position, SymbolDisplayFormat format = null);
The documentation says that position is "A ...
0
votes
1
answer
60
views
How to configure/remove fields from the "Configure your new project" when creating a new project template in visual studio
How can I remove certain fields from the "Configure your new project" when creating a new project template in visual studio?
For an example, there is a Framework section where you can choose ...
0
votes
1
answer
576
views
What exactly is represented by the "Compilation" object provided in a Roslyn IIncrementalGenerator?
According to the Incremental Generators documentation, an incremental generator will be called exactly once by the host regardless of how many projects are involved in the compilation:
...
0
votes
0
answers
114
views
Flaky `ApplicationSyntaxReference` on `AttributeData` with (Incremental) Source Generator
Unfortunately, I have no minimal sample of the issue, but I've pushed the repo publicly, where it should be reproducable: https://github.com/Yeah69/ContainerFeatureSampleComparison
I've implemented a ...