Include ASP packages in offline cache (#5124)

* Archive asp.net package references

* Archive asp.net package references

* Change the hash input so it's the same on all platforms

* Address PR comments
This commit is contained in:
Justin Goshi 2016-12-27 11:28:24 -10:00 committed by GitHub
parent 47fb245258
commit b72d625168
12 changed files with 138 additions and 11 deletions

View file

@ -69,6 +69,10 @@
<Output TaskParameter="BranchName" PropertyName="BranchName" />
</GenerateBuildVersionInfo>
<GenerateNuGetPackagesArchiveVersion RepoRoot="$(RepoRoot)">
<Output TaskParameter="Version" PropertyName="NuGetPackagesArchiveVersion"/>
</GenerateNuGetPackagesArchiveVersion>
<PropertyGroup>
<VersionBadge>$(BaseOutputDirectory)/$(VersionBadgeMoniker)_$(Configuration)_version_badge.svg</VersionBadge>
<SdkVersion>$(NugetVersion)</SdkVersion>
@ -129,7 +133,6 @@
<CoreSetupBlobRootUrl>https://dotnetcli.azureedge.net/dotnet/$(CoreSetupChannel)</CoreSetupBlobRootUrl>
<SharedFrameworkArchiveBlobRootUrl>$(CoreSetupBlobRootUrl)/Binaries/$(SharedFrameworkVersion)</SharedFrameworkArchiveBlobRootUrl>
<CoreSetupInstallerBlobRootUrl>$(CoreSetupBlobRootUrl)/Installers</CoreSetupInstallerBlobRootUrl>
<CoreSetupDownloadDirectory>$(IntermediateDirectory)/coreSetupDownload/$(SharedFrameworkVersion)</CoreSetupDownloadDirectory>
<CombinedSharedHostAndFrameworkArchive>$(CoreSetupDownloadDirectory)/combinedSharedHostAndFrameworkArchive</CombinedSharedHostAndFrameworkArchive>
</PropertyGroup>

View file

@ -19,6 +19,7 @@
<UsingTask TaskName="GenerateBuildVersionInfo" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GenerateChecksums" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GenerateGuidFromName" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GenerateNuGetPackagesArchiveVersion" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GetCommitHash" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="GetCurrentRuntimeInformation" AssemblyFile="$(CLIBuildDll)" />
<UsingTask TaskName="MakeRelative" AssemblyFile="$(CLIBuildDll)" />

View file

@ -21,7 +21,7 @@
<ItemGroup>
<NuGetPackagesArchiveToUpload>
<RelativeBlobPath>$(CoreSetupChannel)/Binaries/$(SharedFrameworkVersion)/$([System.String]::Copy('%(Filename)%(Extension)').Replace('\' ,'/'))</RelativeBlobPath>
<RelativeBlobPath>$(CoreSetupChannel)/Binaries/$(NuGetPackagesArchiveVersion)/$([System.String]::Copy('%(Filename)%(Extension)').Replace('\' ,'/'))</RelativeBlobPath>
</NuGetPackagesArchiveToUpload>
</ItemGroup>
@ -61,6 +61,7 @@
<MakeDir Directories="$(NuGetPackagesArchiveProject);$(NuGetPackagesArchiveFolder)"/>
<DotNetNew ToolPath="$(Stage2Directory)"
TemplateType="Web"
WorkingDirectory="$(NuGetPackagesArchiveProject)" />
<DotNetRestore ToolPath="$(Stage2Directory)"
@ -83,7 +84,7 @@
<Target Name="SetupNuGetPackagesArchiveInputsOutputs"
DependsOnTargets="Prepare;SetupStage">
<PropertyGroup>
<NugetPackagesArchiveName>nuGetPackagesArchive.$(SharedFrameworkVersion).lzma</NugetPackagesArchiveName>
<NugetPackagesArchiveName>nuGetPackagesArchive.$(NuGetPackagesArchiveVersion).lzma</NugetPackagesArchiveName>
<NuGetPackagesArchiveProject>$(IntermediateDirectory)/NuGetPackagesArchiveProject</NuGetPackagesArchiveProject>
<NuGetPackagesArchiveFolder>$(IntermediateDirectory)/NuGetPackagesArchiveFolder</NuGetPackagesArchiveFolder>
<ArchiverDll>$(ToolsOutputDirectory)/Archiver.dll</ArchiverDll>

View file

@ -12,7 +12,19 @@ namespace Microsoft.DotNet.Cli.Build
protected override string Args
{
get { return $""; }
get { return $"{GetTemplateType()}"; }
}
public string TemplateType { get; set; }
private string GetTemplateType()
{
if (!string.IsNullOrEmpty(TemplateType))
{
return $"--type {TemplateType}";
}
return null;
}
}
}

View file

@ -0,0 +1,75 @@
// 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.
using Microsoft.Build.Construction;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace Microsoft.DotNet.Cli.Build
{
public class GenerateNuGetPackagesArchiveVersion : Task
{
public GenerateNuGetPackagesArchiveVersion()
{
}
[Required]
public string RepoRoot { get; set; }
[Output]
public String Version { get; set; }
public override bool Execute()
{
var webTemplatePath = Path.Combine(
RepoRoot,
"src",
"dotnet",
"commands",
"dotnet-new",
"CSharp_Web",
"$projectName$.csproj");
var rootElement = ProjectRootElement.Open(webTemplatePath);
var packageRefs = rootElement.Items.Where(i => i.ItemType == "PackageReference").ToList();
var dataToHash = string.Empty;
foreach (var packageRef in packageRefs)
{
dataToHash += $"{packageRef.Include},";
if (packageRef.HasMetadata)
{
foreach (var metadata in packageRef.Metadata)
{
dataToHash += $"{metadata.Name}={metadata.Value};";
}
}
}
Log.LogMessage($"NuGet Packages Archive Data To Hash: '{dataToHash}'");
var sha256 = SHA256.Create();
var hashBytes = sha256.ComputeHash(Encoding.Unicode.GetBytes(dataToHash));
Version = GetHashString(hashBytes);
Log.LogMessage($"NuGet Packages Archive Version: '{Version}'");
return true;
}
private string GetHashString(byte[] hashBytes)
{
StringBuilder builder = new StringBuilder(hashBytes.Length * 2);
foreach (var b in hashBytes)
{
builder.AppendFormat("{0:x2}", b);
}
return builder.ToString();
}
}
}

View file

@ -16,6 +16,9 @@
<PackageReference Include="Microsoft.NETCore.Runtime.CoreCLR">
<Version>1.0.4</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build">
<Version>$(CLI_MSBuild_Version)</Version>
</PackageReference>
<PackageReference Include="Microsoft.CSharp">
<Version>4.0.1</Version>
</PackageReference>

View file

@ -90,7 +90,10 @@ namespace Microsoft.DotNet.Configurer
private bool CreateTemporaryProject(string workingDirectory)
{
return RunCommand("new", Enumerable.Empty<string>(), workingDirectory);
return RunCommand(
"new",
new[] { "-t", "Web" },
workingDirectory);
}
private bool RestoreTemporaryProject(string extractedPackagesArchiveDirectory, string workingDirectory)

View file

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<Compile Include="..\dotnet\CommandLine\*.cs" />
<Compile Include="..\dotnet\CommandLine\*.cs;..\dotnet\CommonLocalizableStrings.cs;" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.DotNet.Archive\Microsoft.DotNet.Archive.csproj" />

View file

@ -62,7 +62,7 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_dotnetNewCommandMock = new Mock<ICommand>();
SetupCommandMock(_dotnetNewCommandMock);
commandFactoryMock
.Setup(c => c.Create("new", Enumerable.Empty<string>(), null, Constants.DefaultConfiguration))
.Setup(c => c.Create("new", new[] { "-t", "Web" }, null, Constants.DefaultConfiguration))
.Returns(_dotnetNewCommandMock.Object);
_dotnetRestoreCommandMock = new Mock<ICommand>();

View file

@ -127,6 +127,16 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return new AndConstraint<DirectoryInfoAssertions>(new DirectoryInfoAssertions(dir));
}
public AndConstraint<DirectoryInfoAssertions> HaveDirectories(IEnumerable<string> expectedDirs)
{
foreach (var expectedDir in expectedDirs)
{
HaveDirectory(expectedDir);
}
return new AndConstraint<DirectoryInfoAssertions>(this);
}
public AndConstraint<DirectoryInfoAssertions> OnlyHaveFiles(IEnumerable<string> expectedFiles)
{
var actualFiles = _dirInfo.EnumerateFiles("*", SearchOption.TopDirectoryOnly).Select(f => f.Name);

View file

@ -78,7 +78,7 @@ A command is running to initially populate your local package cache, to improve
}
[Fact]
public void ItRestoresTheNuGetPackagesToTheNuGetCacheFolder()
public void ItCreatesASentinelFileUnderTheNuGetCacheFolder()
{
_nugetCacheFolder
.Should()
@ -86,11 +86,30 @@ A command is running to initially populate your local package cache, to improve
}
[Fact]
public void ItCreatesASentinelFileUnderTheNuGetCacheFolder()
public void ItRestoresTheNuGetPackagesToTheNuGetCacheFolder()
{
List<string> expectedDirectories = new List<string>()
{
"microsoft.netcore.app",
"microsoft.aspnetcore.diagnostics",
"microsoft.aspnetcore.mvc",
"microsoft.aspnetcore.razor.tools",
"microsoft.aspnetcore.routing",
"microsoft.aspnetcore.server.iisintegration",
"microsoft.aspnetcore.server.kestrel",
"microsoft.aspnetcore.staticfiles",
"microsoft.extensions.configuration.environmentvariables",
"microsoft.extensions.configuration.json",
"microsoft.extensions.logging",
"microsoft.extensions.logging.console",
"microsoft.extensions.logging.debug",
"microsoft.extensions.options.configurationextensions",
"microsoft.visualstudio.web.browserlink.loader",
};
_nugetCacheFolder
.Should()
.HaveDirectory("microsoft.netcore.app");
.HaveDirectories(expectedDirectories);
}
private string GetDotnetVersion()

View file

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<Compile Include="..\..\src\dotnet-archive\*.cs;..\..\src\dotnet\CommandLine\*.cs" />
<Compile Include="..\..\src\dotnet-archive\*.cs;..\..\src\dotnet\CommandLine\*.cs;..\..\src\dotnet\CommonLocalizableStrings.cs;" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.DotNet.Archive\Microsoft.DotNet.Archive.csproj" />