Addressing code review comments and adding a DOTNET_SKIP_FIRST_TIME_EXPERIENCE env variable to have a way to turn off the feature.
This commit is contained in:
parent
4d631cc1b1
commit
ed7e583ab6
8 changed files with 91 additions and 51 deletions
|
@ -164,12 +164,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
string rootOutputDirectory,
|
||||
DotNetCli currentDotnet)
|
||||
{
|
||||
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
|
||||
var sdkOutputDirectory = Path.Combine(rootOutputDirectory, "sdk", buildVersion.NuGetVersion);
|
||||
|
||||
CompileCliSdk(c, dotnet, rootOutputDirectory);
|
||||
|
||||
GenerateNuGetPackagesArchive(c, currentDotnet, sdkOutputDirectory);
|
||||
CompileCliSdk(c, dotnet, rootOutputDirectory, currentDotnet);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
@ -177,7 +172,8 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
private static BuildTargetResult CompileCliSdk(
|
||||
BuildTargetContext c,
|
||||
DotNetCli dotnet,
|
||||
string rootOutputDirectory)
|
||||
string rootOutputDirectory,
|
||||
DotNetCli dotnetToGenerateNuGetPackagesArchive = null)
|
||||
{
|
||||
var configuration = c.BuildContext.Get<string>("Configuration");
|
||||
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
|
||||
|
@ -280,8 +276,13 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}";
|
||||
File.WriteAllText(Path.Combine(sdkOutputDirectory, ".version"), content);
|
||||
|
||||
if(dotnetToGenerateNuGetPackagesArchive != null)
|
||||
{
|
||||
GenerateNuGetPackagesArchive(c, dotnetToGenerateNuGetPackagesArchive, sdkOutputDirectory);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateNuGetPackagesArchive(
|
||||
BuildTargetContext c,
|
||||
|
@ -325,7 +326,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
string sdkOutputDirectory)
|
||||
{
|
||||
var configuration = c.BuildContext.Get<string>("Configuration");
|
||||
var archiver = Path.Combine(Dirs.Output, "tools", $"Archiver{Constants.ExeSuffix}");
|
||||
var archiverExe = Path.Combine(Dirs.Output, "tools", $"Archiver{Constants.ExeSuffix}");
|
||||
var intermediateArchive = Path.Combine(Dirs.Intermediate, "nuGetPackagesArchive.lzma");
|
||||
var finalArchive = Path.Combine(sdkOutputDirectory, "nuGetPackagesArchive.lzma");
|
||||
|
||||
|
@ -334,14 +335,14 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
|
||||
c.Info("Publishing Archiver");
|
||||
dotnet.Publish("--output", Path.Combine(Dirs.Output, "tools"), "--configuration", configuration)
|
||||
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "tools", "Archiver"))
|
||||
.WorkingDirectory(Path.Combine(Dirs.RepoRoot, "tools", "Archiver"))
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
|
||||
Cmd(archiver,
|
||||
Cmd(archiverExe,
|
||||
"-a", intermediateArchive,
|
||||
nuGetPackagesArchiveFolder)
|
||||
.Execute();
|
||||
.Execute();
|
||||
|
||||
File.Copy(intermediateArchive, finalArchive);
|
||||
}
|
||||
|
|
|
@ -9,13 +9,18 @@ namespace Microsoft.DotNet.Configurer
|
|||
{
|
||||
public class DotnetFirstTimeUseConfigurer
|
||||
{
|
||||
private IEnvironmentProvider _environmentProvider;
|
||||
private INuGetCachePrimer _nugetCachePrimer;
|
||||
private INuGetCacheSentinel _nugetCacheSentinel;
|
||||
|
||||
public DotnetFirstTimeUseConfigurer(INuGetCachePrimer nugetCachePrimer, INuGetCacheSentinel nugetCacheSentinel)
|
||||
public DotnetFirstTimeUseConfigurer(
|
||||
INuGetCachePrimer nugetCachePrimer,
|
||||
INuGetCacheSentinel nugetCacheSentinel,
|
||||
IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_nugetCachePrimer = nugetCachePrimer;
|
||||
_nugetCacheSentinel = nugetCacheSentinel;
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
||||
public void Configure()
|
||||
|
@ -30,29 +35,28 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
private void PrintFirstTimeUseNotice()
|
||||
{
|
||||
const string firstTimeUseWelcomeMessage = @"Welcome to .NET Core!
|
||||
---------------------
|
||||
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
|
||||
Telemetry
|
||||
--------------
|
||||
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
|
||||
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
|
||||
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
|
||||
Configuring...
|
||||
-------------------
|
||||
A command is running to initially populate your local package cache, to improve restorespeed and enable offline access. This command will take up to a minute to complete and will only happen once.";
|
||||
|
||||
Reporter.Output.WriteLine();
|
||||
Reporter.Output.WriteLine("Welcome to .NET Core!");
|
||||
Reporter.Output.WriteLine("---------------------");
|
||||
Reporter.Output.WriteLine("Learn more about .NET Core @ https://aka.ms/dotnet-docs. " +
|
||||
"Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.");
|
||||
Reporter.Output.WriteLine("Telemetry");
|
||||
Reporter.Output.WriteLine("--------------");
|
||||
Reporter.Output.WriteLine("The .NET Core tools collect usage data in order to improve your experience. " +
|
||||
"The data is anonymous and does not include commandline arguments. " +
|
||||
"The data is collected by Microsoft and shared with the community.");
|
||||
Reporter.Output.WriteLine();
|
||||
Reporter.Output.WriteLine("You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT " +
|
||||
"environment variable to 1 using your favorite shell.");
|
||||
Reporter.Output.WriteLine("You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.");
|
||||
Reporter.Output.WriteLine("Configuring...");
|
||||
Reporter.Output.WriteLine("-------------------");
|
||||
Reporter.Output.WriteLine("A command is running to initially populate your local package cache, to improve restore" +
|
||||
"speed and enable offline access. This command will take up to a minute to complete and will only happen once.");
|
||||
Reporter.Output.WriteLine(firstTimeUseWelcomeMessage);
|
||||
}
|
||||
|
||||
private bool ShouldPrimeNugetCache()
|
||||
{
|
||||
return !_nugetCacheSentinel.Exists();
|
||||
var skipFirstTimeExperience =
|
||||
_environmentProvider.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false));
|
||||
|
||||
return !skipFirstTimeExperience && !_nugetCacheSentinel.Exists();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,9 @@ namespace Microsoft.DotNet.Configurer
|
|||
return;
|
||||
}
|
||||
|
||||
var pathToPackagesArchive = _nugetPackagesArchiver.ExtractArchive();
|
||||
var extractedPackagesArchiveDirectory = _nugetPackagesArchiver.ExtractArchive();
|
||||
|
||||
PrimeCacheUsingArchive(pathToPackagesArchive);
|
||||
PrimeCacheUsingArchive(extractedPackagesArchiveDirectory);
|
||||
}
|
||||
|
||||
private bool SkipPrimingTheCache()
|
||||
|
@ -60,7 +60,7 @@ namespace Microsoft.DotNet.Configurer
|
|||
return !_file.Exists(_nugetPackagesArchiver.NuGetPackagesArchive);
|
||||
}
|
||||
|
||||
private void PrimeCacheUsingArchive(string pathToPackagesArchive)
|
||||
private void PrimeCacheUsingArchive(string extractedPackagesArchiveDirectory)
|
||||
{
|
||||
using (var temporaryDotnetNewDirectory = _directory.CreateTemporaryDirectory())
|
||||
{
|
||||
|
@ -69,7 +69,8 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
if (createProjectSucceeded)
|
||||
{
|
||||
var restoreProjectSucceeded = RestoreTemporaryProject(pathToPackagesArchive, workingDirectory);
|
||||
var restoreProjectSucceeded =
|
||||
RestoreTemporaryProject(extractedPackagesArchiveDirectory, workingDirectory);
|
||||
if (restoreProjectSucceeded)
|
||||
{
|
||||
_nuGetCacheSentinel.CreateIfNotExists();
|
||||
|
@ -83,11 +84,11 @@ namespace Microsoft.DotNet.Configurer
|
|||
return RunCommand("new", Enumerable.Empty<string>(), workingDirectory);
|
||||
}
|
||||
|
||||
private bool RestoreTemporaryProject(string pathToPackagesArchive, string workingDirectory)
|
||||
private bool RestoreTemporaryProject(string extractedPackagesArchiveDirectory, string workingDirectory)
|
||||
{
|
||||
return RunCommand(
|
||||
"restore",
|
||||
new[] {NUGET_SOURCE_PARAMETER, $"{pathToPackagesArchive}"},
|
||||
new[] {NUGET_SOURCE_PARAMETER, $"{extractedPackagesArchiveDirectory}"},
|
||||
workingDirectory);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
},
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0-rc3-004391"
|
||||
"version": "1.0.0-rc3-004449-00"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
|
|
|
@ -55,10 +55,10 @@ namespace Microsoft.DotNet.Cli
|
|||
|
||||
try
|
||||
{
|
||||
ConfigureDotNetForFirstTimeUse();
|
||||
|
||||
using (PerfTrace.Current.CaptureTiming())
|
||||
{
|
||||
ConfigureDotNetForFirstTimeUse();
|
||||
|
||||
return ProcessArgs(args, new Telemetry());
|
||||
}
|
||||
}
|
||||
|
@ -162,15 +162,23 @@ namespace Microsoft.DotNet.Cli
|
|||
|
||||
private static void ConfigureDotNetForFirstTimeUse()
|
||||
{
|
||||
using (var nugetPackagesArchiver = new NuGetPackagesArchiver())
|
||||
using (PerfTrace.Current.CaptureTiming())
|
||||
{
|
||||
var nugetCacheSentinel = new NuGetCacheSentinel();
|
||||
var commandFactory = new DotNetCommandFactory();
|
||||
var nugetCachePrimer = new NuGetCachePrimer(commandFactory, nugetPackagesArchiver, nugetCacheSentinel);
|
||||
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(nugetCachePrimer, nugetCacheSentinel);
|
||||
using (var nugetPackagesArchiver = new NuGetPackagesArchiver())
|
||||
{
|
||||
var environmentProvider = new EnvironmentProvider();
|
||||
var nugetCacheSentinel = new NuGetCacheSentinel();
|
||||
var commandFactory = new DotNetCommandFactory();
|
||||
var nugetCachePrimer =
|
||||
new NuGetCachePrimer(commandFactory, nugetPackagesArchiver, nugetCacheSentinel);
|
||||
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
nugetCachePrimer,
|
||||
nugetCacheSentinel,
|
||||
environmentProvider);
|
||||
|
||||
dotnetConfigurer.Configure();
|
||||
}
|
||||
dotnetConfigurer.Configure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitializeProcess()
|
||||
|
|
|
@ -15,11 +15,17 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
{
|
||||
private Mock<INuGetCachePrimer> _nugetCachePrimerMock;
|
||||
private Mock<INuGetCacheSentinel> _nugetCacheSentinelMock;
|
||||
private Mock<IEnvironmentProvider> _environmentProviderMock;
|
||||
|
||||
public GivenADotnetFirstTimeUseConfigurer()
|
||||
{
|
||||
_nugetCachePrimerMock = new Mock<INuGetCachePrimer>();
|
||||
_nugetCacheSentinelMock = new Mock<INuGetCacheSentinel>();
|
||||
_environmentProviderMock = new Mock<IEnvironmentProvider>();
|
||||
|
||||
_environmentProviderMock
|
||||
.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false))
|
||||
.Returns(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -29,7 +35,26 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object);
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
_nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_does_not_prime_the_cache_if_the_sentinel_exists_but_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environemnt_variable()
|
||||
{
|
||||
_nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(false);
|
||||
_environmentProviderMock
|
||||
.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false))
|
||||
.Returns(true);
|
||||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
|
@ -43,7 +68,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
|
||||
var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
_nugetCachePrimerMock.Object,
|
||||
_nugetCacheSentinelMock.Object);
|
||||
_nugetCacheSentinelMock.Object,
|
||||
_environmentProviderMock.Object);
|
||||
|
||||
dotnetFirstTimeUseConfigurer.Configure();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0-rc3-004363"
|
||||
"version": "1.0.0-rc3-004442-00"
|
||||
},
|
||||
"System.Diagnostics.TraceSource": "4.0.0-rc3-24131-00",
|
||||
"Microsoft.DotNet.Configurer": {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"Microsoft.DotNet.Archive": {
|
||||
"target": "project"
|
||||
},
|
||||
"Microsoft.NETCore.App": "1.0.0-rc3-004391"
|
||||
"Microsoft.NETCore.App": "1.0.0-rc3-004442-00"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {}
|
||||
|
|
Loading…
Reference in a new issue