dotnet-installer/src/Microsoft.DotNet.Compiler.Common/LibraryExporterExtensions.cs

64 lines
2.1 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.IO;
using System;
using System.Linq;
2016-03-08 16:46:50 -08:00
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Compilation;
2016-03-08 16:46:50 -08:00
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.Extensions.DependencyModel;
namespace Microsoft.DotNet.Cli.Compiler.Common
{
2016-01-06 02:27:16 -08:00
public static class LibraryExporterExtensions
{
2016-02-09 12:01:52 -08:00
public static void CopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath)
{
2016-02-09 12:01:52 -08:00
if (!Directory.Exists(destinationPath))
{
Directory.CreateDirectory(destinationPath);
}
foreach (var asset in assets)
{
File.Copy(asset.ResolvedPath, Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath)), overwrite: true);
}
}
2016-02-17 10:08:27 -08:00
public static void StructuredCopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath, string tempLocation)
{
2016-02-03 10:57:25 -08:00
if (!Directory.Exists(destinationPath))
{
Directory.CreateDirectory(destinationPath);
}
foreach (var asset in assets)
{
2016-02-03 10:57:25 -08:00
var targetName = ResolveTargetName(destinationPath, asset);
2016-02-17 10:08:27 -08:00
var transformedFile = asset.GetTransformedFile(tempLocation);
2016-02-03 10:57:25 -08:00
2016-02-17 10:08:27 -08:00
File.Copy(transformedFile, targetName, overwrite: true);
2016-02-03 10:57:25 -08:00
}
}
private static string ResolveTargetName(string destinationPath, LibraryAsset asset)
{
string targetName;
if (!string.IsNullOrEmpty(asset.RelativePath))
{
targetName = Path.Combine(destinationPath, asset.RelativePath);
var destinationAssetPath = Path.GetDirectoryName(targetName);
if (!Directory.Exists(destinationAssetPath))
{
Directory.CreateDirectory(destinationAssetPath);
}
}
else
{
targetName = Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath));
}
2016-02-03 10:57:25 -08:00
return targetName;
}
}
}