0

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

hakanaltindis
  • 99
  • 1
  • 11
  • this gist suggests your projects should have compilations: https://gist.github.com/DustinCampbell/32cd69d04ea1c08a16ae5c4cd21dd3a3 Where are you running this code? If it should run during compilation, a custom roslyn analyzer would be your best choice, I guess, have a look at this: https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix – Ardor May 11 '23 at 07:14

1 Answers1

-1

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

Antao Almada
  • 445
  • 5
  • 12
  • The code in question appears to be intended as a regular executable console app. So the fact that VS is .NET Framework seems irrelevant. – Youssef13 Aug 20 '23 at 07:31