private void AddReferenceToSet <T>(HashSet <T> set, Func <string, T> createReferenceFunc, IReadOnlyDictionary <BuildTarget, CompilationPlatformInfo> platforms, IEnumerable <BuildTarget> dependencyPlatforms)
        {
            List <string> platformConditions = MSBuildUnityProjectExporter.GetPlatformConditions(platforms, dependencyPlatforms);

            if (platformConditions.Count > 0)
            {
                set.Add(createReferenceFunc(string.Join(" OR ", platformConditions)));
            }
        }
        private static void ExportCoreUnityPropFiles(UnityProjectInfo unityProjectInfo)
        {
            foreach (CompilationPlatformInfo platform in unityProjectInfo.AvailablePlatforms)
            {
                // Check for specialized template, otherwise get the common one
                MSBuildUnityProjectExporter.ExportCoreUnityPropFile(Exporter, platform, true);
                MSBuildUnityProjectExporter.ExportCoreUnityPropFile(Exporter, platform, false);
            }

            MSBuildUnityProjectExporter.ExportCoreUnityPropFile(Exporter, unityProjectInfo.EditorPlatform, true);
        }
        private static void RegenerateEverything(UnityProjectInfo unityProjectInfo, bool completeGeneration)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            long postCleanupAndCopyStamp = 0, solutionExportStart = 0, solutionExportEnd = 0, exporterStart = 0, exporterEnd = 0, propsFileGenerationStart = 0, propsFileGenerationEnd = 0;

            try
            {
                if (Directory.Exists(Utilities.MSBuildProjectFolder))
                {
                    // Create a copy of the packages as they might change after we create the MSBuild project
                    foreach (string file in Directory.EnumerateFiles(Utilities.MSBuildProjectFolder, "*", SearchOption.TopDirectoryOnly))
                    {
                        File.SetAttributes(file, FileAttributes.Normal);
                        File.Delete(file);
                    }
                }
                else
                {
                    Directory.CreateDirectory(Utilities.MSBuildProjectFolder);
                }

                postCleanupAndCopyStamp = stopwatch.ElapsedMilliseconds;

                propsFileGenerationStart = stopwatch.ElapsedMilliseconds;
                MSBuildUnityProjectExporter.ExportCommonPropsFile(Exporter, MSBuildForUnityVersion, unityProjectInfo.CurrentPlayerPlatform);
                if (completeGeneration)
                {
                    ExportCoreUnityPropFiles(unityProjectInfo);
                }
                propsFileGenerationEnd = stopwatch.ElapsedMilliseconds;

                solutionExportStart = stopwatch.ElapsedMilliseconds;
                if (completeGeneration)
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(Utilities.MSBuildProjectFolder);
                    unityProjectInfo.ExportSolution(Exporter, new FileInfo(Exporter.GetSolutionFilePath(unityProjectInfo)), directoryInfo);
                    unityProjectInfo.ExportProjects(Exporter, directoryInfo);
                }
                MSBuildUnityProjectExporter.ExportTopLevelDependenciesProject(Exporter, MSBuildForUnityVersion, Config, new DirectoryInfo(Utilities.MSBuildProjectFolder), unityProjectInfo);
                solutionExportEnd = stopwatch.ElapsedMilliseconds;


                string nuGetConfigPath = Path.Combine(Utilities.AssetPath, Path.GetFileName(TemplateFiles.Instance.NuGetConfigPath));

                // Copy the NuGet.config file if it does not exist
                if (!File.Exists(nuGetConfigPath))
                {
                    File.Copy(TemplateFiles.Instance.NuGetConfigPath, nuGetConfigPath);
                }

                foreach (string otherFile in TemplateFiles.Instance.OtherFiles)
                {
                    File.Copy(otherFile, Path.Combine(Utilities.MSBuildProjectFolder, Path.GetFileName(otherFile)));
                }

                if (completeGeneration)
                {
                    string buildProjectsFile = "BuildProjects.proj";
                    if (!File.Exists(Path.Combine(Utilities.MSBuildOutputFolder, buildProjectsFile)))
                    {
                        GenerateBuildProjectsFile(buildProjectsFile, Exporter.GetSolutionFilePath(unityProjectInfo), unityProjectInfo.AvailablePlatforms);
                    }
                }
            }
            finally
            {
                stopwatch.Stop();
                Debug.Log($"Whole Generate Projects process took {stopwatch.ElapsedMilliseconds} ms; actual generation took {stopwatch.ElapsedMilliseconds - postCleanupAndCopyStamp}; solution export: {solutionExportEnd - solutionExportStart}; exporter creation: {exporterEnd - exporterStart}; props file generation: {propsFileGenerationEnd - propsFileGenerationStart}");
            }
        }
        public void Export(ICSharpProjectExporter exporter, DirectoryInfo generatedProjectDirectory)
        {
            exporter.Guid                = Guid;
            exporter.AllowUnsafe         = AssemblyDefinitionInfo.allowUnsafeCode;
            exporter.IsEditorOnlyProject = ProjectType == ProjectType.EditorAsmDef || ProjectType == ProjectType.PredefinedEditorAssembly;
            exporter.ProjectName         = Name;
            exporter.SourceIncludePath   = AssemblyDefinitionInfo.Directory;

            foreach (AssemblyDefinitionInfo nestedAsmDef in AssemblyDefinitionInfo.NestedAssemblyDefinitionFiles)
            {
                exporter.SourceExcludePaths.Add(nestedAsmDef.Directory);
            }

            // Set all of the references
            ProcessDepedencies(exporter.PluginReferences, PluginDependencies, exporter.AssemblySearchPaths, (i, c) => new PluginReference(i.Name, i.ReferencePath, c), i => i.ReferencePath.LocalPath);
            ProcessDepedencies(exporter.PluginReferences, WinMDDependencies, exporter.AssemblySearchPaths, (i, c) => new PluginReference(i.Name, i.ReferencePath, c), i => i.ReferencePath.LocalPath);
            ProcessDepedencies(exporter.ProjectReferences, ProjectDependencies, exporter.AssemblySearchPaths, (i, c) => new ProjectReference(new Uri(MSBuildUnityProjectExporter.GetProjectPath(i, generatedProjectDirectory).FullName), c, true));

            AddSupportedBuildPlatformPair(exporter, UnityConfigurationType.InEditor, InEditorPlatforms);
            AddSupportedBuildPlatformPair(exporter, UnityConfigurationType.Player, PlayerPlatforms);
        }
