/// <summary> /// Parses an asmdef file creating a new instance of <see cref="AssemblyDefinitionInfo"/>. /// </summary> /// <param name="file">The file representing asmdef.</param> /// <param name="unityProjectInfo">Instance of <see cref="UnityProjectInfo"/>,</param> /// <param name="assembly">The Unity assembly reference.</param> /// <param name="isBuiltInPackage">True whether this asmdef lives in the editor installation folder.</param> /// <returns></returns> public static AssemblyDefinitionInfo Parse(FileInfo file, UnityProjectInfo unityProjectInfo, Assembly assembly, bool isBuiltInPackage = false) { if (file.Extension != ".asmdef") { throw new ArgumentException($"Given file '{file.FullName}' is not an assembly definition file."); } else if (!file.Exists) { throw new ArgumentException($"Given file '{file.FullName}' does not exist."); } AssemblyDefinitionInfo toReturn = JsonUtility.FromJson <AssemblyDefinitionInfo>(File.ReadAllText(file.FullName)); if (!Utilities.TryGetGuidForAsset(file, out Guid guid)) { Debug.LogError($"Failed to parse AsmDef meta for asm def: '{file.FullName}', didn't find guid."); } toReturn.assembly = assembly; toReturn.Directory = file.Directory; toReturn.file = file; toReturn.Guid = guid; toReturn.BuiltInPackage = isBuiltInPackage; toReturn.Validate(unityProjectInfo.AvailablePlatforms); toReturn.PrecompiledAssemblyReferences = new HashSet <string>(toReturn.precompiledReferences?.Select(t => t.Replace(".dll", string.Empty)) ?? Array.Empty <string>()); return(toReturn); }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="unityProjectInfo">Instance of parsed unity project info.</param> /// <param name="guid">The unique Guid of this reference item.</param> /// <param name="referencePath">The output path to the reference item.</param> /// <param name="name">The name of the reference.</param> protected ReferenceItemInfo(UnityProjectInfo unityProjectInfo, Guid guid, Uri referencePath, string name) { UnityProjectInfo = unityProjectInfo; Guid = guid; ReferencePath = referencePath; Name = name; }
/// <summary> /// Creates a new instance of the <see cref="PluginAssemblyInfo"/>. /// </summary> public PluginAssemblyInfo(UnityProjectInfo unityProjectInfo, Guid guid, string fullPath, PluginType type) : base(unityProjectInfo, guid, new Uri(fullPath), Path.GetFileNameWithoutExtension(fullPath)) { Type = type; if (Type == PluginType.Managed) { ParseYAMLFile(); } }
private static void RunGenerateSDKProjects() { // Create a copy of the packages as they might change after we create the MSBuild project string generatedProjectPath = Path.Combine(Utilities.MSBuildOutputFolder, "Projects"); try { Utilities.EnsureCleanDirectory(generatedProjectPath); } catch (IOException ex) { if (ex.Message.Contains(@"db.lock")) { Debug.LogError("Generated project appears to be still open with Visual Studio."); throw new InvalidDataException("Generated project appears to be still open with Visual Studio.", ex); } else { throw; } } Utilities.EnsureCleanDirectory(Path.Combine(Utilities.MSBuildOutputFolder, "Output")); MakePackagesCopy(Utilities.MSBuildOutputFolder); List <CompilationPlatformInfo> platforms = CompilationPipeline.GetAssemblyDefinitionPlatforms() .Where(t => supportedBuildTargets.Contains(t.BuildTarget)) .Select(CompilationPlatformInfo.GetCompilationPlatform) .OrderBy(t => t.Name) .ToList(); CompilationPlatformInfo editorPlatform = CompilationPlatformInfo.GetEditorPlatform(); CreateCommonPropsFile(platforms, editorPlatform, generatedProjectPath); UnityProjectInfo unityProjectInfo = new UnityProjectInfo(platforms, generatedProjectPath); // Read the solution template string solutionTemplateText = File.ReadAllText(Utilities.GetAssetsRelativePathFrom(TemplateFiles.Instance.MSBuildSolutionTemplatePath)); // Read the project template string projectTemplateText = File.ReadAllText(Utilities.GetAssetsRelativePathFrom(TemplateFiles.Instance.SDKProjectFileTemplatePath)); unityProjectInfo.ExportSolution(solutionTemplateText, projectTemplateText, generatedProjectPath); foreach (string otherFile in TemplateFiles.Instance.OtherFiles) { File.Copy(otherFile, Path.Combine(generatedProjectPath, Path.GetFileName(otherFile))); } }
/// <summary> /// Creates a new instance of the CSProject info. /// </summary> /// <param name="unityProjectInfo">Instance of parsed unity project info.</param> /// <param name="guid">The unique Guid of this reference item.</param> /// <param name="assemblyDefinitionInfo">The associated Assembly-Definition info.</param> /// <param name="assembly">The Unity assembly object associated with this csproj.</param> /// <param name="baseOutputPath">The output path where everything will be outputted.</param> internal CSProjectInfo(UnityProjectInfo unityProjectInfo, AssemblyDefinitionInfo assemblyDefinitionInfo, string baseOutputPath) : base(unityProjectInfo, assemblyDefinitionInfo.Guid, new Uri(Path.Combine(baseOutputPath, $"{assemblyDefinitionInfo.Name}.csproj")), assemblyDefinitionInfo.Name) { AssemblyDefinitionInfo = assemblyDefinitionInfo; ProjectType = GetProjectType(assemblyDefinitionInfo); InEditorPlatforms = GetCompilationPlatforms(true); PlayerPlatforms = GetCompilationPlatforms(false); if (InEditorPlatforms.Count == 0 && PlayerPlatforms.Count == 0) { Debug.LogError($"The assembly project '{Name}' doesn't contain any supported in-editor or player platform targets."); } ProjectDependencies = new ReadOnlyCollection <CSProjectDependency <CSProjectInfo> >(csProjectDependencies); }