1

I want to write a new project with Roslyn Analyzer in .NET 7 My purpose is that to find all references for a method in a project as programmatically.

I loaded the solution like the below code.

_workspace = MSBuildWorkspace.Create();
_workspace.LoadMetadataForReferencedProjects = true;
      
var solution = await _workspace.OpenSolutionAsync(solutionFilenamePath, cancellationToken: cancellationToken);
_workspace.TryApplyChanges(solution);

After this operation, I can see all of the project in the solution. But I cannot see documents in these projects.

My references:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <EnableNETAnalyzers>true</EnableNETAnalyzers>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Build" Version="17.5.0" />
    <PackageReference Include="Microsoft.Build.Framework" Version="17.5.0" />
    <PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.5.0" />
    <PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.5.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.5.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.5.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.5.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.5.0" />
  </ItemGroup>

</Project>

What is my issue? I could not find.

Is Roslyn still not supported in .Net 7?

BTW, I worked successfully with .NET Framework 4.8

1

1 Answer 1

-1

The issue is with Visual Studio. It internally still uses .NET Framework so all the plugins are restricted to it.

Sign up to request clarification or add additional context in comments.

1 Comment

The code in question appears to be intended as a regular executable console app. So the fact that VS is .NET Framework seems irrelevant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.