Add selective unzipping to avoid ASP.NET clobbering NetCore.App (#15272)
This commit is contained in:
commit
59530fd164
2 changed files with 39 additions and 7 deletions
|
@ -32,6 +32,11 @@ namespace Microsoft.DotNet.Build.Tasks
|
|||
/// </summary>
|
||||
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 ITaskItem[] DirectoriesToCopy { get; set; }
|
||||
|
||||
protected override bool ValidateParameters()
|
||||
{
|
||||
base.ValidateParameters();
|
||||
|
@ -73,13 +78,37 @@ namespace Microsoft.DotNet.Build.Tasks
|
|||
{
|
||||
if (ValidateParameters())
|
||||
{
|
||||
#if NETFRAMEWORK
|
||||
// .NET Framework doesn't have overload to overwrite files
|
||||
ZipFile.ExtractToDirectory(SourceArchive, DestinationDirectory);
|
||||
#else
|
||||
ZipFile.ExtractToDirectory(SourceArchive, DestinationDirectory, overwriteFiles: true);
|
||||
#endif
|
||||
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)
|
||||
{
|
||||
if (entry.FullName.StartsWith(directory.ItemSpec))
|
||||
{
|
||||
if (!Directory.Exists(Path.Combine(DestinationDirectory, Path.GetDirectoryName(entry.FullName))))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(DestinationDirectory, Path.GetDirectoryName(entry.FullName)));
|
||||
}
|
||||
|
||||
Log.LogMessage(Path.GetDirectoryName(entry.FullName));
|
||||
entry.ExtractToFile(Path.Combine(loc, entry.FullName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NETFRAMEWORK
|
||||
// .NET Framework doesn't have overload to overwrite files
|
||||
ZipFile.ExtractToDirectory(SourceArchive, DestinationDirectory);
|
||||
#else
|
||||
|
||||
ZipFile.ExtractToDirectory(SourceArchive, DestinationDirectory, overwriteFiles: true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -274,6 +274,7 @@
|
|||
<BaseUrl Condition=" '$(DotNetBuildFromSource)' == 'true' AND '$(DotNetBuildFromSourceFlavor)' == 'Product' ">$(AspNetCoreSharedFxRootUrl)</BaseUrl>
|
||||
<DownloadFileName>$(AspNetCoreSharedFxArchiveFileName)</DownloadFileName>
|
||||
<RelativeLayoutPath></RelativeLayoutPath>
|
||||
<DirectoriesToCopy>shared/Microsoft.AspNetCore.App</DirectoriesToCopy>
|
||||
</BundledLayoutComponent>
|
||||
|
||||
<!-- The AspNet does not provide native MacOS PKG installers at this time; we use AspNet archives.
|
||||
|
@ -334,6 +335,7 @@
|
|||
<BundledLayoutComponent Include="WinFormsAndWpfSharedFxArchiveFile">
|
||||
<BaseUrl>$(WinFormsAndWpfSharedFxRootUrl)$(WindowsDesktopBlobVersion)</BaseUrl>
|
||||
<DownloadFileName>$(WinFormsAndWpfSharedFxArchiveFileName)</DownloadFileName>
|
||||
<DirectoriesToCopy>shared/Microsoft.WindowsDesktop.App</DirectoriesToCopy>
|
||||
</BundledLayoutComponent>
|
||||
|
||||
<BundledInstallerComponent Include="DownloadedWinFormsAndWpfSharedFrameworkInstallerFile"
|
||||
|
@ -447,7 +449,8 @@
|
|||
|
||||
<Target Name="LayoutBundledComponents">
|
||||
<ExtractArchiveToDirectory SourceArchive="%(BundledLayoutComponent.DownloadDestination)"
|
||||
DestinationDirectory="$(RedistLayoutPath)/%(BundledLayoutComponent.RelativeLayoutPath)" />
|
||||
DestinationDirectory="$(RedistLayoutPath)/%(BundledLayoutComponent.RelativeLayoutPath)"
|
||||
DirectoriesToCopy="%(BundledLayoutComponent.DirectoriesToCopy)"/>
|
||||
|
||||
<Copy SourceFiles="@(BundledLayoutPackageDownloadFilesWithDestination)"
|
||||
DestinationFiles="@(BundledLayoutPackageDownloadFilesWithDestination->'%(DestinationPath)')"
|
||||
|
|
Loading…
Reference in a new issue