Example #1
0
        public static void RebuildSolution()
        {
            foreach (var file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.csproj"))
            {
                File.Delete(file);
            }

            foreach (var file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln"))
            {
                File.Delete(file);
            }

            Type            type = typeof(UEditor).Assembly.GetType("UnityEditor.VisualStudioIntegration.SolutionSynchronizer");
            ConstructorInfo ctor = type.GetConstructor(new[] { typeof(string) });
            object          sync = ctor.Invoke(new object[] { Directory.GetParent(Application.dataPath).FullName });

            if (sync == null)
            {
                return;
            }
            var rewriteSolutionMethod = type.GetMethod("GenerateAndWriteSolutionAndProjects", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            if (rewriteSolutionMethod == null)
            {
                return;
            }
            var scriptEditor = ScriptEditorUtility.GetScriptEditorFromPreferences();

            rewriteSolutionMethod.Invoke(sync, new object[] { scriptEditor });

            CsProjectPostProcessor.OnGeneratedCSProjectFiles();
        }
Example #2
0
        public void Sync()
        {
            Profiler.BeginSample("SolutionSynchronizerSync");
            // Do not sync solution until all Unity extensions are registered and initialized.
            // Otherwise Unity might emit errors when VSTU tries to generate the solution and
            // get all managed extensions, which not yet initialized.
            if (!InternalEditorUtility.IsUnityExtensionsInitialized())
            {
                Profiler.EndSample();
                return;
            }

            SetupProjectSupportedExtensions();

            bool externalCodeAlreadyGeneratedProjects = AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles();

            if (!externalCodeAlreadyGeneratedProjects)
            {
                #pragma warning disable 618
                var scriptEditor = ScriptEditorUtility.GetScriptEditorFromPreferences();
                GenerateAndWriteSolutionAndProjects(scriptEditor);
            }

            AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles();
            Profiler.EndSample();
        }
Example #3
0
 public void Sync()
 {
     this.SetupProjectSupportedExtensions();
     if (!AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles())
     {
         ScriptEditorUtility.ScriptEditor scriptEditorFromPreferences = ScriptEditorUtility.GetScriptEditorFromPreferences();
         if (scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.SystemDefault || scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.Other)
         {
             return;
         }
         IEnumerable <MonoIsland> islands = from i in EditorCompilationInterface.GetAllMonoIslands()
                                            where 0 < i._files.Length && i._files.Any((string f) => this.ShouldFileBePartOfSolution(f))
                                            select i;
         Dictionary <string, string> allAssetsProjectParts = this.GenerateAllAssetProjectParts();
         string[] responseFileDefinesFromFile = ScriptCompilerBase.GetResponseFileDefinesFromFile(MonoCSharpCompiler.ReponseFilename);
         this.SyncSolution(islands);
         List <MonoIsland> list = SolutionSynchronizer.RelevantIslandsForMode(islands, SolutionSynchronizer.ModeForCurrentExternalEditor()).ToList <MonoIsland>();
         foreach (MonoIsland current in list)
         {
             this.SyncProject(current, allAssetsProjectParts, responseFileDefinesFromFile, list);
         }
         if (scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
         {
             this.WriteVSCodeSettingsFiles();
         }
     }
     AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles();
 }
Example #4
0
        private string ProjectHeader(MonoIsland island, string[] additionalDefines)
        {
            string            text     = "v3.5";
            string            text2    = "4";
            string            text3    = "4.0";
            string            text4    = "10.0.20506";
            string            text5    = ".";
            ScriptingLanguage language = SolutionSynchronizer.ScriptingLanguageFor(island);

            if (PlayerSettingsEditor.IsLatestApiCompatibility(island._api_compatibility_level))
            {
                text  = "v4.6";
                text2 = "6";
            }
            else if (ScriptEditorUtility.GetScriptEditorFromPreferences() == ScriptEditorUtility.ScriptEditor.Rider)
            {
                text = "v4.5";
            }
            else if (this._settings.VisualStudioVersion == 9)
            {
                text3 = "3.5";
                text4 = "9.0.21022";
            }
            object[] array = new object[]
            {
                text3,
                text4,
                this.ProjectGuid(island._output),
                this._settings.EngineAssemblyPath,
                this._settings.EditorAssemblyPath,
                string.Join(";", new string[]
                {
                    "DEBUG",
                    "TRACE"
                }.Concat(this._settings.Defines).Concat(island._defines).Concat(additionalDefines).Distinct <string>().ToArray <string>()),
                SolutionSynchronizer.MSBuildNamespaceUri,
                Path.GetFileNameWithoutExtension(island._output),
                EditorSettings.projectGenerationRootNamespace,
                text,
                text2,
                text5
            };
            string result;

            try
            {
                result = string.Format(this._settings.GetProjectHeaderTemplate(language), array);
            }
            catch (Exception)
            {
                throw new NotSupportedException("Failed creating c# project because the c# project header did not have the correct amount of arguments, which is " + array.Length);
            }
            return(result);
        }
        private string ProjectHeader(MonoIsland island,
                                     ScriptCompilerBase.ResponseFileData responseFileData)
        {
            string            targetframeworkversion = "v3.5";
            string            targetLanguageVersion  = "4";
            string            toolsversion           = "4.0";
            string            productversion         = "10.0.20506";
            string            baseDirectory          = ".";
            ScriptingLanguage language = ScriptingLanguageFor(island);

            if (PlayerSettingsEditor.IsLatestApiCompatibility(island._api_compatibility_level))
            {
                if (ScriptEditorUtility.GetScriptEditorFromPreferences() == ScriptEditorUtility.ScriptEditor.Rider ||
                    ScriptEditorUtility.GetScriptEditorFromPreferences() == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
                {
                    targetframeworkversion = "v4.5";
                }
                else
                {
                    targetframeworkversion = "v4.7.1";
                }
                targetLanguageVersion = "7.2";
            }
            else if (_settings.VisualStudioVersion == 9)
            {
                toolsversion   = "3.5";
                productversion = "9.0.21022";
            }

            var arguments = new object[]
            {
                toolsversion, productversion, ProjectGuid(island._output),
                _settings.EngineAssemblyPath,
                _settings.EditorAssemblyPath,
                string.Join(";", new[] { "DEBUG", "TRACE" }.Concat(island._defines).Concat(responseFileData.Defines).Distinct().ToArray()),
                MSBuildNamespaceUri,
                Path.GetFileNameWithoutExtension(island._output),
                EditorSettings.projectGenerationRootNamespace,
                targetframeworkversion,
                targetLanguageVersion,
                baseDirectory,
                island._allowUnsafeCode | responseFileData.Unsafe
            };

            try
            {
                return(string.Format(_settings.GetProjectHeaderTemplate(language), arguments));
            }
            catch (Exception)
            {
                throw new System.NotSupportedException("Failed creating c# project because the c# project header did not have the correct amount of arguments, which is " + arguments.Length);
            }
        }
Example #6
0
        private static Mode ModeForCurrentExternalEditor()
        {
            #pragma warning disable 618
            var scriptEditor = ScriptEditorUtility.GetScriptEditorFromPreferences();

            if (scriptEditor == ScriptEditorUtility.ScriptEditor.VisualStudio ||
                scriptEditor == ScriptEditorUtility.ScriptEditor.VisualStudioExpress)
            {
                return(Mode.UnityScriptAsPrecompiledAssembly);
            }

            return(EditorPrefs.GetBool("kExternalEditorSupportsUnityProj", false) ? Mode.UnityScriptAsUnityProj : Mode.UnityScriptAsPrecompiledAssembly);
        }
Example #7
0
 private static SolutionSynchronizer.Mode ModeForCurrentExternalEditor()
 {
     ScriptEditorUtility.ScriptEditor scriptEditorFromPreferences = ScriptEditorUtility.GetScriptEditorFromPreferences();
     SolutionSynchronizer.Mode        result;
     if (scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.VisualStudio || scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.VisualStudioExpress || scriptEditorFromPreferences == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
     {
         result = SolutionSynchronizer.Mode.UnityScriptAsPrecompiledAssembly;
     }
     else
     {
         result = ((!EditorPrefs.GetBool("kExternalEditorSupportsUnityProj", false)) ? SolutionSynchronizer.Mode.UnityScriptAsPrecompiledAssembly : SolutionSynchronizer.Mode.UnityScriptAsUnityProj);
     }
     return(result);
 }
        public void Sync()
        {
            SetupProjectSupportedExtensions();

            bool externalCodeAlreadyGeneratedProjects = AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles();

            if (!externalCodeAlreadyGeneratedProjects)
            {
                var scriptEditor = ScriptEditorUtility.GetScriptEditorFromPreferences();
                GenerateAndWriteSolutionAndProjects(scriptEditor);
            }

            AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles();
        }
Example #9
0
        public void Sync()
        {
            SetupProjectSupportedExtensions();

            bool externalCodeAlreadyGeneratedProjects = AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles();

            if (!externalCodeAlreadyGeneratedProjects)
            {
                var scriptEditor = ScriptEditorUtility.GetScriptEditorFromPreferences();

                // Do not generate .sln and .csproj for unsupported code editors.
                if (scriptEditor == ScriptEditorUtility.ScriptEditor.SystemDefault || scriptEditor == ScriptEditorUtility.ScriptEditor.Other)
                {
                    return;
                }

                GenerateAndWriteSolutionAndProjects(scriptEditor);
            }

            AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles();
        }
Example #10
0
 public void Sync()
 {
     this.SetupProjectSupportedExtensions();
     if (!AssetPostprocessingInternal.OnPreGeneratingCSProjectFiles())
     {
         IEnumerable <MonoIsland> islands = from i in InternalEditorUtility.GetMonoIslands()
                                            where 0 < i._files.Length
                                            select i;
         string   otherAssetsProjectPart      = this.GenerateAllAssetProjectPart();
         string[] responseFileDefinesFromFile = ScriptCompilerBase.GetResponseFileDefinesFromFile(MonoCSharpCompiler.ReponseFilename);
         this.SyncSolution(islands);
         foreach (MonoIsland current in SolutionSynchronizer.RelevantIslandsForMode(islands, SolutionSynchronizer.ModeForCurrentExternalEditor()))
         {
             this.SyncProject(current, otherAssetsProjectPart, responseFileDefinesFromFile);
         }
         if (ScriptEditorUtility.GetScriptEditorFromPreferences() == ScriptEditorUtility.ScriptEditor.VisualStudioCode)
         {
             this.WriteVSCodeSettingsFiles();
         }
     }
     AssetPostprocessingInternal.CallOnGeneratedCSProjectFiles();
 }