netstandard2.0
enable
true
Generated
true
latest
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath> <IsRoslynComponent>true</IsRoslynComponent>
上面是关键的三个配置
-
Save it.
-
Add a Console Application project with some examples of code you would like to test the SourceGenerator with.
-
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>
-
Save it.
-
Right click on the SourceGenerator project
-
Click
Properties
.
-
Click
Debug
.
-
Click
Open debug launch profiles UI
.
-
Click on
Delete
to delete the profile shown.
-
Click on
Add
-
Select
Roslyn component
.
-
In
Target project
select the Console Application project.
-
Close the UI.
-
Restart Visual Studio 2022.
-
In the debug profiles dropdown next to the
Play
button, select your SourceGenerator project.
-
Put a break point in your SourceGenerator to make sure the debugger stops.
-
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.