Skip to content

Commit

Permalink
Fixes automatic restoring the package via msbuild. Issue #62
Browse files Browse the repository at this point in the history
  • Loading branch information
3F committed Dec 25, 2017
1 parent 2409921 commit f623474
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions Wizard/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class Project: IProject
/// </summary>
protected const string DXP_TARGET_PKG_R = "DllExportRestorePkg";

/// <summary>
/// To support dynamic `import` section.
/// https://github.com/3F/DllExport/issues/62
/// </summary>
protected const string DXP_TARGET_R_DYN = "DllExportRPkgDynamicImport";

/// <summary>
/// Access to found project.
/// </summary>
Expand Down Expand Up @@ -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}')";
Expand All @@ -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())
Expand All @@ -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))) { }

Expand Down

0 comments on commit f623474

Please sign in to comment.