Skip to content

Commit

Permalink
Merge pull request #147 from caioproiete/set-debugger-options
Browse files Browse the repository at this point in the history
Improve debugging experience / Automatically set debugger options
  • Loading branch information
govert authored Oct 17, 2017
2 parents 354a95e + 69d7e17 commit 55207b5
Show file tree
Hide file tree
Showing 16 changed files with 742 additions and 97 deletions.
22 changes: 22 additions & 0 deletions Package/ExcelDna.AddIn/content/ExcelDna.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@
* Open your solution/project again in Visual Studio
-->

<!--
Configuration properties for debugging Excel-DNA add-ins
-->
<PropertyGroup>
<!--
Enable/Disable setting the debug options when building the project
-->
<RunExcelDnaSetDebuggerOptions Condition="'$(RunExcelDnaSetDebuggerOptions)' == ''">true</RunExcelDnaSetDebuggerOptions>

<!--
Override the path of EXCEL.EXE used for debugging the project, if you need
By default, it will use the latest version of Excel it can find on the machine
-->
<ExcelDnaExcelExePath Condition="'$(ExcelDnaExcelExePath)' == ''"></ExcelDnaExcelExePath>

<!--
Override the name of the .XLL add-in to use when debugging the project, if you need
By default, it will use the first unpacked .xll add-in that matches the bitness of EXCEL.EXE
-->
<ExcelDnaAddInForDebugging Condition="'$(ExcelDnaAddInForDebugging)' == ''"></ExcelDnaAddInForDebugging>
</PropertyGroup>

<!--
Configuration properties for building .dna files
-->
Expand Down
33 changes: 30 additions & 3 deletions Package/ExcelDna.AddIn/tools/ExcelDna.AddIn.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="ExcelDna.AddIn.Tasks.CreateExcelAddIn" AssemblyFile="ExcelDna.AddIn.Tasks.dll" />
<UsingTask TaskName="ExcelDna.AddIn.Tasks.SetDebuggerOptions" AssemblyFile="ExcelDna.AddIn.Tasks.dll" />
<UsingTask TaskName="ExcelDna.AddIn.Tasks.CleanExcelAddIn" AssemblyFile="ExcelDna.AddIn.Tasks.dll" />
<UsingTask TaskName="ExcelDna.AddIn.Tasks.CreateExcelAddIn" AssemblyFile="ExcelDna.AddIn.Tasks.dll" />

<PropertyGroup>
<ExcelDnaTargetsImported>true</ExcelDnaTargetsImported>
Expand All @@ -18,10 +19,11 @@
</PropertyGroup>

<!--
Extend the Build target to call our ExcelDnaBuild and ExcelDnaPack targets
Extend the Build target to call our ExcelDnaDebugger, ExcelDnaBuild, and ExcelDnaPack targets
-->
<PropertyGroup>
<BuildDependsOn>
ExcelDnaSetDebuggerOptions;
$(BuildDependsOn);
ExcelDnaBuild;
ExcelDnaPack;
Expand All @@ -41,6 +43,7 @@
Default values for configuration properties - in case they were not set in via .props file or command-line
-->
<PropertyGroup>
<RunExcelDnaSetDebuggerOptions Condition="'$(RunExcelDnaSetDebuggerOptions)' == ''">true</RunExcelDnaSetDebuggerOptions>
<RunExcelDnaClean Condition="'$(RunExcelDnaClean)' == ''">true</RunExcelDnaClean>
<RunExcelDnaBuild Condition="'$(RunExcelDnaBuild)' == ''">true</RunExcelDnaBuild>
<RunExcelDnaPack Condition="'$(RunExcelDnaPack)' == ''">true</RunExcelDnaPack>
Expand All @@ -59,6 +62,31 @@
<ExcelDnaPackRunMultithreaded Condition="'$(ExcelDnaPackRunMultithreaded)' == ''">true</ExcelDnaPackRunMultithreaded>
</PropertyGroup>

<!--
Configure debugger options (Path for EXCEL.EXE, add-in to open, etc).
-->
<Target Name="ExcelDnaSetDebuggerOptions" BeforeTargets="PreBuildEvent" Condition="$(RunExcelDnaSetDebuggerOptions) AND '$(BuildingInsideVisualStudio)' == 'true'">
<Message Text="---" Importance="High" />

