2016-07-06 16:12:13 +02:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
2016-05-13 15:10:20 -07:00
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
2016-07-06 16:12:13 +02:00
|
|
|
using System;
|
2016-05-13 15:10:20 -07:00
|
|
|
using System.Collections.Generic;
|
2016-01-04 12:49:13 -08:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2016-01-04 23:12:40 -08:00
|
|
|
using Microsoft.DotNet.ProjectModel.Compilation;
|
2016-03-08 16:46:50 -08:00
|
|
|
using Microsoft.DotNet.ProjectModel.Graph;
|
2016-01-04 12:49:13 -08:00
|
|
|
|
2016-01-04 23:12:40 -08:00
|
|
|
namespace Microsoft.DotNet.Cli.Compiler.Common
|
2016-01-04 12:49:13 -08:00
|
|
|
{
|
2016-07-06 16:12:13 +02:00
|
|
|
public static class LibraryExporterExtensions
|
|
|
|
{
|
|
|
|
public static IEnumerable<LibraryExport> GetAllProjectTypeDependencies(this LibraryExporter exporter)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
exporter.GetDependencies(LibraryType.Project)
|
|
|
|
.Concat(exporter.GetDependencies(LibraryType.MSBuildProject));
|
|
|
|
}
|
2016-05-13 15:10:20 -07:00
|
|
|
|
2016-07-06 16:12:13 +02:00
|
|
|
public static void CopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath)
|
|
|
|
{
|
|
|
|
if (!Directory.Exists(destinationPath))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(destinationPath);
|
|
|
|
}
|
2016-02-09 12:01:52 -08:00
|
|
|
|
2016-07-06 16:12:13 +02:00
|
|
|
foreach (var asset in assets)
|
|
|
|
{
|
|
|
|
var file = Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath));
|
|
|
|
File.Copy(asset.ResolvedPath, file, overwrite: true);
|
|
|
|
RemoveFileAttribute(file, FileAttributes.ReadOnly);
|
|
|
|
}
|
|
|
|
}
|
2016-01-04 12:49:13 -08:00
|
|
|
|
2016-07-06 16:12:13 +02:00
|
|
|
private static void RemoveFileAttribute(String file, FileAttributes attribute)
|
|
|
|
{
|
|
|
|
if (File.Exists(file))
|
|
|
|
{
|
|
|
|
var fileAttributes = File.GetAttributes(file);
|
|
|
|
if ((fileAttributes & attribute) == attribute)
|
|
|
|
{
|
|
|
|
File.SetAttributes(file, fileAttributes & ~attribute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 10:57:25 -08:00
|
|
|
|
2016-07-06 16:12:13 +02:00
|
|
|
public static void StructuredCopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath, string tempLocation)
|
|
|
|
{
|
|
|
|
if (!Directory.Exists(destinationPath))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(destinationPath);
|
|
|
|
}
|
2016-02-03 10:57:25 -08:00
|
|
|
|
2016-07-06 16:12:13 +02:00
|
|
|
foreach (var asset in assets)
|
|
|
|
{
|
|
|
|
var targetName = ResolveTargetName(destinationPath, asset);
|
|
|
|
var transformedFile = asset.GetTransformedFile(tempLocation);
|
2016-02-03 10:57:25 -08:00
|
|
|
|
2016-07-06 16:12:13 +02:00
|
|
|
File.Copy(transformedFile, targetName, overwrite: true);
|
|
|
|
RemoveFileAttribute(targetName, FileAttributes.ReadOnly);
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 10:57:25 -08:00
|
|
|
|
2016-07-06 16:12:13 +02: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));
|
|
|
|
}
|
|
|
|
return targetName;
|
|
|
|
}
|
|
|
|
}
|
2016-01-04 12:49:13 -08:00
|
|
|
}
|