添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
netstandard2.0 enable true Generated true latest
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath> <IsRoslynComponent>true</IsRoslynComponent>

上面是关键的三个配置

  1. Save it.
  2. Add a Console Application project with some examples of code you would like to test the SourceGenerator with.
  3. Edit the Console Application porject and add a reference to the SourceGenerator this way:
  <ItemGroup>
    <ProjectReference
      Include="..\MySourceGenerator\MySourceGenerator.csproj"
      OutputItemType="Analyzer"
      ReferenceOutputAssembly="false"/>
  </ItemGroup>
  1. Save it.
  1. Right click on the SourceGenerator project
  2. Click Properties .
  3. Click Debug .
  4. Click Open debug launch profiles UI .
  5. Click on Delete to delete the profile shown.
  6. Click on Add
  7. Select Roslyn component .
  8. In Target project select the Console Application project.
  9. Close the UI.
  10. Restart Visual Studio 2022.
  11. In the debug profiles dropdown next to the Play button, select your SourceGenerator project.
  12. Put a break point in your SourceGenerator to make sure the debugger stops.
  13. Click Play .

That’s All。

四、Unity使用Analyser

Refer to : https://docs.unity.cn/cn/2022.1/Manual/roslyn-analyzers.html

Of cousrse, there are some Pits you may encounter. Don’t wary, it’s an usual.