<Error Text="ExcelDna32BitAddInSuffix and ExcelDna64BitAddInSuffix cannot be identical. Fix your ExcelDna.Build.props file"
Condition="'$(ExcelDna32BitAddInSuffix)' == '$(ExcelDna64BitAddInSuffix)'" />

<ItemGroup>
<ExcelDnaFilesInProject Include="@(None)" />
<ExcelDnaFilesInProject Include="@(Content)" />
</ItemGroup>

<SetDebuggerOptions
ProjectName="$(MSBuildProjectName)"
ExcelExePath="$(ExcelDnaExcelExePath)"
AddInForDebugging="$(ExcelDnaAddInForDebugging)"
FilesInProject="@(ExcelDnaFilesInProject)"
OutDirectory="$(OutDir)"
FileSuffix32Bit="$(ExcelDna32BitAddInSuffix)"
FileSuffix64Bit="$(ExcelDna64BitAddInSuffix)">
</SetDebuggerOptions>
</Target>

<!--
Target that removes .dna, .xll, and .xll.config from the build output folder
-->
Expand All @@ -83,7 +111,6 @@
PackIsEnabled="$(RunExcelDnaPack)"
PackedFileSuffix="$(ExcelDnaPackXllSuffix)">
</CleanExcelAddIn>

</Target>

<!--
Expand Down
35 changes: 0 additions & 35 deletions Package/ExcelDna.AddIn/tools/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ param($installPath, $toolsPath, $package, $project)
Write-Host "Starting ExcelDna.AddIn install script"

$dteVersion = $project.DTE.Version
$isBeforeVS2015 = ($dteVersion -lt 14.0)
$isFSharpProject = ($project.Type -eq "F#")
$projectName = $project.Name

Expand Down Expand Up @@ -50,40 +49,6 @@ param($installPath, $toolsPath, $package, $project)
}
}

if ($isFSharpProject -and $isBeforeVS2015)
{
# I don't know how to do this for F# projects on old VS
Write-Host "`t*** Unable to configure Debug startup setting.`r`n`t Please configure manually to start Excel when debugging.`r`n`t See readme.txt for details."
}
else
{
# Find Debug configuration and set debugger settings.
$exeValue = Get-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Excel.XLL\shell\Open\command -name "(default)"
if ($exeValue -match "`".*`"")
{
$exePath = $matches[0] -replace "`"", ""
# Write-Host "Excel path found: " $exePath

# Find Debug configuration and set debugger settings.
$debugProject = $project.ConfigurationManager | Where-Object {$_.ConfigurationName -eq "Debug"}
if ($null -ne $debugProject)
{
# Write-Host "Start Action " $debugProject.Properties.Item("StartAction").Value
if ($debugProject.Properties.Item("StartAction").Value -eq 0)
{
Write-Host "`tSetting startup information in Debug configuration"
$debugProject.Properties.Item("StartAction").Value = 1
$debugProject.Properties.Item("StartProgram").Value = $exePath
$debugProject.Properties.Item("StartArguments").Value = "`"${projectName}-AddIn.xll`""
}
}
}
else
{
Write-Host "`tExcel path not found!"
}
}

Write-Host "`tAdding build targets to the project"

# This is the MSBuild targets file to add
Expand Down
31 changes: 0 additions & 31 deletions Package/ExcelDna.AddIn/tools/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ param($installPath, $toolsPath, $package, $project)
Write-Host "Starting ExcelDna.AddIn uninstall script"

$dteVersion = $project.DTE.Version
$isBeforeVS2015 = ($dteVersion -lt 14.0)
$isFSharpProject = ($project.Type -eq "F#")
$projectName = $project.Name

Expand All @@ -28,36 +27,6 @@ param($installPath, $toolsPath, $package, $project)
}
}


if ($isFSharpProject -and $isBeforeVS2015)
{
# No Debug information was set.
}
else
{
# Clean Debug settings
$exeValue = Get-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Excel.XLL\shell\Open\command -name "(default)"
if ($exeValue -match "`".*`"")
{
$exePath = $matches[0] -replace "`"", ""

# Find Debug configuration and set debugger settings.
$debugProject = $project.ConfigurationManager | Where-Object {$_.ConfigurationName -eq "Debug"}
if ($null -ne $debugProject)
{
if (($debugProject.Properties.Item("StartAction").Value -eq 1) -and
($debugProject.Properties.Item("StartArguments").Value -match "\.xll"))
{
Write-Host "`tClearing Debug start settings"
$debugProject.Properties.Item("StartAction").Value = 0
$debugProject.Properties.Item("StartProgram").Value = ""
$debugProject.Properties.Item("StartArguments").Value = ""
}
}
}
}


