public UserConfig(IWizardConfig cfg, IXProject xp) : this(cfg) { if (xp == null) { return; } Namespace = GetValue(MSBuildProperties.DXP_NAMESPACE, xp); Platform = GetPlatform(xp); UseCecil = GetValue(MSBuildProperties.DXP_DDNS_CECIL, xp).ToBoolean(); var rawTimeout = GetValue(MSBuildProperties.DXP_TIMEOUT, xp); Compiler = new CompilerCfg() { genExpLib = GetValue(MSBuildProperties.DXP_GEN_EXP_LIB, xp).ToBoolean(), ordinalsBase = GetValue(MSBuildProperties.DXP_ORDINALS_BASE, xp).ToInteger(), ourILAsm = GetValue(MSBuildProperties.DXP_OUR_ILASM, xp).ToBoolean(), customILAsm = GetUnevaluatedValue(MSBuildProperties.DXP_CUSTOM_ILASM, xp), intermediateFiles = GetValue(MSBuildProperties.DXP_INTERMEDIATE_FILES, xp).ToBoolean(), timeout = String.IsNullOrWhiteSpace(rawTimeout) ? CompilerCfg.TIMEOUT_EXEC : rawTimeout.ToInteger(), peCheck = (PeCheckType)GetValue(MSBuildProperties.DXP_PE_CHECK, xp).ToInteger() }; }
/// <summary> /// Get projects that depend on the specified project. /// Including sequential referencing through other projects. /// /// https://github.com/3F/DllExport/pull/148#issuecomment-624831606 /// ProjectC -} ProjectA + ProjectB /// ProjectB -} ProjectA /// ... /// + /// ... ProjectC -} ProjectB -} ProjectA /// </summary> /// <param name="project"></param> /// <returns></returns> private IEnumerable <IXProject> GetSeqDependents(IXProject project) { bool GetSeqDependents(HashSet <string> dep) { foreach (var prj in dep) { if (prj.Guid() == project.ProjectGuid.Guid()) { return(true); } if (GetSeqDependents(Sln.ProjectDependencies.Dependencies[prj])) { return(true); } } return(false); } foreach (var dep in Sln.ProjectDependencies.Dependencies) { if (GetSeqDependents(dep.Value)) { var prj = GetProjectByGuid(Sln.Env.Projects, dep.Key); if (prj != null) { yield return(prj); } } } }
protected string GetPostProcEnv(PostProcType type, IXProject xp) { if (type != PostProcType.None) { return(GetUnevaluatedValue(MSBuildProperties.DXP_PROC_ENV, xp)); } return(null); }
protected Platform GetPlatform(IXProject project) { if (GetUnevaluatedValue(MSBuildProperties.DXP_PLATFORM, project) == Platform.Auto.ToString()) { return(Platform.Auto); } return(GetPlatform(GetValue(MSBuildProperties.PRJ_PLATFORM, project))); }
public UserConfig(IConfigInitializer cfg, IXProject project) : this(cfg?.Config, project) { if (cfg?.DDNS != null) { NSBuffer = cfg.DDNS.NSBuffer; DDNS = cfg.DDNS; } Log = cfg.Log; }
protected string GetPostProcCmd(PostProcType type, IXProject xp) { if (type == PostProcType.None) { return(null); } //TODO: return("..."); }
/// <summary> /// Get dependencies for the specified project. /// </summary> /// <param name="project"></param> /// <returns></returns> private IEnumerable <IXProject> GetDependencies(IXProject project) { foreach (var pguid in Sln.ProjectDependencies.Dependencies[project.ProjectGuid]) { var prj = GetProjectByGuid(Sln.Env.Projects, pguid); if (prj != null) { yield return(prj); } } }
/// <summary> /// Checking of equality by limited project attributes like full path and its configuration. /// IXProject does not override Equals() and GetHashCode() /// And this can help to compare projects by minimal information for Unload() methods etc. /// </summary> /// <param name="x"></param> /// <param name="prj"></param> /// <returns></returns> public static bool IsLimEqual(this IXProject x, IXProject prj) { if (x == null) { return(x == prj); } return(x.ProjectFullPath == prj.ProjectFullPath && x.ProjectItem.project == prj.ProjectItem.project && (ConfigItem)x.ProjectItem.solutionConfig == (ConfigItem)prj.ProjectItem.solutionConfig && (ConfigItem)x.ProjectItem.projectConfig == (ConfigItem)prj.ProjectItem.projectConfig); }
//TODO: select a specific project + add property to the list internal void LoadProperties(IXProject project) { dgvProperties.UIAction(g => g.Rows.Clear()); if (project == null) { return; } var props = project.GetProperties().ToArray(); // array prevents possible InvalidOperationException dgvProperties.UIAction(g => props.ForEach(p => g.Rows.Add(p.name, p.evaluatedValue))); }
public static void AddPackageIfNotExists(this IXProject xp, string id, string version) { if (xp == null) { throw new ArgumentNullException(nameof(xp)); } if (xp.GetFirstPackageReference(id ?? throw new ArgumentNullException(nameof(id))).parentItem == null) { xp.AddPackageReference(id, version); } }
/// <summary> /// Executes IXProject through MSBuild engine. /// </summary> /// <param name="xp"></param> /// <param name="entrypoint">Initial target.</param> /// <param name="properties">Additional properties that will be available when executing code.</param> /// <returns>True if request was a complete success.</returns> public bool Execute(IXProject xp, string entrypoint, IDictionary <string, string> properties = null) { if (xp == null) { throw new ArgumentNullException(nameof(xp)); } UpdateGlobalProperties(xp, properties); var request = new BuildRequestData ( xp.Project.CreateProjectInstance(), new string[] { entrypoint ?? throw new ArgumentNullException(nameof(entrypoint)) },
/// <summary> /// Get projects that depend on the specified project. /// /// https://github.com/3F/DllExport/pull/148#issuecomment-624831606 /// ProjectC -} ProjectA + ProjectB /// ProjectB -} ProjectA /// ... /// </summary> /// <param name="project"></param> /// <returns></returns> private IEnumerable <IXProject> GetDependents(IXProject project) { foreach (var dep in Sln.ProjectDependencies.Dependencies) { if (dep.Value.Any(g => g.Guid() == project.ProjectGuid.Guid())) { var prj = GetProjectByGuid(Sln.Env.Projects, dep.Key); if (prj != null) { yield return(prj); } } } }
internal static bool RemoveXmlTarget(this IXProject xp, string name) { if (string.IsNullOrWhiteSpace(name)) { return(false); } var target = xp?.Project.Xml.Targets?.FirstOrDefault(t => t.Name == name); if (target != null) { xp.Project.Xml.RemoveChild(target); return(true); } return(false); }
/// <summary> /// Get unique identifier for project (not instance). /// TODO: MvsSln should provide similar PId with v2.0.1+ /// </summary> /// <param name="xp"></param> /// <returns></returns> public static Guid GetPId(this IXProject xp) { if (xp == null) { return(Guid.Empty); } var pItem = xp.ProjectItem; return(( pItem.project.pGuid + pItem.projectConfig + pItem.solutionConfig ) .Guid()); }
internal static void RemoveProperties(this IXProject xp, params string[] names) { if (xp == null) { return; } foreach (string name in names) { if (!string.IsNullOrWhiteSpace(name)) { while (xp.RemoveProperty(name, true)) { } } } xp.RemoveEmptyPropertyGroups(); }
public void ItemsTest1() { var projects = new Dictionary <string, RawText>() { ["{12B25935-229F-4128-B66B-7561A77ABC54}"] = new RawText(PrjSamplesResource.snet) }; using (var sln = new Sln(SlnItems.EnvWithProjects, new RawText(SlnSamplesResource.regXwild), projects)) { IXProject project = sln.Result.Env.Projects.FirstOrDefault(); Assert.AreEqual(null, project.GetItem("Reference", "NOT_REAL_INC").evaluatedInclude); Assert.AreEqual(true, project.AddItem("Reference", "MyInclude")); Assert.AreEqual("MyInclude", project.GetItem("Reference", "MyInclude").evaluatedInclude); Assert.AreEqual(false, project.RemoveItem("Reference", "NOT_REAL_INC")); Assert.AreEqual(true, project.RemoveItem("Reference", "MyInclude")); Assert.AreEqual(null, project.GetItem("Reference", "MyInclude").evaluatedInclude); } }
public void PropertiesTest3() { var projects = new Dictionary <string, RawText>() { ["{12B25935-229F-4128-B66B-7561A77ABC54}"] = new RawText(PrjSamplesResource.snet) }; using (var sln = new Sln(SlnItems.EnvWithProjects, new RawText(SlnSamplesResource.regXwild), projects)) { IXProject project = sln.Result.Env.Projects.FirstOrDefault(); var prop = project.GetProperty("Platform", true); Assert.Null(prop.name); Assert.Null(prop.unevaluatedValue); Assert.Null(prop.evaluatedValue); Assert.Null(prop.parentProperty); Assert.NotNull(prop.parentProject); } }
internal static ProjectPropertyGroupElement GetOrAddPropertyGroup(this IXProject xp, string label, string condition = null) { if (xp == null) { throw new ArgumentNullException(nameof(xp)); } if (string.IsNullOrEmpty(label)) { throw new ArgumentOutOfRangeException(nameof(label)); } var pgroup = xp.Project.Xml.PropertyGroups.FirstOrDefault(p => p.Label == label); if (pgroup != null) { return(pgroup); } return(xp.AddPropertyGroup(label, condition)); }
public void PropertiesTest1() { var projects = new Dictionary <string, RawText>() { ["{12B25935-229F-4128-B66B-7561A77ABC54}"] = new RawText(PrjSamplesResource.snet) }; using (var sln = new Sln(SlnItems.EnvWithProjects, new RawText(SlnSamplesResource.regXwild), projects)) { IXProject project = sln.Result.Env.Projects.FirstOrDefault(); Assert.AreEqual(null, project.GetProperty("NOT_REAL_PROPERTY").name); Assert.AreEqual("MyProperty1", project.SetProperty("MyProperty1", "Value1").name); Assert.AreEqual("Value1", project.GetProperty("MyProperty1").evaluatedValue); Assert.AreEqual(false, project.RemoveProperty("NOT_REAL_PROPERTY_2")); Assert.AreEqual(true, project.RemoveProperty("MyProperty1")); Assert.AreEqual(null, project.GetProperty("MyProperty1").name); } }
private IXProject GetProject(string file) { IXProject ret = Sln.Env.Projects.FirstOrDefault(p => p.ProjectFullPath == file); if (ret != null) { return(ret); } // We're working with external storage through Import section. foreach (var xp in Sln.Env.Projects) { if (xp.Project.Imports?.Any(p => p.ImportedProject?.FullPath == file) == true) { return(xp); } } // or not ... throw new NotSupportedException(string.Format(Resources.File_0_is_not_supported_for_1, file, nameof(PostProc))); }
internal static ProjectPropertyGroupElement AddPropertyGroup(this IXProject xp, string label = null, string condition = null) { if (xp == null) { throw new ArgumentNullException(nameof(xp)); } var pgroup = xp.Project.Xml.AddPropertyGroup(); if (label != null) { pgroup.Label = label; } if (condition != null) { pgroup.Condition = condition; } return(pgroup); }
public void CorrectProjectInstnacesTest(string configuration, string platform, SlnItems opt) { using Sln sln = new(TestData.PathTo(@"XProjectEnv\projectInstnaces\ClassLibrary1.sln"), opt); ISlnResult l = sln.Result; ConfigItem input = new(configuration, platform); ProjectItem prj = l.ProjectItems.FirstOrDefault(); IXProject xp = l.Env.XProjectByFile ( prj.fullPath, input, new Dictionary <string, string>() { { PropertyNames.CONFIG, configuration }, { PropertyNames.PLATFORM, platform } } ); Assert.True(input.Equals(xp.ProjectItem.projectConfig)); Assert.Equal ( input, new(xp.Project.GlobalProperties[PropertyNames.CONFIG], xp.Project.GlobalProperties[PropertyNames.PLATFORM]) ); var p = l.Env.GetOrLoadProject ( l.ProjectItems.FirstOrDefault(), l.ProjectItemsConfigs .FirstOrDefault(p => input.Equals(p.solutionConfig) == true) .projectConfig ); Assert.Equal ( new(p.GlobalProperties[PropertyNames.CONFIG], p.GlobalProperties[PropertyNames.PLATFORM]), input ); }
protected string GetPreProcCmd(PreProcType type, IXProject xp) { if ((type & PreProcType.ILMerge) == PreProcType.ILMerge) { return(GetUnevaluatedValue(MSBuildProperties.DXP_ILMERGE, xp)); } if ((type & PreProcType.Exec) == PreProcType.Exec) { var tExec = xp?.Project.Xml?.Targets .FirstOrDefault(t => t.Name == MSBuildTargets.DXP_PRE_PROC && t.Label == Project.METALIB_PK_TOKEN)? .Tasks .FirstOrDefault(t => t.Name == "Exec"); if (tExec != null) { return(tExec.GetParameter("Command")); } } return(null); }
public void PropertiesTest4() { var projects = new Dictionary <string, RawText>() { ["{12B25935-229F-4128-B66B-7561A77ABC54}"] = new RawText(PrjSamplesResource.snet) }; using (var sln = new Sln(SlnItems.EnvWithProjects, new RawText(SlnSamplesResource.regXwild), projects)) { IXProject project = sln.Result.Env.Projects.FirstOrDefault(); Assert.Throws <InvalidOperationException>(() => { project.SetProperty("Platform", "x64"); }); Assert.Throws <InvalidOperationException>(() => { project.SetProperty("Configuration", "Release"); }); } }
public UserConfig(IWizardConfig cfg, IXProject xp) : this(cfg) { if (xp == null) { return; } Namespace = GetValue(MSBuildProperties.DXP_NAMESPACE, xp); Platform = GetPlatform(xp); UseCecil = GetValue(MSBuildProperties.DXP_DDNS_CECIL, xp).ToBoolean(); var rawTimeout = GetValue(MSBuildProperties.DXP_TIMEOUT, xp); Compiler = new CompilerCfg() { genExpLib = GetValue(MSBuildProperties.DXP_GEN_EXP_LIB, xp).ToBoolean(), ordinalsBase = GetValue(MSBuildProperties.DXP_ORDINALS_BASE, xp).ToInteger(), ourILAsm = GetValue(MSBuildProperties.DXP_OUR_ILASM, xp).ToBoolean(), customILAsm = GetUnevaluatedValue(MSBuildProperties.DXP_CUSTOM_ILASM, xp), rSysObj = GetValue(MSBuildProperties.DXP_SYSOBJ_REBASE, xp).ToBoolean(), intermediateFiles = GetValue(MSBuildProperties.DXP_INTERMEDIATE_FILES, xp).ToBoolean(), timeout = String.IsNullOrWhiteSpace(rawTimeout) ? CompilerCfg.TIMEOUT_EXEC : rawTimeout.ToInteger(), peCheck = (PeCheckType)GetValue(MSBuildProperties.DXP_PE_CHECK, xp).ToInteger(), patches = (PatchesType)GetValue(MSBuildProperties.DXP_PATCHES, xp).ToLongInteger() }; var preType = (PreProcType)GetValue(MSBuildProperties.DXP_PRE_PROC_TYPE, xp).ToLongInteger(); PreProc = new PreProc().Configure(preType, GetPreProcCmd(preType, xp)); var postType = (PostProcType)GetValue(MSBuildProperties.DXP_POST_PROC_TYPE, xp).ToLongInteger(); PostProc = new PostProc().Configure ( postType, GetPostProcEnv(postType, xp), GetPostProcCmd(postType, xp) ); }
/// <summary> /// To get unevaluated property value with global scope by default. /// </summary> /// <param name="xp"></param> /// <param name="name">The name of the property.</param> /// <param name="localScope">If true, will return default value for any special and imported properties type.</param> /// <returns>The unevaluated property value, which is never null.</returns> public static string GetUnevaluatedPropertyValue(this IXProject xp, string name, bool localScope = false) { return(xp?.GetProperty(name, localScope).unevaluatedValue); }
//TODO: select a specific project + add property to the list internal void LoadProperties(IXProject project) { dgvProperties.Rows.Clear(); project?.GetProperties().ForEach(p => dgvProperties.Rows.Add(p.name, p.evaluatedValue)); }
private string GetUnevaluatedValue(string property, IXProject project) { return(project?.GetUnevaluatedPropertyValue(property)); }
private string GetValue(string property, IXProject project) { return(project?.GetPropertyValue(property)); }
internal static void RemoveEmptyPropertyGroups(this IXProject xp) => xp.RemovePropertyGroups(p => p.Properties.Count < 1);