Skip to content

Commit

Permalink
Updated logic of restoring package when DllExport.bat does not exist …
Browse files Browse the repository at this point in the history
…at all - #38
  • Loading branch information
3F committed Aug 3, 2017
1 parent 7312630 commit bec432d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Wizard/CfgBatWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace net.r_eg.DllExport.Wizard
//TODO:
internal sealed class CfgBatWrapper
{
private const string DXP_INSTALLER = "DllExport.bat";
internal const string DXP_INSTALLER = "DllExport.bat";

private IWizardConfig config;
private ISender log;
Expand Down
54 changes: 50 additions & 4 deletions Wizard/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class Project: IProject
/// </summary>
public const string DXP_TARGET = "net.r_eg.DllExport.targets";

/// <summary>
/// The name of target to restore package.
/// </summary>
protected const string DXP_TARGET_PKG_R = "DllExportRestorePkg";

/// <summary>
/// Access to found project.
/// </summary>
Expand Down Expand Up @@ -311,36 +316,77 @@ protected void AddDllExportLib()
var lib = MetaLib;
Log.send(this, $"Add meta library: '{lib}'", Message.Level.Info);
XProject.AddReference(lib, false);

AddRestoreDxp(
DXP_TARGET_PKG_R,
$"'$(DllExportModImported)' != 'true' Or !Exists('{dxpTarget}')",
CfgBatWrapper.DXP_INSTALLER
);
}

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);
target.BeforeTargets = "PrepareForBuild";

var ifInstaller = $"Exists('$(SolutionDir){installer}')";

var taskMsg = target.AddTask("Warning");
taskMsg.Condition = $"!{ifInstaller}";
taskMsg.SetParameter("Text", "We can't find 'DllExport.bat' in '$(SolutionDir)' - https://github.com/3F/DllExport");

var taskExec = target.AddTask("Exec");
taskExec.Condition = $"({condition}) And {ifInstaller}";
taskExec.SetParameter("Command", $"cd \"$(SolutionDir)\" & {installer} -action Restore");
}

protected void RemoveDllExportLib()
{
foreach(var refer in XProject.GetReferences().ToArray())
{
if(CmpPublicKeyTokens(METALIB_PK_TOKEN, refer.Assembly.PublicKeyToken)) {
Log.send(this, $"Remove old reference pk:'{METALIB_PK_TOKEN}'", Message.Level.Debug);
Log.send(this, $"Remove old reference pk:'{METALIB_PK_TOKEN}'", Message.Level.Info);
XProject.RemoveItem(refer); // immediately modifies collection from XProject.GetReferences
}
}

Log.send(this, $"Remove old Import elements:'{DXP_TARGET}'", Message.Level.Debug);
Log.send(this, $"Remove old Import elements:'{DXP_TARGET}'", Message.Level.Info);
while(XProject.RemoveImport(XProject.GetImport(DXP_TARGET, null))) { }

Log.send(this, $"Try to remove old Import elements via pk:'{METALIB_PK_TOKEN}'", Message.Level.Debug);
Log.send(this, $"Trying to remove old Import elements via pk:'{METALIB_PK_TOKEN}'", Message.Level.Info);
while(XProject.RemoveImport(XProject.GetImport(null, METALIB_PK_TOKEN))) { }

Log.send(this, $"Trying to remove old restore-target: '{DXP_TARGET_PKG_R}'", Message.Level.Info);
while(RemoveXmlTarget(DXP_TARGET_PKG_R)) { }

if(String.IsNullOrWhiteSpace(Config.Wizard.DxpTarget)) {
return;
}

var dxpTarget = Path.GetFileName(Config.Wizard.DxpTarget);
if(DXP_TARGET.Equals(dxpTarget, StringComparison.InvariantCultureIgnoreCase))
{
Log.send(this, $"Find and remove '{dxpTarget}' as an old .target file of the DllExport.", Message.Level.Debug);
Log.send(this, $"Find and remove '{dxpTarget}' as an old .target file of the DllExport.", Message.Level.Info);
while(XProject.RemoveImport(XProject.GetImport(dxpTarget, null))) { }
}
}

protected bool RemoveXmlTarget(string name)
{
if(String.IsNullOrWhiteSpace(name)) {
return false;
}

var target = XProject.Project.Xml.Targets.Where(t => t.Name == name).FirstOrDefault();
if(target != null) {
XProject.Project.Xml.RemoveChild(target);
return true;
}
return false;
}

protected void RemoveProperties(params string[] names)
{
foreach(string name in names)
Expand Down
13 changes: 9 additions & 4 deletions Wizard/Wizard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,22 @@
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="Microsoft.Build">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Framework">
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Build.Utilities.v4.0">
<Private>True</Private>
</Reference>
<Reference Include="MvsSln, Version=1.0.1.43422, Culture=neutral, PublicKeyToken=87f0bd8fb7f0a2c4, processorArchitecture=MSIL">
<HintPath>..\packages\MvsSln.1.0.1\lib\net40\MvsSln.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActionType.cs" />
Expand Down
22 changes: 6 additions & 16 deletions tools/net.r_eg.DllExport.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<NuPkgRootPath>$(MSBuildThisFileDirectory)..\</NuPkgRootPath>
<WizardDxpTarget>$(NuPkgRootPath)tools\net.r_eg.DllExport.Wizard.targets</WizardDxpTarget>
</PropertyGroup>

<PropertyGroup Label="Wizardcfg">
<wAction>Restore</wAction>
<wSlnFile Condition="'$(wSlnFile)' == ''">$(SolutionPath)</wSlnFile>
<wRootPath Condition="'$(wRootPath)' == ''">$(SolutionDir)</wRootPath>
<wPkgPath Condition="'$(wPkgPath)' == ''">$(NuPkgRootPath)</wPkgPath>
<DllExportModImported>true</DllExportModImported>
</PropertyGroup>

<Import Project="$(WizardDxpTarget)" Condition="'$(DllExportWizardImported)' != 'true' And Exists('$(WizardDxpTarget)')" />
<Target Name="DllExportLib" BeforeTargets="PrepareForBuild">
<CallTarget Targets="DllExportWizard" Condition="'$(DllExportWizardExecuted)' != 'true'" />
</Target>

<PropertyGroup>
<DllExportRootPkg Condition="'$(DllExportRootPkg)' == ''">$(NuPkgRootPath)</DllExportRootPkg>
<DllExportRootPkg Condition="'$(DllExportRootPkg)' == ''">$(MSBuildThisFileDirectory)..\</DllExportRootPkg>
<DllExportVSRoot Condition="'$(DllExportVSRoot)' == ''">$(VsInstallRoot)\</DllExportVSRoot>
<DllExportVSRoot Condition="'$(DllExportVSRoot)' == ''">$(DevEnvDir)\..\..\</DllExportVSRoot>
<DllExportVSBin Condition="'$(DllExportVSBin)' == ''">$(DllExportVSRoot)Common7\IDE\</DllExportVSBin>
Expand Down Expand Up @@ -85,7 +72,10 @@
OurILAsmPath="$(DllExportOurILAsmPath)"
MetaLib="$(DllExportMetaLibFullPath)"
/>


<PropertyGroup>
<DllExportModExecuted>true</DllExportModExecuted>
</PropertyGroup>
</Target>
<UsingTask TaskName="RGiesecke.DllExport.MSBuild.DllExportAppDomainIsolatedTask" AssemblyFile="RGiesecke.DllExport.MSBuild.dll" />

Expand Down

0 comments on commit bec432d

Please sign in to comment.