Write-Host "`Removing build targets from the project"

# Need to load MSBuild assembly if it's not loaded yet
Expand Down
33 changes: 29 additions & 4 deletions Source/ExcelDna.AddIn.Tasks/AbstractTask.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
using Microsoft.Build.Framework;
using System;
using Microsoft.Build.Framework;

namespace ExcelDna.AddIn.Tasks
{
public abstract class AbstractTask : ITask
{
private readonly string _targetName;

protected AbstractTask(string targetName)
{
if (string.IsNullOrWhiteSpace(targetName))
{
throw new ArgumentException("Value cannot be null or whitespace.", nameof(targetName));
}

_targetName = targetName;
}

public abstract bool Execute();

protected void LogDebugMessage(string message)
{
#if DEBUG
LogMessage(message, MessageImportance.High);
#else
LogMessage(message, MessageImportance.Low);
#endif
}

protected void LogMessage(string message, MessageImportance importance = MessageImportance.High)
{
BuildEngine.LogMessageEvent(new BuildMessageEventArgs("ExcelDnaBuild: " + message, "ExcelDnaBuild", "ExcelDnaBuild", importance));
BuildEngine.LogMessageEvent(new BuildMessageEventArgs(string.Format("{0}: {1}", _targetName, message),
_targetName, _targetName, importance));
}

protected void LogWarning(string code, string message)
{
BuildEngine.LogWarningEvent(new BuildWarningEventArgs("ExcelDnaBuild", code, null, 0, 0, 0, 0, message, "ExcelDnaBuild", "ExcelDnaBuild"));
BuildEngine.LogWarningEvent(new BuildWarningEventArgs(_targetName, code, null, 0, 0, 0, 0, message,
_targetName, _targetName));
}

protected void LogError(string code, string message)
{
BuildEngine.LogErrorEvent(new BuildErrorEventArgs("ExcelDnaBuild", code, null, 0, 0, 0, 0, message, "ExcelDnaBuild", "ExcelDnaBuild"));
BuildEngine.LogErrorEvent(new BuildErrorEventArgs(_targetName, code, null, 0, 0, 0, 0, message, _targetName,
_targetName));
}

public IBuildEngine BuildEngine { get; set; }
Expand Down
24 changes: 13 additions & 11 deletions Source/ExcelDna.AddIn.Tasks/CleanExcelAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public CleanExcelAddIn()
}

public CleanExcelAddIn(IExcelDnaFileSystem fileSystem)
: base("ExcelDnaClean")
{
if (fileSystem == null)
{
Expand All @@ -34,18 +35,18 @@ public override bool Execute()
{
try
{
LogDebugMessage("Running CleanExcelAddIn MSBuild Task");

LogDiagnostics();

FilesInProject = FilesInProject ?? new ITaskItem[0];
LogMessage("Number of files in project: " + FilesInProject.Length, MessageImportance.Low);
LogDebugMessage("Number of files in project: " + FilesInProject.Length);

_common = new BuildTaskCommon(FilesInProject, OutDirectory, FileSuffix32Bit, FileSuffix64Bit);

var existingBuiltFiles = _common.GetBuildItemsForDnaFiles();
_packedFilesToDelete = GetPackedFilesToDelete(existingBuiltFiles);

LogMessage("---");

// Get the packed name versions : Refactor this + build items
DeleteAddInFiles(existingBuiltFiles);
DeletePackedAddInFiles(_packedFilesToDelete);
Expand All @@ -62,14 +63,14 @@ public override bool Execute()

private void LogDiagnostics()
{
LogMessage("----Arguments----", MessageImportance.Low);
LogMessage("FilesInProject: " + (FilesInProject ?? new ITaskItem[0]).Length, MessageImportance.Low);
LogMessage("OutDirectory: " + OutDirectory, MessageImportance.Low);
LogMessage("Xll32FilePath: " + Xll32FilePath, MessageImportance.Low);
LogMessage("Xll64FilePath: " + Xll64FilePath, MessageImportance.Low);
LogMessage("FileSuffix32Bit: " + FileSuffix32Bit, MessageImportance.Low);
LogMessage("FileSuffix64Bit: " + FileSuffix64Bit, MessageImportance.Low);
LogMessage("-----------------", MessageImportance.Low);
LogDebugMessage("----Arguments----");
LogDebugMessage("FilesInProject: " + (FilesInProject ?? new ITaskItem[0]).Length);
LogDebugMessage("OutDirectory: " + OutDirectory);
LogDebugMessage("Xll32FilePath: " + Xll32FilePath);
LogDebugMessage("Xll64FilePath: " + Xll64FilePath);
LogDebugMessage("FileSuffix32Bit: " + FileSuffix32Bit);
LogDebugMessage("FileSuffix64Bit: " + FileSuffix64Bit);
LogDebugMessage("-----------------");
}

private List<ITaskItem> GetPackedFilesToDelete(BuildItemSpec[] existingBuiltFiles)
Expand Down Expand Up @@ -141,6 +142,7 @@ private void DeleteFileIfExists(string path)
{
if (_fileSystem.FileExists(path))
{
LogDebugMessage("Deleting file " + path);
_fileSystem.DeleteFile(path);
}
}
Expand Down
27 changes: 15 additions & 12 deletions Source/ExcelDna.AddIn.Tasks/CreateExcelAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public CreateExcelAddIn()
}

public CreateExcelAddIn(IExcelDnaFileSystem fileSystem)
: base("ExcelDnaBuild")
{
if (fileSystem == null)
{
Expand All @@ -35,6 +36,8 @@ public override bool Execute()
{
try
{
LogDebugMessage("Running CreateExcelAddIn MSBuild Task");

LogDiagnostics();

RunSanityChecks();
Expand All @@ -43,7 +46,7 @@ public override bool Execute()
DnaFilesToPack = new ITaskItem[0];

FilesInProject = FilesInProject ?? new ITaskItem[0];
LogMessage("Number of files in project: " + FilesInProject.Length, MessageImportance.Low);
LogDebugMessage("Number of files in project: " + FilesInProject.Length);

_configFilesInProject = GetConfigFilesInProject();
_common = new BuildTaskCommon(FilesInProject, OutDirectory, FileSuffix32Bit, FileSuffix64Bit);
Expand All @@ -52,7 +55,7 @@ public override bool Execute()

TryBuildAddInFor32Bit(buildItemsForDnaFiles);

LogMessage("---");
LogMessage("---", MessageImportance.High);

TryBuildAddInFor64Bit(buildItemsForDnaFiles);

Expand All @@ -70,16 +73,16 @@ public override bool Execute()

private void LogDiagnostics()
{
LogMessage("----Arguments----", MessageImportance.Low);
LogMessage("FilesInProject: " + (FilesInProject ?? new ITaskItem[0]).Length, MessageImportance.Low);
LogMessage("OutDirectory: " + OutDirectory, MessageImportance.Low);
LogMessage("Xll32FilePath: " + Xll32FilePath, MessageImportance.Low);
LogMessage("Xll64FilePath: " + Xll64FilePath, MessageImportance.Low);
LogMessage("Create32BitAddIn: " + Create32BitAddIn, MessageImportance.Low);
LogMessage("Create64BitAddIn: " + Create64BitAddIn, MessageImportance.Low);
LogMessage("FileSuffix32Bit: " + FileSuffix32Bit, MessageImportance.Low);
LogMessage("FileSuffix64Bit: " + FileSuffix64Bit, MessageImportance.Low);
LogMessage("-----------------", MessageImportance.Low);
LogDebugMessage("----Arguments----");
LogDebugMessage("FilesInProject: " + (FilesInProject ?? new ITaskItem[0]).Length);
LogDebugMessage("OutDirectory: " + OutDirectory);
LogDebugMessage("Xll32FilePath: " + Xll32FilePath);
LogDebugMessage("Xll64FilePath: " + Xll64FilePath);
LogDebugMessage("Create32BitAddIn: " + Create32BitAddIn);
LogDebugMessage("Create64BitAddIn: " + Create64BitAddIn);
LogDebugMessage("FileSuffix32Bit: " + FileSuffix32Bit);
LogDebugMessage("FileSuffix64Bit: " + FileSuffix64Bit);
LogDebugMessage("-----------------");
}

private void RunSanityChecks()
Expand Down
Loading

0 comments on commit 55207b5

Please sign in to comment.