Change approach to only extract files that match criteria
This commit is contained in:
parent
0f4680522b
commit
c1a4771218
2 changed files with 40 additions and 5 deletions
|
@ -32,6 +32,11 @@ namespace Microsoft.DotNet.Build.Tasks
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CleanDestination { get; set; }
|
public bool CleanDestination { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A list of directories, semicolon deliminated, relative to the root of the archive to include. If empty all directories will be copied.
|
||||||
|
/// </summary>
|
||||||
|
public string DirectoriesToCopy { get; set; }
|
||||||
|
|
||||||
protected override bool ValidateParameters()
|
protected override bool ValidateParameters()
|
||||||
{
|
{
|
||||||
base.ValidateParameters();
|
base.ValidateParameters();
|
||||||
|
@ -73,13 +78,41 @@ namespace Microsoft.DotNet.Build.Tasks
|
||||||
{
|
{
|
||||||
if (ValidateParameters())
|
if (ValidateParameters())
|
||||||
{
|
{
|
||||||
|
if (DirectoriesToCopy != null && DirectoriesToCopy.Length != 0)
|
||||||
|
{
|
||||||
|
var zip = new ZipArchive(File.OpenRead(SourceArchive));
|
||||||
|
string loc = DestinationDirectory;
|
||||||
|
foreach (var entry in zip.Entries)
|
||||||
|
{
|
||||||
|
foreach (var directory in DirectoriesToCopy.Split(';'))
|
||||||
|
{
|
||||||
|
if (entry.FullName.Contains(directory))
|
||||||
|
{
|
||||||
|
string dirBuilder = loc;
|
||||||
|
foreach (var pathPart in Path.GetDirectoryName(entry.FullName).Split('/'))
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(Path.Combine(dirBuilder, pathPart)))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(Path.Combine(dirBuilder, pathPart));
|
||||||
|
}
|
||||||
|
dirBuilder = Path.Combine(dirBuilder, pathPart);
|
||||||
|
}
|
||||||
|
Log.LogMessage(Path.GetDirectoryName(entry.FullName));
|
||||||
|
entry.ExtractToFile(Path.Combine(loc, entry.FullName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
// .NET Framework doesn't have overload to overwrite files
|
// .NET Framework doesn't have overload to overwrite files
|
||||||
ZipFile.ExtractToDirectory(SourceArchive, DestinationDirectory);
|
ZipFile.ExtractToDirectory(SourceArchive, DestinationDirectory);
|
||||||
#else
|
#else
|
||||||
ZipFile.ExtractToDirectory(SourceArchive, DestinationDirectory, overwriteFiles: true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
ZipFile.ExtractToDirectory(SourceArchive, DestinationDirectory, overwriteFiles: true);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -267,6 +267,7 @@
|
||||||
<BaseUrl Condition=" '$(DotNetBuildFromSource)' == 'true' AND '$(DotNetBuildFromSourceFlavor)' == 'Product' ">$(AspNetCoreSharedFxRootUrl)</BaseUrl>
|
<BaseUrl Condition=" '$(DotNetBuildFromSource)' == 'true' AND '$(DotNetBuildFromSourceFlavor)' == 'Product' ">$(AspNetCoreSharedFxRootUrl)</BaseUrl>
|
||||||
<DownloadFileName>$(AspNetCoreSharedFxArchiveFileName)</DownloadFileName>
|
<DownloadFileName>$(AspNetCoreSharedFxArchiveFileName)</DownloadFileName>
|
||||||
<RelativeLayoutPath></RelativeLayoutPath>
|
<RelativeLayoutPath></RelativeLayoutPath>
|
||||||
|
<DirectoriesToCopy>shared/Microsoft.AspNetCore.App</DirectoriesToCopy>
|
||||||
</BundledLayoutComponent>
|
</BundledLayoutComponent>
|
||||||
|
|
||||||
<!-- The AspNet does not provide native MacOS PKG installers at this time; we use AspNet archives.
|
<!-- The AspNet does not provide native MacOS PKG installers at this time; we use AspNet archives.
|
||||||
|
@ -449,7 +450,8 @@
|
||||||
|
|
||||||
<Target Name="LayoutBundledComponents">
|
<Target Name="LayoutBundledComponents">
|
||||||
<ExtractArchiveToDirectory SourceArchive="%(BundledLayoutComponent.DownloadDestination)"
|
<ExtractArchiveToDirectory SourceArchive="%(BundledLayoutComponent.DownloadDestination)"
|
||||||
DestinationDirectory="$(RedistLayoutPath)/%(BundledLayoutComponent.RelativeLayoutPath)" />
|
DestinationDirectory="$(RedistLayoutPath)/%(BundledLayoutComponent.RelativeLayoutPath)"
|
||||||
|
DirectoriesToCopy="%(BundledLayoutComponent.DirectoriesToCopy)"/>
|
||||||
|
|
||||||
<Copy SourceFiles="@(BundledLayoutPackageDownloadFilesWithDestination)"
|
<Copy SourceFiles="@(BundledLayoutPackageDownloadFilesWithDestination)"
|
||||||
DestinationFiles="@(BundledLayoutPackageDownloadFilesWithDestination->'%(DestinationPath)')"
|
DestinationFiles="@(BundledLayoutPackageDownloadFilesWithDestination->'%(DestinationPath)')"
|
||||||
|
|
Loading…
Add table
Reference in a new issue