@@ -633,6 +633,7 @@ RegistryEntry packageEntry
633633 string ? meta ;
634634
635635 string fileExtension = Path . GetExtension ( fileInUnityPackage ) ;
636+
636637 if ( fileExtension == ".dll" )
637638 {
638639 meta = UnityMeta . GetMetaForDll (
@@ -664,6 +665,20 @@ RegistryEntry packageEntry
664665 // write meta file
665666 await WriteTextFileToTar ( tarArchive , $ "{ fileInUnityPackage } .meta", meta ) ;
666667 }
668+
669+ // Write analyzer asmdef
670+ // Check Analyzer Scope section: https://docs.unity3d.com/Manual/roslyn-analyzers.html
671+ var analyzerAsmdef = CreateAnalyzerAmsdef ( identity ) ;
672+ var analyzerAsmdefAsJson = analyzerAsmdef . ToJson ( ) ;
673+ string analyzerAsmdefFileName = $ "{ identity . Id } .asmdef";
674+ await WriteTextFileToTar ( tarArchive , analyzerAsmdefFileName , analyzerAsmdefAsJson ) ;
675+ await WriteTextFileToTar ( tarArchive , $ "{ analyzerAsmdefFileName } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , analyzerAsmdefFileName ) , ".asmdef" ) ! ) ;
676+
677+ // Write empty script (Necessary to compile the asmdef file)
678+ var emptyScriptContent = UnityScript . GetEmptyScript ( ) ;
679+ const string emptyScriptFileName = "EmptyScript.cs" ;
680+ await WriteTextFileToTar ( tarArchive , emptyScriptFileName , emptyScriptContent ) ;
681+ await WriteTextFileToTar ( tarArchive , $ "{ emptyScriptFileName } .meta", UnityMeta . GetMetaForExtension ( GetStableGuid ( identity , emptyScriptFileName ) , ".cs" ) ! ) ;
667682 }
668683
669684 // Get all known platform definitions
@@ -1067,6 +1082,15 @@ private static UnityPackage CreateUnityPackage(NpmPackageInfo npmPackageInfo, Np
10671082 return unityPackage ;
10681083 }
10691084
1085+ private static UnityAsmdef CreateAnalyzerAmsdef ( PackageIdentity packageIdentity )
1086+ {
1087+ return new ( )
1088+ {
1089+ Name = $ "{ packageIdentity . Id } _Unity", // Add _Unity suffix because Unity has a validation so that assemblies names do not collide with asmdefs assembly names
1090+ IncludePlatforms = new string [ ] { "Editor" }
1091+ } ;
1092+ }
1093+
10701094 private static Guid StringToGuid ( string text )
10711095 {
10721096 var guid = new byte [ 16 ] ;
0 commit comments