private static void SetBuildEvent(VSProject project, string name, string value) { // Remove old build event property if existed. if (project.FindProperty(name, out var group, out var property)) { group.RemoveChild(property); if (group.Count == 0) { project.Xml.RemoveChild(group); } } // Add new build event property. var buildEventGroup = project.CreatePropertyGroupAfter(project.MSBuildToolsImport); buildEventGroup.AddProperty(name, value); }
private static void ConfigureUnityPlugins(Configs.UnityPlugins config) { foreach (var kvp in config.ManagedProjects) { var projPath = kvp.Key; LoggedConsole.WriteInfo($@"Configure c# project '{projPath}'."); var vsproj = VSProject.GetOrLoad(projPath); if (vsproj == null) { LoggedConsole.WriteWarn($"Failed to load project at '{projPath}', skipped."); continue; } var parameter = CSharpProjectConfigurator.ParseUnityPluginParameter(config, kvp.Value); CSharpProjectConfigurator.SetupUnityPluginProject(vsproj, parameter); } }
private static void TryRun(CommandLineOptions options) { var errorOccus = false; try { RunImpl(options); } catch (Exception e) { LoggedConsole.WriteError(e); errorOccus = true; } finally { VSProject.UnloadAll(); } LoggedConsole.WriteInfo(errorOccus ? "Error occurred..." : "Done!"); }
public SLNToolsProject SetupCSharpProject(VSProject project, Configs.UnityProject.PluginProject config) { if (SolutionFile == null) { throw new InvalidOperationException("Solution file not found."); } if (project == null) { throw new ArgumentNullException(nameof(project)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } // Clone a new project for modification for solution. var newPath = Path.Combine(ProjectDirectory.FullName, Path.GetFileName(project.FilePath)); project = VSProject.Clone(project, newPath, true); // Select configuration groups of the project for solution. var targetConfigurations = SelectConfigurationsForSolution(project, config.Configurations); SelectConfigurationPropertyGroups(project, targetConfigurations, out var targetPropertyGroups, out var redundantPropertyGroups); SelectConfigurationItemGroups(project, targetConfigurations, out _, out var redundantItemGroups); // Remove redundant configuration groups. project.RemovePropertyGroups(redundantPropertyGroups); project.RemoveItemGroups(redundantItemGroups); // Setup configuration groups. SetupOutputPath(project, targetPropertyGroups); // Setup build events. SetupPostBuildEvent(project, config); project.Save(); RemoveCSharpProject(newPath); return(AddProjectToSolutionFile(project, targetPropertyGroups)); }
public static void SetupUnityPluginProject(VSProject project, UnityPluginParameter parameter) { Ensure.Argument.NotNull(project, nameof(project)); Ensure.Argument.NotNull(parameter, nameof(parameter)); var versions = parameter.Versions; if (versions == null) { return; } project.RemovePropertyGroups(project.ParseConditionalConfigurationPropertyGroups((string)null)); project.RemoveItemGroups(project.ParseConditionalConfigurationItemGroups((string)null)); var propertyGroupAnchor = project.DefaultPropertyGroup; var itemGroupAnchor = project.DefaultReferenceGroup; foreach (var kvp in versions) { var ver = kvp.Key; var info = kvp.Value; foreach (var type in EnumTraits <ProjectConfigurationType> .Values) { SetupConfigurationGroupForUnity( propertyGroupAnchor = project.CreatePropertyGroupAfter(propertyGroupAnchor), type, parameter.ForEditor, ver); var references = info.AssemblyReferences; if (!CollectionUtil.IsNullOrEmpty(references)) { SetupReferenceGroupForUnity( itemGroupAnchor = project.CreateItemGroupAfter(itemGroupAnchor), type, parameter.ForEditor, ver, references); } } } }
private static void Run(CommandLineOptions options) { RunImpl(options); VSProject.UnloadAll(); }
private static string GetOutputPath(VSProject project, ProjectConfigurationType type) => $@"Temp\{project.Name}_bin\{type}";
private static string GetIntermediateOutputPath(VSProject project, ProjectConfigurationType type) => $@"Temp\{project.Name}_obj\{type}";
private static void UnloadImpl(string path, VSProject instance) { instances.Remove(path); instance.Dispose(); }
private static VSProject AddInstance(VSProject instance) { instances.Add(instance.FilePath, instance); return(instance); }