DefineでSourceGenerartorによるSource生成を制御 & ManualGeneratorのMac対応#9
Open
AtaruMatsudaira wants to merge 5 commits intoruccho:masterfrom
Open
DefineでSourceGenerartorによるSource生成を制御 & ManualGeneratorのMac対応#9AtaruMatsudaira wants to merge 5 commits intoruccho:masterfrom
AtaruMatsudaira wants to merge 5 commits intoruccho:masterfrom
Conversation
ruccho
reviewed
Jul 11, 2025
Comment on lines
+75
to
+84
| if (roslynContext.Compilation.AssemblyName != "UniTyped") | ||
| { | ||
| result = $""" | ||
| #if !UNITYPED_USER_DEFINE_DISABLE_SOURCE_GENERATOR | ||
| {result} | ||
| #endif | ||
| """; | ||
| } | ||
|
|
||
|
|
Owner
There was a problem hiding this comment.
Manual GeneratorとSource Generatorの間で同一入力を与えれば同一のコードが生成される状態を維持したいので、生成コード側に #if をつけるより、Source Generatorの実行時に定義済みのシンボルを参照して生成結果を変えるようにしたいんですが、どうでしょうか?
ちなみにRoslynではSyntaxTree.OptionsをCSharpParseOptionsにダウンキャストすると、定義済みのシンボルを引っ張ってくることができます。
https://learn.microsoft.com/ja-jp/dotnet/api/microsoft.codeanalysis.csharp.csharpparseoptions.preprocessorsymbolnames?view=roslyn-dotnet-4.3.0#microsoft-codeanalysis-csharp-csharpparseoptions-preprocessorsymbolnames
| }; | ||
| var fullProjectPath = Path.GetFullPath(item.projectPath); | ||
| var fullOutputFilePath = Path.GetFullPath(item.outputFile); | ||
| var args = $"--roll-forward Major {fullGeneratorPath} --project {fullProjectPath} --output {fullOutputFilePath}"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
SourceGeneratorが動作するUnityバージョンでもManual Generatorを利用したいモチベーションがあり、
の対応を行いました。
補足
ユーザ定義によるSourceGenerartorを無効にするDefineSymbolの追加と適応
ProjectReflectionGeneratorによって生成される成果物はDefineの対象外としています。
Manual Generatorを利用したいシチュエーションが、ローカルにAnimatorControllerなどのアセットが存在せずリモートで取得する場合などを想定しているため、
TagやLayerはManualGenerartorによる生成を必要としないためです。
Macにてdotnetのpath解決が失敗する不具合の修正
下記記事を参考に対応させていただきました。
https://zenn.dev/ruccho/articles/a5b58dc2cfecd6
dotnetのランタイムが.NET Core3.1以外で動作させる
.NET Core3.1は既にサポートされていないための対応となります。
dotnetコマンドのオプションに
--roll-forward Majorを指定することでメジャーバージョンを無視して、DLL等を実行するコトができるようになります。