示例#5
0
        public void ExportProjects(IUnityProjectExporter unityProjectExporter, DirectoryInfo generatedProjectFolder)
        {
            foreach (KeyValuePair <string, CSProjectInfo> project in CSProjects)
            {
                bool isGenerated = project.Value.AssemblyDefinitionInfo.AssetLocation != AssetLocation.Package && project.Value.AssemblyDefinitionInfo.AssetLocation != AssetLocation.Project;

                ICSharpProjectExporter exporter = unityProjectExporter.CreateCSharpProjectExporter(MSBuildUnityProjectExporter.GetProjectPath(project.Value, generatedProjectFolder), generatedProjectFolder, isGenerated);
                exporter.DefaultPlatform = CurrentPlayerPlatform.Name;
                exporter.LanguageVersion = MSBuildTools.CSharpVersion;
                exporter.IsGenerated     = isGenerated;
                foreach (CompilationPlatformInfo platform in AvailablePlatforms)
                {
                    exporter.SupportedPlatforms.Add(platform.Name);
                }

                project.Value.Export(exporter, generatedProjectFolder);
                exporter.Write();
            }
        }
示例#6
0
        public void ExportSolution(IUnityProjectExporter unityProjectExporter, FileInfo solutionFilePath, DirectoryInfo generatedProjectsFolder)
        {
            SolutionFileInfo  solutionFileInfo = TextSolutionFileParser.ParseExistingSolutionFile(logger, solutionFilePath.FullName);
            ISolutionExporter exporter         = unityProjectExporter.CreateSolutionExporter(logger, solutionFilePath);

            //TODO we need to figure out how to handle existing projects

            // Remove known folders
            solutionFileInfo.Projects.Remove(config.BuiltInPackagesFolderGuid);
            solutionFileInfo.Projects.Remove(config.ImportedPackagesFolderGuid);
            solutionFileInfo.Projects.Remove(config.ExternalPackagesFolderGuid);

            // Process generated projects
            foreach (KeyValuePair <string, CSProjectInfo> projectPair in CSProjects)
            {
                Uri relativePath = Utilities.GetRelativeUri(solutionFilePath.Directory.FullName, MSBuildUnityProjectExporter.GetProjectPath(projectPair.Value, generatedProjectsFolder).FullName);
                exporter.AddProject(CreateSolutionProjectEntry(projectPair.Value, relativePath, solutionFileInfo), isGenerated: true);
            }

            // Add dependency project
            string dependencyProjectName = $"{UnityProjectName}.Dependencies.msb4u";

            exporter.AddProject(GetDependencyProjectReference(dependencyProjectName, $"{dependencyProjectName}.csproj"), isGenerated: true);

            // Process existing projects
            foreach (KeyValuePair <Guid, Project> projectPair in solutionFileInfo.Projects)
            {
                if (!exporter.Projects.ContainsKey(projectPair.Key) &&
                    !solutionFileInfo.MSB4UGeneratedItems.Contains(projectPair.Key) &&
                    projectPair.Value.TypeGuid != SolutionProject.FolderTypeGuid)
                {
                    exporter.AddProject(GetSolutionProjectEntryFrom(projectPair.Value, solutionFileInfo));
                }
            }

            // Bring forward the properties, then set the one we care about
            exporter.Properties.AddRange(solutionFileInfo.Properties);
            exporter.Properties["HideSolutionNode"] = "FALSE";

            // Bring forward the extensibility globals, then set the one we care about
            exporter.ExtensibilityGlobals.AddRange(solutionFileInfo.ExtensibilityGlobals);
            exporter.ExtensibilityGlobals["SolutionGuid"] = "{" + config.SolutionGuid.ToString().ToUpper() + "}";

            // Bring forward the pairs, and then set the platforms we know of
            exporter.ConfigurationPlatforms.AddRange(solutionFileInfo.ConfigPlatformPairs);
            foreach (CompilationPlatformInfo platform in AvailablePlatforms)
            {
                exporter.ConfigurationPlatforms.Add(new ConfigurationPlatformPair(UnityConfigurationType.InEditor, platform.Name));
                exporter.ConfigurationPlatforms.Add(new ConfigurationPlatformPair(UnityConfigurationType.Player, platform.Name));
            }

            // Set the folders by scanning for "projects" with folder type in old projects
            foreach (KeyValuePair <Guid, Project> folderPair in solutionFileInfo.Projects.Where(t => t.Value.TypeGuid == SolutionProject.FolderTypeGuid))
            {
                exporter.GetOrAddFolder(folderPair.Key, folderPair.Value.Name)
                .Children.AddRange(solutionFileInfo.ChildToParentNestedMappings.Where(t => t.Value == folderPair.Key).Select(t => t.Key));
            }

            Dictionary <AssetLocation, Tuple <Guid, string> > knownFolderMapping = GetKnownFolderMapping();

            // Confiure known folders for generated projects
            ProcessSetForKnownFolders(exporter, knownFolderMapping, CSProjects.Values, t => t.AssemblyDefinitionInfo.AssetLocation, t => t.Guid);

            //TODO handle existing projects

            exporter.AdditionalSections = solutionFileInfo.SolutionSections;

            exporter.Write();
        }