/// <summary>
        /// Syncs the scripting solution if any affected files are relevant.
        /// </summary>
        /// <returns>
        /// Whether the solution was synced.
        /// </returns>
        /// <param name='affectedFiles'>
        /// A set of files whose status has changed
        /// </param>
        /// <param name="reimportedFiles">
        /// A set of files that got reimported
        /// </param>
        public bool SyncIfNeeded(List <string> affectedFiles, string[] reimportedFiles)
        {
            Profiler.BeginSample("SolutionSynchronizerSync");
            SetupProjectSupportedExtensions();

            // Don't sync if we haven't synced before
            if (SolutionExists() && HasFilesBeenModified(affectedFiles, reimportedFiles))
            {
                var assemblies           = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);
                var allProjectAssemblies = RelevantAssembliesForMode(assemblies).ToList();
                var allAssetProjectParts = GenerateAllAssetProjectParts();

                var affectedNames         = affectedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)?.Split(new [] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                var reimportedNames       = reimportedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)?.Split(new [] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                var affectedAndReimported = new HashSet <string>(affectedNames.Concat(reimportedNames));
                var assemblyNames         = new HashSet <string>(allProjectAssemblies.Select(assembly => Path.GetFileName(assembly.outputPath)));

                foreach (var assembly in allProjectAssemblies)
                {
                    if (!affectedAndReimported.Contains(assembly.name))
                    {
                        continue;
                    }

                    SyncProject(assembly, allAssetProjectParts, ParseResponseFileData(assembly), assemblyNames);
                }

                Profiler.EndSample();
                return(true);
            }

            Profiler.EndSample();
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Syncs the scripting solution if any affected files are relevant.
        /// </summary>
        /// <returns>
        /// Whether the solution was synced.
        /// </returns>
        /// <param name='affectedFiles'>
        /// A set of files whose status has changed
        /// </param>
        /// <param name="reimportedFiles">
        /// A set of files that got reimported
        /// </param>
        public bool SyncIfNeeded(List <string> affectedFiles, string[] reimportedFiles)
        {
            Profiler.BeginSample("SolutionSynchronizerSync");
            SetupProjectSupportedExtensions();

            if (!HasFilesBeenModified(affectedFiles, reimportedFiles))
            {
                Profiler.EndSample();
                return(false);
            }

            var assemblies           = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);
            var allProjectAssemblies = RelevantAssembliesForMode(assemblies).ToList();

            SyncSolution(allProjectAssemblies);

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var affectedNames         = affectedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)).Where(name => !string.IsNullOrWhiteSpace(name)).Select(name => name.Split(new [] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
            var reimportedNames       = reimportedFiles.Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset)).Where(name => !string.IsNullOrWhiteSpace(name)).Select(name => name.Split(new [] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
            var affectedAndReimported = new HashSet <string>(affectedNames.Concat(reimportedNames));

            foreach (var assembly in allProjectAssemblies)
            {
                if (!affectedAndReimported.Contains(assembly.name))
                {
                    continue;
                }

                SyncProject(assembly, allAssetProjectParts, ParseResponseFileData(assembly));
            }

            Profiler.EndSample();
            return(true);
        }
        /// <summary>
        /// Syncs the scripting solution if any affected files are relevant.
        /// </summary>
        /// <returns>
        /// Whether the solution was synced.
        /// </returns>
        /// <param name='affectedFiles'>
        /// A set of files whose status has changed
        /// </param>
        /// <param name="reimportedFiles">
        /// A set of files that got reimported
        /// </param>
        public bool SyncIfNeeded(IEnumerable <string> affectedFiles, IEnumerable <string> reimportedFiles)
        {
            using (solutionSyncMarker.Auto())
            {
                // We need the exact VS version/capabilities to tweak project generation (analyzers/langversion)
                RefreshCurrentInstallation();

                SetupProjectSupportedExtensions();

                // See https://devblogs.microsoft.com/setup/configure-visual-studio-across-your-organization-with-vsconfig/
                // We create a .vsconfig file to make sure our ManagedGame workload is installed
                CreateVsConfigIfNotFound();

                // Don't sync if we haven't synced before
                var affected   = affectedFiles as ICollection <string> ?? affectedFiles.ToArray();
                var reimported = reimportedFiles as ICollection <string> ?? reimportedFiles.ToArray();
                if (!HasFilesBeenModified(affected, reimported))
                {
                    return(false);
                }

                var assemblies           = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);
                var allProjectAssemblies = RelevantAssembliesForMode(assemblies).ToList();
                SyncSolution(allProjectAssemblies);

                var allAssetProjectParts = GenerateAllAssetProjectParts();

                var affectedNames = affected
                                    .Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset))
                                    .Where(name => !string.IsNullOrWhiteSpace(name)).Select(name =>
                                                                                            name.Split(new[] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                var reimportedNames = reimported
                                      .Select(asset => m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset))
                                      .Where(name => !string.IsNullOrWhiteSpace(name)).Select(name =>
                                                                                              name.Split(new[] { ".dll" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                var affectedAndReimported = new HashSet <string>(affectedNames.Concat(reimportedNames));

                foreach (var assembly in allProjectAssemblies)
                {
                    if (!affectedAndReimported.Contains(assembly.name))
                    {
                        continue;
                    }

                    SyncProject(assembly,
                                allAssetProjectParts,
                                responseFilesData: ParseResponseFileData(assembly).ToArray());
                }

                return(true);
            }
        }
        public void GenerateAndWriteSolutionAndProjects(Type[] types)
        {
            // Only synchronize islands that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            var assemblies           = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution).ToArray();
            var assemblyNames        = new HashSet <string>(assemblies.Select(a => a.name));
            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var projectParts = new List <ProjectPart>();

            foreach (var assembly in assemblies)
            {
                allAssetProjectParts.TryGetValue(assembly.name, out var additionalAssetsForProject);
                projectParts.Add(new ProjectPart(assembly.name, assembly, additionalAssetsForProject));
            }

            var projectPartsWithoutAssembly = allAssetProjectParts.Where(a => !assemblyNames.Contains(a.Key));

            projectParts.AddRange(projectPartsWithoutAssembly.Select(allAssetProjectPart => new ProjectPart(allAssetProjectPart.Key, null, allAssetProjectPart.Value)));

            SyncSolution(projectParts.ToArray(), types);

            foreach (var projectPart in projectParts)
            {
                SyncProject(projectPart, types, GetAllRoslynAnalyzerPaths().ToArray());
            }
        }
        internal void GenerateAndWriteSolutionAndProjects(ScriptEditorUtility.ScriptEditor scriptEditor)
        {
            Profiler.BeginSample("GenerateAndWriteSolutionAndProjects");

            Profiler.BeginSample("SolutionSynchronizer.GetIslands");
            // Only synchronize islands that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            List <Compilation.Assembly> assemblies = m_assemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution).ToList();

            Profiler.EndSample();

            Profiler.BeginSample("GenerateAllAssetProjectParts.GetIslands");
            var allAssetProjectParts = GenerateAllAssetProjectParts();

            Profiler.EndSample();

            Profiler.BeginSample("SyncSolution");
            SyncSolution(assemblies);
            Profiler.EndSample();

            var allProjectAssemblies = RelevantAssembliesForMode(assemblies, ModeForCurrentExternalEditor()).ToList();

            foreach (Compilation.Assembly assembly in allProjectAssemblies)
            {
                Profiler.BeginSample("SyncProject");
                SyncProject(assembly, allAssetProjectParts, ParseResponseFileData(assembly), allProjectAssemblies);
                Profiler.EndSample();
            }

            Profiler.EndSample();
        }
        public void GenerateAndWriteSolutionAndProjects()
        {
            // Only synchronize assemblies that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            var assemblies = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var assemblyList = assemblies.ToList();

            SyncSolution(assemblyList);

            var allProjectAssemblies = RelevantAssembliesForMode(assemblyList).ToList();

            foreach (Assembly assembly in allProjectAssemblies)
            {
                SyncProject(assembly,
                            allAssetProjectParts,
                            responseFilesData: ParseResponseFileData(assembly),
                            allProjectAssemblies,
#if UNITY_2020_2_OR_NEWER
                            assembly.compilerOptions.RoslynAnalyzerDllPaths);
#else
                            Array.Empty <string>());
#endif
            }
        }
Beispiel #7
0
        public void GenerateAndWriteSolutionAndProjects(Type[] types)
        {
            // Only synchronize islands that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            var assemblies           = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution).ToArray();
            var assemblyNames        = new HashSet <string>(assemblies.Select(a => a.name));
            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var projectParts = new List <ProjectPart>();

            foreach (var assembly in assemblies)
            {
                allAssetProjectParts.TryGetValue(assembly.name, out var additionalAssetsForProject);
                projectParts.Add(new ProjectPart(assembly.name, assembly, additionalAssetsForProject));
            }

            var riderAssembly = m_AssemblyNameProvider.GetAssemblies(_ => true).FirstOrDefault(a => a.name == "Unity.Rider.Editor");
            var projectPartsWithoutAssembly = allAssetProjectParts.Where(a => !assemblyNames.Contains(a.Key));

            projectParts.AddRange(projectPartsWithoutAssembly.Select(allAssetProjectPart =>
            {
                Assembly assembly = null;
                if (riderAssembly != null)
                {
                    // We want to add those references, so that Rider would detect Unity path and version and provide rich features for shader files
                    assembly = new Assembly(allAssetProjectPart.Key, riderAssembly.outputPath, new string[0], new string[0],
                                            new Assembly[0],
                                            riderAssembly.compiledAssemblyReferences.Where(a =>
                                                                                           a.EndsWith("UnityEditor.dll") || a.EndsWith("UnityEngine.dll") ||
                                                                                           a.EndsWith("UnityEngine.CoreModule.dll")).ToArray(), riderAssembly.flags);
                }
                return(new ProjectPart(allAssetProjectPart.Key, assembly, allAssetProjectPart.Value));
            }));

            SyncSolution(projectParts.ToArray(), types);

            foreach (var projectPart in projectParts)
            {
                SyncProject(projectPart, types, GetAllRoslynAnalyzerPaths().ToArray());
            }
        }
        public void GenerateAndWriteSolutionAndProjects(Type[] types)
        {
            // Only synchronize islands that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            var assemblies = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            var monoIslands = assemblies.ToList();

            SyncSolution(monoIslands, types);

            foreach (var assembly in monoIslands)
            {
                var responseFileData = ParseResponseFileData(assembly);
                SyncProject(assembly, allAssetProjectParts, responseFileData, types, GetAllRoslynAnalyzerPaths().ToArray());
            }
        }
Beispiel #9
0
        public void GenerateAndWriteSolutionAndProjects()
        {
            // Only synchronize islands that have associated source files and ones that we actually want in the project.
            // This also filters out DLLs coming from .asmdef files in packages.
            var assemblies = m_AssemblyNameProvider.GetAssemblies(ShouldFileBePartOfSolution);

            var allAssetProjectParts = GenerateAllAssetProjectParts();

            SyncSolution(assemblies);
            var allProjectIslands = RelevantIslandsForMode(assemblies).ToList();

            foreach (Assembly assembly in allProjectIslands)
            {
                var responseFileData = ParseResponseFileData(assembly);
                SyncProject(assembly, allAssetProjectParts, responseFileData, allProjectIslands);
            }

            WriteVSCodeSettingsFiles();
        }