public static void ExportTopLevelDependenciesProject(IUnityProjectExporter exporter, Version msb4uVerison, MSBuildToolsConfig config, DirectoryInfo generatedProjectFolder, UnityProjectInfo unityProjectInfo) { string projectPath = GetProjectFilePath(Utilities.AssetPath, $"{unityProjectInfo.UnityProjectName}.Dependencies"); ITopLevelDependenciesProjectExporter projectExporter = exporter.CreateTopLevelDependenciesProjectExporter(new FileInfo(projectPath), generatedProjectFolder); projectExporter.MSBuildForUnityVersion = msb4uVerison; projectExporter.Guid = config.DependenciesProjectGuid; if (unityProjectInfo.AvailablePlatforms != null) { Dictionary <BuildTarget, CompilationPlatformInfo> allPlatforms = unityProjectInfo.AvailablePlatforms.ToDictionary(t => t.BuildTarget, t => t); foreach (CSProjectInfo projectInfo in unityProjectInfo.CSProjects.Values) { List <string> platformConditions = GetPlatformConditions(allPlatforms, projectInfo.InEditorPlatforms.Keys); projectExporter.References.Add(new ProjectReference() { ReferencePath = new Uri(GetProjectPath(projectInfo, generatedProjectFolder).FullName), Condition = platformConditions.Count == 0 ? "false" : string.Join(" OR ", platformConditions), IsGenerated = true }); } } foreach (string otherProjectFile in unityProjectInfo.ExistingCSProjects) { projectExporter.References.Add(new ProjectReference() { ReferencePath = new Uri(otherProjectFile), IsGenerated = false }); } projectExporter.Write(); }
/// <summary> /// Parses the current state of the Unity project. /// </summary> /// <param name="supportedBuildTargets">BuildTargets that are considered supported.</param> /// <param name="config">Config for MSBuildTools.</param> /// <param name="performCompleteParse">If this is false, UnityProjectInfo will parse only the minimum required information about current project. Includes: <see cref="ExistingCSProjects"/> <see cref="CurrentPlayerPlatform"/>.</param> public UnityProjectInfo(ILogger logger, Dictionary <BuildTarget, string> supportedBuildTargets, MSBuildToolsConfig config, bool performCompleteParse = true) { this.logger = logger; this.config = config; if (performCompleteParse) { AvailablePlatforms = new ReadOnlyCollection <CompilationPlatformInfo>(CompilationPipeline.GetAssemblyDefinitionPlatforms() .Where(t => Utilities.IsPlatformInstalled(t.BuildTarget)) .Where(t => supportedBuildTargets.ContainsKey(t.BuildTarget)) .Select(CompilationPlatformInfo.GetCompilationPlatform) .OrderBy(t => t.Name).ToList()); EditorPlatform = CompilationPlatformInfo.GetEditorPlatform(); CurrentPlayerPlatform = AvailablePlatforms.First(t => t.BuildTarget == EditorUserBuildSettings.activeBuildTarget); } else { CurrentPlayerPlatform = CompilationPlatformInfo.GetCompilationPlatform( CompilationPipeline.GetAssemblyDefinitionPlatforms() .First(t => t.BuildTarget == EditorUserBuildSettings.activeBuildTarget)); } UnityProjectName = Application.productName; if (string.IsNullOrWhiteSpace(UnityProjectName)) { UnityProjectName = "UnityProject"; } RefreshPlugins(performCompleteParse); if (performCompleteParse) { RefreshProjects(); } }