private static JSONValue JsonForProject()
        {
            var islands = EditorCompilationInterface.GetAllMonoIslands().Select(i => new Island
            {
                MonoIsland = i,
                Name       = Path.GetFileNameWithoutExtension(i._output),
                References = i._references.ToList()
            }).ToList();

            // Mono islands have references to each others output location. For MD we want to have the reference
            // be to the actual project, so we are going to update the references here
            foreach (Island island in islands)
            {
                var toAdd    = new List <string>();
                var toRemove = new List <string>();

                foreach (var reference in island.References)
                {
                    var refName = Path.GetFileNameWithoutExtension(reference);

                    if (reference.StartsWith("Library/") && islands.Any(i => i.Name == refName))
                    {
                        toAdd.Add(refName);
                        toRemove.Add(reference);
                    }

                    if (reference.EndsWith("/UnityEditor.dll") || reference.EndsWith("/UnityEngine.dll") ||
                        reference.EndsWith("\\UnityEditor.dll") || reference.EndsWith("\\UnityEngine.dll"))
                    {
                        toRemove.Add(reference);
                    }
                }

                island.References.Add(InternalEditorUtility.GetEditorAssemblyPath());
                island.References.Add(InternalEditorUtility.GetEngineAssemblyPath());

                foreach (var a in toAdd)
                {
                    island.References.Add(a);
                }

                foreach (var r in toRemove)
                {
                    island.References.Remove(r);
                }
            }

            var files            = islands.SelectMany(i => i.MonoIsland._files).Concat(GetAllSupportedFiles()).Distinct().ToArray();
            var emptyDirectories = RelativeToProjectPath(FindEmptyDirectories(AssetsPath, files));

            var result = new JSONValue();

            result["islands"]       = new JSONValue(islands.Select(i => JsonForIsland(i)).Where(i2 => !i2.IsNull()).ToList());
            result["basedirectory"] = ProjectPath;

            var assetDatabase = new JSONValue();

            assetDatabase["files"]            = ToJSON(files);
            assetDatabase["emptydirectories"] = ToJSON(emptyDirectories);

            result["assetdatabase"] = assetDatabase;
            return(result);
        }
        private string ProjectHeader(
            Assembly assembly,
            IEnumerable <ResponseFileData> responseFilesData,
            string[] roslynAnalyzerDllPaths
            )
        {
            var          toolsVersion   = "4.0";
            var          productVersion = "10.0.20506";
            const string baseDirectory  = ".";

            var targetFrameworkVersion = "v4.7.1";
            var targetLanguageVersion  = "latest";            // danger: latest is not the same absolute value depending on the VS version.

            if (m_CurrentInstallation != null && m_CurrentInstallation.SupportsCSharp8)
            {
                // Current VS installation is compatible with C# 8.

#if !UNITY_2020_2_OR_NEWER
                // Unity 2020.2.0a12 added support for C# 8
                // <=2020.1 has no support for C# 8 constructs, so tell the compiler to accept only C# 7.3 or lower.
                targetLanguageVersion = "7.3";
#endif
            }

            var projectType = ProjectTypeOf(assembly.name);

            var arguments = new object[]
            {
                toolsVersion,
                productVersion,
                ProjectGuid(assembly),
                XmlFilename(FileUtility.Normalize(InternalEditorUtility.GetEngineAssemblyPath())),
                XmlFilename(FileUtility.Normalize(InternalEditorUtility.GetEditorAssemblyPath())),
                string.Join(";", assembly.defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray()),
                MSBuildNamespaceUri,
                assembly.name,
                assembly.outputPath,
                GetRootNamespace(assembly),
                targetFrameworkVersion,
                targetLanguageVersion,
                baseDirectory,
                assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
                // flavoring
                projectType + ":" + (int)projectType,
                EditorUserBuildSettings.activeBuildTarget + ":" + (int)EditorUserBuildSettings.activeBuildTarget,
                Application.unityVersion,
                VisualStudioIntegration.PackageVersion()
            };

            try
            {
#if UNITY_2020_2_OR_NEWER
                return(string.Format(GetProjectHeaderTemplate(roslynAnalyzerDllPaths, assembly.compilerOptions.RoslynAnalyzerRulesetPath), arguments));
#else
                return(string.Format(GetProjectHeaderTemplate(Array.Empty <string>(), null), arguments));
#endif
            }
            catch (Exception)
            {
                throw new NotSupportedException("Failed creating c# project because the c# project header did not have the correct amount of arguments, which is " + arguments.Length);
            }
        }
Beispiel #3
0
 private static void OpenEditorAssemblyPath()
 {
     RevealInFinder(new FileInfo(InternalEditorUtility.GetEditorAssemblyPath()).Directory.FullName);
 }