From f6234745d111d1d6af8f5fa851a35e852f8e4e9a Mon Sep 17 00:00:00 2001 From: "Denis Kuzmin [ github.com/3F ]" Date: Mon, 25 Dec 2017 21:01:43 +0300 Subject: [PATCH] Fixes automatic restoring the package via msbuild. Issue #62 --- Wizard/Project.cs | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/Wizard/Project.cs b/Wizard/Project.cs index d33048e..cc389a8 100644 --- a/Wizard/Project.cs +++ b/Wizard/Project.cs @@ -51,6 +51,12 @@ public class Project: IProject /// protected const string DXP_TARGET_PKG_R = "DllExportRestorePkg"; + /// + /// To support dynamic `import` section. + /// https://github.com/3F/DllExport/issues/62 + /// + protected const string DXP_TARGET_R_DYN = "DllExportRPkgDynamicImport"; + /// /// Access to found project. /// @@ -471,13 +477,16 @@ protected void AddDllExportLib() $"'$(DllExportModImported)' != 'true' Or !Exists('{dxpTarget}')", CfgBatWrapper.DXP_INSTALLER ); + + AddDynRestore( + DXP_TARGET_R_DYN, + $"'$(DllExportModImported)' != 'true' And '$(DllExportRPkgDyn)' != 'false'" + ); } protected void AddRestoreDxp(string name, string condition, string installer) { - Log.send(this, $"Add '{name}' target", Message.Level.Info); - - var target = XProject.Project.Xml.AddTarget(name); + var target = AddTarget(name); target.BeforeTargets = "PrepareForBuild"; var ifInstaller = $"Exists('$(SolutionDir){installer}')"; @@ -491,6 +500,29 @@ protected void AddRestoreDxp(string name, string condition, string installer) taskExec.SetParameter("Command", $"cd \"$(SolutionDir)\" & {installer} -action Restore"); } + // https://github.com/3F/DllExport/issues/62#issuecomment-353785676 + protected void AddDynRestore(string name, string condition) + { + var target = AddTarget(name); + target.BeforeTargets = "PostBuildEvent"; + target.DependsOnTargets = "GetFrameworkPaths"; + target.Condition = condition; + + var taskMsb = target.AddTask("MSBuild"); + + taskMsb.SetParameter("BuildInParallel", "true"); + taskMsb.SetParameter("UseResultsCache", "true"); + taskMsb.SetParameter("Projects", "$(MSBuildProjectFullPath)"); + taskMsb.SetParameter("Properties", "DllExportRPkgDyn=true"); + taskMsb.SetParameter("Targets", "Build"); + } + + protected Microsoft.Build.Construction.ProjectTargetElement AddTarget(string name) + { + Log.send(this, $"Add '{name}' target", Message.Level.Info); + return XProject.Project.Xml.AddTarget(name); + } + protected void RemoveDllExportLib() { foreach(var refer in XProject.GetReferences().ToArray()) @@ -514,6 +546,9 @@ protected void RemoveDllExportLib() Log.send(this, $"Trying to remove old restore-target: '{DXP_TARGET_PKG_R}'", Message.Level.Info); while(RemoveXmlTarget(DXP_TARGET_PKG_R)) { } + Log.send(this, $"Trying to remove dynamic `import` section: '{DXP_TARGET_R_DYN}'", Message.Level.Info); + while(RemoveXmlTarget(DXP_TARGET_R_DYN)) { } + Log.send(this, $"Trying to remove X_EXT_STORAGE Import elements: '{Guids.X_EXT_STORAGE}'", Message.Level.Info); while(XProject.RemoveImport(XProject.GetImport(null, Guids.X_EXT_STORAGE))) { }