Skip to content

Commit

Permalink
Merge pull request #130 from caioproiete/fix-msbuild-clean-task
Browse files Browse the repository at this point in the history
Fix MSBuild Clean Task issues
  • Loading branch information
govert authored May 14, 2017
2 parents 80c3e9b + 86d1e4f commit 87fe3b5
Show file tree
Hide file tree
Showing 33 changed files with 114 additions and 202 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Ignore temporary files created to run ExcelDna integration tests
Source/Tests/.exceldna.addin/
Source/Tests/ExcelDna.AddIn.Tasks.IntegrationTests.TestTarget/out/

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
.vs/
*.suo
*.user
*.sln.docstates
Expand Down
1 change: 1 addition & 0 deletions Package/ExcelDna.AddIn/content/ExcelDna.Build.props
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="ExcelDnaProps">
<!--
If you change properties in this file, they may not come into effect until you:
Expand Down
2 changes: 1 addition & 1 deletion Package/ExcelDna.AddIn/tools/ExcelDna.AddIn.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="Windows-1252"?>
<?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.CleanExcelAddIn" AssemblyFile="ExcelDna.AddIn.Tasks.dll" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ namespace ExcelDna.AddIn.Tasks
{
public class BuildTaskCommon
{
private string OutDirectory;
private string FileSuffix32Bit;
private string FileSuffix64Bit;
private ITaskItem[] FilesInProject;
private readonly string _outDirectory;
private readonly string _fileSuffix32Bit;
private readonly string _fileSuffix64Bit;
private readonly ITaskItem[] _filesInProject;

public BuildTaskCommon(ITaskItem[] FilesInProject, string OutDirectory, string FileSuffix32Bit, string FileSuffix64Bit)
public BuildTaskCommon(ITaskItem[] filesInProject, string outDirectory, string fileSuffix32Bit, string fileSuffix64Bit)
{
this.FilesInProject = FilesInProject;
this.OutDirectory = OutDirectory;
this.FileSuffix32Bit = FileSuffix32Bit;
this.FileSuffix64Bit = FileSuffix64Bit;
if (filesInProject == null)
{
throw new ArgumentNullException("filesInProject");
}

_filesInProject = filesInProject;
_outDirectory = outDirectory;
_fileSuffix32Bit = fileSuffix32Bit;
_fileSuffix64Bit = fileSuffix64Bit;
}

internal BuildItemSpec[] GetBuildItemsForDnaFiles()
{
var buildItemsForDnaFiles = (
from item in FilesInProject
from item in _filesInProject
where string.Equals(Path.GetExtension(item.ItemSpec), ".dna", StringComparison.OrdinalIgnoreCase)
orderby item.ItemSpec
let inputDnaFileNameAs32Bit = GetDnaFileNameAs32Bit(item.ItemSpec)
Expand All @@ -41,55 +46,55 @@ orderby item.ItemSpec
InputConfigFileNameAs64Bit = Path.ChangeExtension(inputDnaFileNameAs64Bit, ".config"),
InputConfigFileNameFallbackAs64Bit = GetAppConfigFileNameAs64Bit(),

OutputDnaFileNameAs32Bit = Path.Combine(OutDirectory, inputDnaFileNameAs32Bit),
OutputDnaFileNameAs64Bit = Path.Combine(OutDirectory, inputDnaFileNameAs64Bit),
OutputDnaFileNameAs32Bit = Path.Combine(_outDirectory, inputDnaFileNameAs32Bit),
OutputDnaFileNameAs64Bit = Path.Combine(_outDirectory, inputDnaFileNameAs64Bit),

OutputXllFileNameAs32Bit = Path.Combine(OutDirectory, Path.ChangeExtension(inputDnaFileNameAs32Bit, ".xll")),
OutputXllFileNameAs64Bit = Path.Combine(OutDirectory, Path.ChangeExtension(inputDnaFileNameAs64Bit, ".xll")),
OutputXllFileNameAs32Bit = Path.Combine(_outDirectory, Path.ChangeExtension(inputDnaFileNameAs32Bit, ".xll")),
OutputXllFileNameAs64Bit = Path.Combine(_outDirectory, Path.ChangeExtension(inputDnaFileNameAs64Bit, ".xll")),

OutputConfigFileNameAs32Bit = Path.Combine(OutDirectory, Path.ChangeExtension(inputDnaFileNameAs32Bit, ".xll.config")),
OutputConfigFileNameAs64Bit = Path.Combine(OutDirectory, Path.ChangeExtension(inputDnaFileNameAs64Bit, ".xll.config")),
OutputConfigFileNameAs32Bit = Path.Combine(_outDirectory, Path.ChangeExtension(inputDnaFileNameAs32Bit, ".xll.config")),
OutputConfigFileNameAs64Bit = Path.Combine(_outDirectory, Path.ChangeExtension(inputDnaFileNameAs64Bit, ".xll.config")),
}).ToArray();

return buildItemsForDnaFiles;
}

private string GetDnaFileNameAs32Bit(string fileName)
{
return GetFileNameWithBitnessSuffix(fileName, FileSuffix32Bit);
return GetFileNameWithBitnessSuffix(fileName, _fileSuffix32Bit);
}

private string GetDnaFileNameAs64Bit(string fileName)
{
return GetFileNameWithBitnessSuffix(fileName, FileSuffix64Bit);
return GetFileNameWithBitnessSuffix(fileName, _fileSuffix64Bit);
}

private string GetAppConfigFileNameAs32Bit()
{
return GetFileNameWithBitnessSuffix("App.config", FileSuffix32Bit);
return GetFileNameWithBitnessSuffix("App.config", _fileSuffix32Bit);
}

private string GetAppConfigFileNameAs64Bit()
{
return GetFileNameWithBitnessSuffix("App.config", FileSuffix64Bit);
return GetFileNameWithBitnessSuffix("App.config", _fileSuffix64Bit);
}

private string GetFileNameWithBitnessSuffix(string fileName, string suffix)
{
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName) ?? string.Empty;

if (!string.IsNullOrWhiteSpace(FileSuffix32Bit))
if (!string.IsNullOrWhiteSpace(_fileSuffix32Bit))
{
var indexOfSuffix = fileNameWithoutExtension.LastIndexOf(FileSuffix32Bit, StringComparison.OrdinalIgnoreCase);
var indexOfSuffix = fileNameWithoutExtension.LastIndexOf(_fileSuffix32Bit, StringComparison.OrdinalIgnoreCase);
if (indexOfSuffix > 0)
{
fileNameWithoutExtension = fileNameWithoutExtension.Remove(indexOfSuffix);
}
}

if (!string.IsNullOrWhiteSpace(FileSuffix64Bit))
if (!string.IsNullOrWhiteSpace(_fileSuffix64Bit))
{
var indexOfSuffix = fileNameWithoutExtension.LastIndexOf(FileSuffix64Bit, StringComparison.OrdinalIgnoreCase);
var indexOfSuffix = fileNameWithoutExtension.LastIndexOf(_fileSuffix64Bit, StringComparison.OrdinalIgnoreCase);
if (indexOfSuffix > 0)
{
fileNameWithoutExtension = fileNameWithoutExtension.Remove(indexOfSuffix);
Expand Down
45 changes: 26 additions & 19 deletions Source/ExcelDna.AddIn.Tasks/CleanExcelAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ namespace ExcelDna.AddIn.Tasks
public class CleanExcelAddIn : AbstractTask
{
private readonly IExcelDnaFileSystem _fileSystem;
private ITaskItem[] _configFilesInProject;
private List<ITaskItem> _packedFilesToDelete;
private BuildTaskCommon common;
private BuildTaskCommon _common;

public CleanExcelAddIn()
: this(new ExcelDnaPhysicalFileSystem())
Expand All @@ -40,14 +39,14 @@ public override bool Execute()
FilesInProject = FilesInProject ?? new ITaskItem[0];
LogMessage("Number of files in project: " + FilesInProject.Length, MessageImportance.Low);

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

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

LogMessage("---");

//Get the packed name versions : Refactor this + build items
// Get the packed name versions : Refactor this + build items
DeleteAddInFiles(existingBuiltFiles);
DeletePackedAddInFiles(_packedFilesToDelete);

Expand All @@ -73,17 +72,17 @@ private void LogDiagnostics()
LogMessage("-----------------", MessageImportance.Low);
}

private List<ITaskItem> GetPackedFilesToDelete(BuildItemSpec[] existingBuiltFiles)
private List<ITaskItem> GetPackedFilesToDelete(BuildItemSpec[] existingBuiltFiles)
{
var _packedFilesToDelete = new List<ITaskItem>();
var packedFilesToDelete = new List<ITaskItem>();

foreach (var item in existingBuiltFiles)
{
_packedFilesToDelete.Add(GetPackedFileNames(item.OutputDnaFileNameAs32Bit, item.OutputXllFileNameAs32Bit, item.OutputConfigFileNameAs32Bit));
_packedFilesToDelete.Add(GetPackedFileNames(item.OutputDnaFileNameAs64Bit, item.OutputXllFileNameAs64Bit, item.OutputConfigFileNameAs64Bit));
packedFilesToDelete.Add(GetPackedFileNames(item.OutputDnaFileNameAs32Bit, item.OutputXllFileNameAs32Bit, item.OutputConfigFileNameAs32Bit));
packedFilesToDelete.Add(GetPackedFileNames(item.OutputDnaFileNameAs64Bit, item.OutputXllFileNameAs64Bit, item.OutputConfigFileNameAs64Bit));
}

return _packedFilesToDelete;
return packedFilesToDelete;
}

private TaskItem GetPackedFileNames(string outputDnaFileName, string outputXllFileName, string outputXllConfigFileName)
Expand Down Expand Up @@ -117,27 +116,35 @@ private void DeleteAddInFiles(BuildItemSpec[] buildItemsForDnaFiles)
{
foreach (var item in buildItemsForDnaFiles)
{
_fileSystem.DeleteFile(item.OutputDnaFileNameAs32Bit);
_fileSystem.DeleteFile(item.OutputDnaFileNameAs64Bit);
DeleteFileIfExists(item.OutputDnaFileNameAs32Bit);
DeleteFileIfExists(item.OutputDnaFileNameAs64Bit);

_fileSystem.DeleteFile(item.OutputXllFileNameAs32Bit);
_fileSystem.DeleteFile(item.OutputXllFileNameAs64Bit);
DeleteFileIfExists(item.OutputXllFileNameAs32Bit);
DeleteFileIfExists(item.OutputXllFileNameAs64Bit);

_fileSystem.DeleteFile(item.OutputConfigFileNameAs32Bit);
_fileSystem.DeleteFile(item.OutputConfigFileNameAs64Bit);
DeleteFileIfExists(item.OutputConfigFileNameAs32Bit);
DeleteFileIfExists(item.OutputConfigFileNameAs64Bit);
}
}

private void DeletePackedAddInFiles(List<ITaskItem> filesToDelete)
{
filesToDelete.ToList().ForEach(f =>
{
_fileSystem.DeleteFile(f.GetMetadata("OutputPackedDnaFileName"));
_fileSystem.DeleteFile(f.GetMetadata("OutputPackedXllFileName"));
_fileSystem.DeleteFile(f.GetMetadata("OutputPackedXllConfigFileName"));
DeleteFileIfExists(f.GetMetadata("OutputPackedDnaFileName"));
DeleteFileIfExists(f.GetMetadata("OutputPackedXllFileName"));
DeleteFileIfExists(f.GetMetadata("OutputPackedXllConfigFileName"));
});
}

private void DeleteFileIfExists(string path)
{
if (_fileSystem.FileExists(path))
{
_fileSystem.DeleteFile(path);
}
}

/// <summary>
/// The list of files in the project marked as Content or None
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions Source/ExcelDna.AddIn.Tasks/CreateExcelAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CreateExcelAddIn : AbstractTask
private readonly IExcelDnaFileSystem _fileSystem;
private ITaskItem[] _configFilesInProject;
private List<ITaskItem> _dnaFilesToPack;
private BuildTaskCommon common;
private BuildTaskCommon _common;

public CreateExcelAddIn()
: this(new ExcelDnaPhysicalFileSystem())
Expand Down Expand Up @@ -46,9 +46,9 @@ public override bool Execute()
LogMessage("Number of files in project: " + FilesInProject.Length, MessageImportance.Low);

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

var buildItemsForDnaFiles = common.GetBuildItemsForDnaFiles();
var buildItemsForDnaFiles = _common.GetBuildItemsForDnaFiles();

TryBuildAddInFor32Bit(buildItemsForDnaFiles);

Expand Down
2 changes: 1 addition & 1 deletion Source/ExcelDna.AddIn.Tasks/ExcelDna.AddIn.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<Compile Include="BuildItemSpec.cs" />
<None Include="Properties\ExcelDna.AddIn.Tasks.targets" />
<Compile Include="CleanExcelAddIn.cs" />
<Compile Include="Common.cs" />
<Compile Include="BuildTaskCommon.cs" />
<Compile Include="CreateExcelAddIn.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\ExcelDnaPhysicalFileSystem.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleDnaFileDefaultSuffix", "SingleDnaFileDefaultSuffix\SingleDnaFileDefaultSuffix.csproj", "{69CFC6E4-EAF6-416A-B462-B586DC3E051D}"
EndProject
Expand All @@ -19,9 +19,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleDnaFileNoConfigDefaul
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreAndPostBuildEvents", "PreAndPostBuildEvents\PreAndPostBuildEvents.csproj", "{01805002-4F09-432A-B1E2-803C273671CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultipleAddInProjectTwo", "MultipleAddInProjectTwo\MultipleAddInProjectTwo.csproj", "{C174238C-B87F-41D3-BCAA-325AB66F0A7F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedOutDirProjectOne", "SharedOutDirProjectOne\SharedOutDirProjectOne.csproj", "{4CE13234-A53E-4539-9AFF-D03F7DF2721C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreAndPostBuildEvents", "PreAndPostBuildEvents\PreAndPostBuildEvents.csproj", "{01805002-4F09-432A-B1E2-803C273671CB}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedOutDirProjectTwo", "SharedOutDirProjectTwo\SharedOutDirProjectTwo.csproj", "{C174238C-B87F-41D3-BCAA-325AB66F0A7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -61,15 +61,14 @@ Global
{01805002-4F09-432A-B1E2-803C273671CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01805002-4F09-432A-B1E2-803C273671CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01805002-4F09-432A-B1E2-803C273671CB}.Release|Any CPU.Build.0 = Release|Any CPU
{C174238C-B87F-41D3-BCAA-325AB66F0A7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C174238C-B87F-41D3-BCAA-325AB66F0A7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C174238C-B87F-41D3-BCAA-325AB66F0A7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C174238C-B87F-41D3-BCAA-325AB66F0A7F}.Release|Any CPU.Build.0 = Release|Any CPU
{4CE13234-A53E-4539-9AFF-D03F7DF2721C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CE13234-A53E-4539-9AFF-D03F7DF2721C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CE13234-A53E-4539-9AFF-D03F7DF2721C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CE13234-A53E-4539-9AFF-D03F7DF2721C}.Release|Any CPU.Build.0 = Release|Any CPU

{C174238C-B87F-41D3-BCAA-325AB66F0A7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C174238C-B87F-41D3-BCAA-325AB66F0A7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C174238C-B87F-41D3-BCAA-325AB66F0A7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C174238C-B87F-41D3-BCAA-325AB66F0A7F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(ProjectDir)..\..\.exceldna.addin\tools\ExcelDna.AddIn.targets" />
<PropertyGroup>
<PreBuildEvent>ECHO Running ExcelDna **Pre-build** event</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>ECHO Running ExcelDna **Post-build** event</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(ProjectDir)..\..\.exceldna.addin\tools\ExcelDna.AddIn.targets" />
<PropertyGroup>
<PreBuildEvent>ECHO Running ExcelDna **Pre-build** event</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>ECHO Running ExcelDna **Post-build** event</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<DnaLibrary Name="MultipleAddInProjectOne 64-bit Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="MultipleAddInProjectOne.dll" LoadFromBytes="true" Pack="true" />
<DnaLibrary Name="SharedOutDirProjectOne 64-bit Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="SharedOutDirProjectOne.dll" LoadFromBytes="true" Pack="true" />

<!--
The RuntimeVersion attribute above allows two settings:
Expand Down
Loading

0 comments on commit 87fe3b5

Please sign in to comment.