Skip to content

Commit

Permalink
Add Microsoft.Data.Entity.Build.Tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Jun 4, 2019
1 parent de1ee27 commit 20f9c74
Show file tree
Hide file tree
Showing 15 changed files with 1,467 additions and 0 deletions.
6 changes: 6 additions & 0 deletions EntityFramework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTests.Transitiona
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTests.ProviderAgnostic", "test\EntityFramework\FunctionalTests.ProviderAgnostic\FunctionalTests.ProviderAgnostic.csproj", "{C0B5124C-0133-4E0B-BF36-A32CE5AD9DAA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Entity.Build.Tasks", "src\Microsoft.Data.Entity.Build.Tasks\Microsoft.Data.Entity.Build.Tasks.csproj", "{B8DB9CC0-822A-423C-A5BE-28C19F94899B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -91,6 +93,10 @@ Global
{C0B5124C-0133-4E0B-BF36-A32CE5AD9DAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0B5124C-0133-4E0B-BF36-A32CE5AD9DAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0B5124C-0133-4E0B-BF36-A32CE5AD9DAA}.Release|Any CPU.Build.0 = Release|Any CPU
{B8DB9CC0-822A-423C-A5BE-28C19F94899B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8DB9CC0-822A-423C-A5BE-28C19F94899B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8DB9CC0-822A-423C-A5BE-28C19F94899B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8DB9CC0-822A-423C-A5BE-28C19F94899B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</PropertyGroup>
<PropertyGroup Label="Dependencies from nuget.org">
<EnvDTEVersion>8.0.2</EnvDTEVersion>
<MicrosoftBuildFrameworkVersion>16.0.461</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildUtilitiesCoreVersion>16.0.461</MicrosoftBuildUtilitiesCoreVersion>
<MicrosoftPowerShell2ReferenceAssembliesVersion>1.0.0</MicrosoftPowerShell2ReferenceAssembliesVersion>
<MicrosoftSqlServerCompactVersion>4.0.8876.1</MicrosoftSqlServerCompactVersion>
<MicrosoftSqlServerTypesVersion>14.0.1016.290</MicrosoftSqlServerTypesVersion>
Expand Down
117 changes: 117 additions & 0 deletions src/Microsoft.Data.Entity.Build.Tasks/EntityClean.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Data.Entity.Design;
using System.Data.Metadata.Edm;
using System.Globalization;
using System.IO;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Data.Entity.Build.Tasks.Properties;

namespace Microsoft.Data.Entity.Build.Tasks
{
public class EntityClean: Task
{
private ITaskItem[] _sources;
private string _resourceOutputPath;
private string _outputPath;

[Required]
public ITaskItem[] Sources
{
get { return _sources; }
set { _sources = value; }
}

/// <remarks>
/// [Required] - this (required) property doesn't exist in v3.5 and prevents targeting v3.5 framework and tools from v4
/// the v3.5 Microsoft.Data.Entity.targets won't use the property
/// the v4.0 Microsoft.Data.Entity.targets will always supply the property
/// other target files are not expected to directly use Microsoft.Data.Entity.Build.Tasks.dll
/// </remarks>
public string ResourceOutputPath
{
get { return _resourceOutputPath; }
set { _resourceOutputPath = value; }
}

[Required]
public string OutputPath
{
get { return _outputPath; }
set { _outputPath = value; }
}

public override bool Execute()
{
bool allFilesCleaned = true;

// the source's itemspec will mirror the metadata locations
// in the bin directory exactly.
foreach (ITaskItem source in this.Sources)
{
// combine the output path and the edmx file location to create a location that points to where the
// output files exist
string relativePath = EntityDeploySplit.EntityDeployMetadataRelativePath(source);
string resourceOutputModelPath = (null != this.ResourceOutputPath) ? Path.Combine(this.ResourceOutputPath, relativePath) : null;
string outputModelPath = Path.Combine(this.OutputPath, relativePath);
List<FileInfo> filesToDelete = new List<FileInfo>();
try
{
// translate the 'fake' model path into the assumed locations of the csdl, ssdl, and msl locations
// under either ResourceOutputPath or OutputPath - file will be deleted if present under either one
// if resourceOutputModelPath is null then follow the v3.5 behavior
if (null != resourceOutputModelPath)
{
filesToDelete.Add(new FileInfo(Path.ChangeExtension(resourceOutputModelPath, XmlConstants.CSpaceSchemaExtension)));
filesToDelete.Add(new FileInfo(Path.ChangeExtension(resourceOutputModelPath, XmlConstants.SSpaceSchemaExtension)));
filesToDelete.Add(new FileInfo(Path.ChangeExtension(resourceOutputModelPath, XmlConstants.CSSpaceSchemaExtension)));
}

filesToDelete.Add(new FileInfo(Path.ChangeExtension(outputModelPath, XmlConstants.CSpaceSchemaExtension)));
filesToDelete.Add(new FileInfo(Path.ChangeExtension(outputModelPath, XmlConstants.SSpaceSchemaExtension)));
filesToDelete.Add(new FileInfo(Path.ChangeExtension(outputModelPath, XmlConstants.CSSpaceSchemaExtension)));
}
catch (Exception ex)
{
// there are lots of possible exceptions here (Security, NotSupported, Argument, Unauthorized, etc.)
Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, source.ItemSpec));
Log.LogErrorFromException(ex, false);
allFilesCleaned = false;
continue;
}

// if each CSDL, SSDL, and MSL file exists, then delete it
foreach (FileInfo fileToDelete in filesToDelete)
{
if (fileToDelete.Exists)
{
try
{
fileToDelete.Delete();
Log.LogMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, Resources.FinishedCleaningFile, fileToDelete.FullName));
}
catch (Exception e)
{
Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorCleaningFile, fileToDelete.FullName));
Log.LogErrorFromException(e, false);
allFilesCleaned = false;
}
}
}

Log.LogMessage(string.Format(CultureInfo.CurrentCulture, Resources.FinishedCleaningEdmxFile, source.ItemSpec));
}

if (allFilesCleaned)
{
Log.LogMessage(string.Format(CultureInfo.CurrentCulture, Resources.FinishedCleaningAllFiles, this.Sources.Length));
}

return allFilesCleaned;
}
}
}
Loading

0 comments on commit 20f9c74

Please sign in to comment.