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> /// Exports the core Unity props file. /// </summary> /// <param name="exporter">The overal exporter to use for creating exporters.</param> /// <param name="platform">The compilation platform to export.</param> /// <param name="inEditor">Whether to export the inEditor version.</param> public static void ExportCoreUnityPropFile(IUnityProjectExporter exporter, CompilationPlatformInfo platform, bool inEditor) { string configuration = inEditor ? "InEditor" : "Player"; FileInfo outputFile = new FileInfo(Path.Combine(Utilities.MSBuildProjectFolder, $"{platform.Name}.{configuration}.props")); IPlatformPropsExporter propsExporter = (!inEditor && platform.BuildTarget == BuildTarget.WSAPlayer) ? CreateWSAPlayerExporter(exporter, outputFile, platform.ScriptingBackend) : exporter.CreatePlatformPropsExporter(outputFile, configuration, platform.Name, platform.ScriptingBackend); propsExporter.TargetFramework = platform.TargetFramework.AsMSBuildString(); propsExporter.DefineConstants.AddRange(platform.CommonPlatformDefines); propsExporter.DefineConstants.AddRange(inEditor ? platform.AdditionalInEditorDefines : platform.AdditionalPlayerDefines); // Common references foreach (string reference in platform.CommonPlatformReferences) { propsExporter.References[Path.GetFileNameWithoutExtension(reference)] = new Uri(reference); propsExporter.AssemblySearchPaths.Add(Path.GetDirectoryName(reference)); } // Additional references foreach (string reference in (inEditor ? platform.AdditionalInEditorReferences : platform.AdditionalPlayerReferences)) { propsExporter.References[Path.GetFileNameWithoutExtension(reference)] = new Uri(reference); propsExporter.AssemblySearchPaths.Add(Path.GetDirectoryName(reference)); } propsExporter.Write(); }
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(); } }
/// <summary> /// Exports the common MSBuildForUnity.Common.props file. /// </summary> /// <param name="exporter">The overal exporter to use for creating exporters.</param> /// <param name="currentPlayerPlatform">Current unity platform.</param> public static void ExportCommonPropsFile(IUnityProjectExporter exporter, Version msb4uVersion, CompilationPlatformInfo currentPlayerPlatform) { ICommonPropsExporter propsExporter = exporter.CreateCommonPropsExporter(new FileInfo(Path.Combine(Utilities.ProjectPath, "MSBuildForUnity.Common.props"))); propsExporter.MSBuildForUnityVersion = msb4uVersion; string[] versionParts = Application.unityVersion.Split('.'); propsExporter.UnityMajorVersion = versionParts[0]; propsExporter.UnityMinorVersion = versionParts[1]; propsExporter.UnityEditorInstallPath = new DirectoryInfo(Path.GetDirectoryName(EditorApplication.applicationPath)); propsExporter.GeneratedProjectOutputPath = new DirectoryInfo(Utilities.MSBuildOutputFolder); propsExporter.UnityProjectAssetsDirectory = new DirectoryInfo(Utilities.AssetPath); propsExporter.CurrentTargetFramework = currentPlayerPlatform.TargetFramework.AsMSBuildString(); propsExporter.CurrentUnityPlatform = currentPlayerPlatform.Name; propsExporter.Write(); }
private static IPlatformPropsExporter CreateWSAPlayerExporter(IUnityProjectExporter exporter, FileInfo outputFile, ScriptingBackend scriptingBackend) { IWSAPlayerPlatformPropsExporter uwpExporter = exporter.CreateWSAPlayerPlatformPropsExporter(outputFile, scriptingBackend); string minUWPPlatform = EditorUserBuildSettings.wsaMinUWPSDK; if (string.IsNullOrWhiteSpace(minUWPPlatform) || new Version(minUWPPlatform) < MSBuildTools.DefaultMinUWPSDK) { minUWPPlatform = MSBuildTools.DefaultMinUWPSDK.ToString(); } string targetUWPPlatform = EditorUserBuildSettings.wsaUWPSDK; if (string.IsNullOrWhiteSpace(targetUWPPlatform)) { targetUWPPlatform = Utilities.GetUWPSDKs().Max().ToString(4); } uwpExporter.MinimumUWPVersion = minUWPPlatform; uwpExporter.TargetUWPVersion = targetUWPPlatform; return(uwpExporter); }
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(); }