Update LibraryExporterExtensions.cs
This commit is contained in:
parent
2aa07efa10
commit
f769f9ea1c
1 changed files with 68 additions and 52 deletions
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -9,62 +10,77 @@ using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Compiler.Common
|
namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
{
|
{
|
||||||
public static class LibraryExporterExtensions
|
public static class LibraryExporterExtensions
|
||||||
{
|
{
|
||||||
public static IEnumerable<LibraryExport> GetAllProjectTypeDependencies(this LibraryExporter exporter)
|
public static IEnumerable<LibraryExport> GetAllProjectTypeDependencies(this LibraryExporter exporter)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
exporter.GetDependencies(LibraryType.Project)
|
exporter.GetDependencies(LibraryType.Project)
|
||||||
.Concat(exporter.GetDependencies(LibraryType.MSBuildProject));
|
.Concat(exporter.GetDependencies(LibraryType.MSBuildProject));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath)
|
public static void CopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(destinationPath))
|
if (!Directory.Exists(destinationPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(destinationPath);
|
Directory.CreateDirectory(destinationPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var asset in assets)
|
foreach (var asset in assets)
|
||||||
{
|
{
|
||||||
File.Copy(asset.ResolvedPath, Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath)), overwrite: true);
|
var file = Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath));
|
||||||
}
|
File.Copy(asset.ResolvedPath, file, overwrite: true);
|
||||||
}
|
RemoveFileAttribute(file, FileAttributes.ReadOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void StructuredCopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath, string tempLocation)
|
private static void RemoveFileAttribute(String file, FileAttributes attribute)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(destinationPath))
|
if (File.Exists(file))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(destinationPath);
|
var fileAttributes = File.GetAttributes(file);
|
||||||
}
|
if ((fileAttributes & attribute) == attribute)
|
||||||
|
{
|
||||||
|
File.SetAttributes(file, fileAttributes & ~attribute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var asset in assets)
|
public static void StructuredCopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath, string tempLocation)
|
||||||
{
|
{
|
||||||
var targetName = ResolveTargetName(destinationPath, asset);
|
if (!Directory.Exists(destinationPath))
|
||||||
var transformedFile = asset.GetTransformedFile(tempLocation);
|
{
|
||||||
|
Directory.CreateDirectory(destinationPath);
|
||||||
|
}
|
||||||
|
|
||||||
File.Copy(transformedFile, targetName, overwrite: true);
|
foreach (var asset in assets)
|
||||||
}
|
{
|
||||||
}
|
var targetName = ResolveTargetName(destinationPath, asset);
|
||||||
|
var transformedFile = asset.GetTransformedFile(tempLocation);
|
||||||
|
|
||||||
private static string ResolveTargetName(string destinationPath, LibraryAsset asset)
|
File.Copy(transformedFile, targetName, overwrite: true);
|
||||||
{
|
RemoveFileAttribute(targetName, FileAttributes.ReadOnly);
|
||||||
string targetName;
|
}
|
||||||
if (!string.IsNullOrEmpty(asset.RelativePath))
|
}
|
||||||
{
|
|
||||||
targetName = Path.Combine(destinationPath, asset.RelativePath);
|
|
||||||
var destinationAssetPath = Path.GetDirectoryName(targetName);
|
|
||||||
|
|
||||||
if (!Directory.Exists(destinationAssetPath))
|
private static string ResolveTargetName(string destinationPath, LibraryAsset asset)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(destinationAssetPath);
|
string targetName;
|
||||||
}
|
if (!string.IsNullOrEmpty(asset.RelativePath))
|
||||||
}
|
{
|
||||||
else
|
targetName = Path.Combine(destinationPath, asset.RelativePath);
|
||||||
{
|
var destinationAssetPath = Path.GetDirectoryName(targetName);
|
||||||
targetName = Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath));
|
|
||||||
}
|
if (!Directory.Exists(destinationAssetPath))
|
||||||
return targetName;
|
{
|
||||||
}
|
Directory.CreateDirectory(destinationAssetPath);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
targetName = Path.Combine(destinationPath, Path.GetFileName(asset.ResolvedPath));
|
||||||
|
}
|
||||||
|
return targetName;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue