Merge pull request #6955 from livarcocc/fallback_folder_in_dotnet_hive

Move the NuGet fallback folder into the dotnet hive
This commit is contained in:
Livar 2017-06-20 15:51:39 -07:00 committed by GitHub
commit 1792723623
40 changed files with 441 additions and 182 deletions

View file

@ -6,13 +6,13 @@
<CLI_Roslyn_Version>2.3.0-beta3-61816-04</CLI_Roslyn_Version>
<CLI_DiaSymNative_Version>1.6.0-beta2-25304</CLI_DiaSymNative_Version>
<CLI_FSharp_Version>4.2.0-rc-170602-0</CLI_FSharp_Version>
<!-- We'll usually want to keep these versions in sync, but we may want to diverge in some
cases, so use separate properties but derive one from the other unless we want to
explicitly use different versions. -->
<CLI_NETSDK_Version>2.0.0-preview2-20170615-7</CLI_NETSDK_Version>
<CLI_MSBuildExtensions_Version>$(CLI_NETSDK_Version)</CLI_MSBuildExtensions_Version>
<CLI_NuGet_Version>4.3.0-preview3-4168</CLI_NuGet_Version>
<CLI_NETStandardLibraryNETFrameworkVersion>2.0.0-preview2-25331-02</CLI_NETStandardLibraryNETFrameworkVersion>
<CLI_WEBSDK_Version>2.0.0-rel-20170518-512</CLI_WEBSDK_Version>

View file

@ -2,7 +2,7 @@
echo "This software may collect information about you and your use of the software, and send that to Microsoft."
echo "Please visit http://aka.ms/dotnet-cli-eula for more information."
# Run 'dotnet new' as the user to trigger the first time experience to initialize the cache
# Run 'dotnet new' to trigger the first time experience to initialize the cache
echo "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.
@ -15,4 +15,4 @@ The data collected is anonymous and will be published in an aggregated form for
The .NET Core Tools telemetry feature is enabled by default. You can opt-out of the telemetry feature by setting an environment variable DOTNET_CLI_TELEMETRY_OPTOUT (for example, 'export' on macOS/Linux, 'set' on Windows) to true (for example, 'true', 1). You can read more about .NET Core tools telemetry at https://aka.ms/dotnet-cli-telemetry."
su - $SUDO_USER -c "dotnet new > /dev/null 2>&1 || true"
dotnet new > /dev/null 2>&1 || true

View file

@ -11,8 +11,7 @@ INSTALL_DESTINATION=$2
# A temporary fix for the permissions issue(s)
chmod -R 755 $INSTALL_DESTINATION
# Run 'dotnet new' as user to trigger the first time experience to initialize the cache
INSTALLER_USER=$(stat -f '%Su' $HOME)
su - $INSTALLER_USER -c "$INSTALL_DESTINATION/dotnet new > /dev/null 2>&1 || true"
# Run 'dotnet new' to trigger the first time experience to initialize the cache
$INSTALL_DESTINATION/dotnet new > /dev/null 2>&1 || true
exit 0

View file

@ -19,4 +19,4 @@ The data collected is anonymous and will be published in an aggregated form for
The .NET Core Tools telemetry feature is enabled by default. You can opt-out of the telemetry feature by setting an environment variable DOTNET_CLI_TELEMETRY_OPTOUT (for example, 'export' on macOS/Linux, 'set' on Windows) to true (for example, 'true', 1). You can read more about .NET Core tools telemetry at https://aka.ms/dotnet-cli-telemetry."
su - $SUDO_USER -c "dotnet new > /dev/null 2>&1 || true"
dotnet new > /dev/null 2>&1 || true

View file

@ -12,14 +12,18 @@ namespace Microsoft.DotNet.Configurer
{
public class CliFallbackFolderPathCalculator
{
public string CliFallbackFolderPath
public string CliFallbackFolderPath =>
Environment.GetEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER") ??
Path.Combine(new DirectoryInfo(AppContext.BaseDirectory).Parent.FullName, "NuGetFallbackFolder");
public string DotnetUserProfileFolderPath
{
get
{
string profileDir = Environment.GetEnvironmentVariable(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "USERPROFILE" : "HOME");
return Path.Combine(profileDir, ".dotnet", "NuGetFallbackFolder");
return Path.Combine(profileDir, ".dotnet");
}
}

View file

@ -14,19 +14,22 @@ namespace Microsoft.DotNet.Configurer
private INuGetCachePrimer _nugetCachePrimer;
private INuGetCacheSentinel _nugetCacheSentinel;
private IFirstTimeUseNoticeSentinel _firstTimeUseNoticeSentinel;
private string _cliFallbackFolderPath;
public DotnetFirstTimeUseConfigurer(
INuGetCachePrimer nugetCachePrimer,
INuGetCacheSentinel nugetCacheSentinel,
IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
IEnvironmentProvider environmentProvider,
IReporter reporter)
IReporter reporter,
string cliFallbackFolderPath)
{
_nugetCachePrimer = nugetCachePrimer;
_nugetCacheSentinel = nugetCacheSentinel;
_firstTimeUseNoticeSentinel = firstTimeUseNoticeSentinel;
_environmentProvider = environmentProvider;
_reporter = reporter;
_cliFallbackFolderPath = cliFallbackFolderPath;
}
public void Configure()
@ -38,7 +41,13 @@ namespace Microsoft.DotNet.Configurer
if (ShouldPrimeNugetCache())
{
if (_nugetCacheSentinel.UnauthorizedAccess)
{
PrintUnauthorizedAccessMessage();
}
PrintNugetCachePrimeMessage();
_nugetCachePrimer.PrimeCache();
}
}
@ -55,14 +64,20 @@ namespace Microsoft.DotNet.Configurer
private void PrintFirstTimeUseNotice()
{
string firstTimeUseWelcomeMessage = LocalizableStrings.FirstTimeWelcomeMessage;
_reporter.WriteLine();
_reporter.WriteLine(firstTimeUseWelcomeMessage);
_reporter.WriteLine(LocalizableStrings.FirstTimeWelcomeMessage);
_firstTimeUseNoticeSentinel.CreateIfNotExists();
}
private void PrintUnauthorizedAccessMessage()
{
_reporter.WriteLine();
_reporter.WriteLine(string.Format(
LocalizableStrings.UnauthorizedAccessMessage,
_cliFallbackFolderPath));
}
private bool ShouldPrimeNugetCache()
{
return ShouldRunFirstRunExperience() &&

View file

@ -14,19 +14,19 @@ namespace Microsoft.DotNet.Configurer
private readonly IFile _file;
private string _nugetCachePath;
private string _dotnetUserProfileFolderPath;
private string SentinelPath => Path.Combine(_nugetCachePath, SENTINEL);
private string SentinelPath => Path.Combine(_dotnetUserProfileFolderPath, SENTINEL);
public FirstTimeUseNoticeSentinel(CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator) :
this(cliFallbackFolderPathCalculator.CliFallbackFolderPath, FileSystemWrapper.Default.File)
this(cliFallbackFolderPathCalculator.DotnetUserProfileFolderPath, FileSystemWrapper.Default.File)
{
}
internal FirstTimeUseNoticeSentinel(string nugetCachePath, IFile file)
internal FirstTimeUseNoticeSentinel(string dotnetUserProfileFolderPath, IFile file)
{
_file = file;
_nugetCachePath = nugetCachePath;
_dotnetUserProfileFolderPath = dotnetUserProfileFolderPath;
}
public bool Exists()

View file

@ -12,5 +12,7 @@ namespace Microsoft.DotNet.Configurer
bool Exists();
void CreateIfNotExists();
bool UnauthorizedAccess { get; }
}
}

View file

@ -1,10 +0,0 @@
// 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.
namespace Microsoft.DotNet.Configurer
{
public interface INuGetConfig
{
void AddCliFallbackFolder(string fallbackFolderPath);
}
}

View file

@ -136,4 +136,14 @@ A command is running to initially populate your local package cache, to improve
<data name="FailedToPrimeCacheError" xml:space="preserve">
<value>Failed to prime the NuGet cache. {0} failed with: {1}</value>
</data>
<data name="UnauthorizedAccessMessage" xml:space="preserve">
<value>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</value>
</data>
</root>

View file

@ -17,18 +17,14 @@ namespace Microsoft.DotNet.Configurer
private readonly INuGetCacheSentinel _nuGetCacheSentinel;
private readonly INuGetConfig _nuGetConfig;
private readonly CliFallbackFolderPathCalculator _cliFallbackFolderPathCalculator;
public NuGetCachePrimer(
INuGetPackagesArchiver nugetPackagesArchiver,
INuGetCacheSentinel nuGetCacheSentinel,
INuGetConfig nuGetConfig,
CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
: this(nugetPackagesArchiver,
nuGetCacheSentinel,
nuGetConfig,
cliFallbackFolderPathCalculator,
FileSystemWrapper.Default.File)
{
@ -37,7 +33,6 @@ namespace Microsoft.DotNet.Configurer
internal NuGetCachePrimer(
INuGetPackagesArchiver nugetPackagesArchiver,
INuGetCacheSentinel nuGetCacheSentinel,
INuGetConfig nuGetConfig,
CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator,
IFile file)
{
@ -45,8 +40,6 @@ namespace Microsoft.DotNet.Configurer
_nuGetCacheSentinel = nuGetCacheSentinel;
_nuGetConfig = nuGetConfig;
_cliFallbackFolderPathCalculator = cliFallbackFolderPathCalculator;
_file = file;
@ -61,8 +54,6 @@ namespace Microsoft.DotNet.Configurer
var nuGetFallbackFolder = _cliFallbackFolderPathCalculator.CliFallbackFolderPath;
_nuGetConfig.AddCliFallbackFolder(nuGetFallbackFolder);
_nugetPackagesArchiver.ExtractArchive(nuGetFallbackFolder);
_nuGetCacheSentinel.CreateIfNotExists();

View file

@ -1,6 +1,7 @@
// 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 System;
using System.IO;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.EnvironmentAbstractions;
@ -13,8 +14,12 @@ namespace Microsoft.DotNet.Configurer
public static readonly string SENTINEL = $"{Product.Version}.dotnetSentinel";
public static readonly string INPROGRESS_SENTINEL = $"{Product.Version}.inprogress.dotnetSentinel";
public bool UnauthorizedAccess { get; private set; }
private readonly IFile _file;
private readonly IDirectory _directory;
private string _nugetCachePath;
private string SentinelPath => Path.Combine(_nugetCachePath, SENTINEL);
@ -23,14 +28,17 @@ namespace Microsoft.DotNet.Configurer
private Stream InProgressSentinel { get; set; }
public NuGetCacheSentinel(CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator) :
this(cliFallbackFolderPathCalculator.CliFallbackFolderPath, FileSystemWrapper.Default.File)
this(cliFallbackFolderPathCalculator.CliFallbackFolderPath,
FileSystemWrapper.Default.File,
FileSystemWrapper.Default.Directory)
{
}
internal NuGetCacheSentinel(string nugetCachePath, IFile file)
internal NuGetCacheSentinel(string nugetCachePath, IFile file, IDirectory directory)
{
_file = file;
_nugetCachePath = nugetCachePath;
_file = file;
_directory = directory;
SetInProgressSentinel();
}
@ -62,9 +70,9 @@ namespace Microsoft.DotNet.Configurer
{
try
{
if (!Directory.Exists(_nugetCachePath))
if (!_directory.Exists(_nugetCachePath))
{
Directory.CreateDirectory(_nugetCachePath);
_directory.CreateDirectory(_nugetCachePath);
}
// open an exclusive handle to the in-progress sentinel and mark it for delete on close.
@ -80,6 +88,10 @@ namespace Microsoft.DotNet.Configurer
1,
FileOptions.DeleteOnClose);
}
catch (UnauthorizedAccessException)
{
UnauthorizedAccess = true;
}
catch { }
}

View file

@ -1,39 +0,0 @@
// 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 NuGet.Common;
using NuGet.Configuration;
using System.Linq;
namespace Microsoft.DotNet.Configurer
{
public class NuGetConfig : INuGetConfig
{
public const string FallbackPackageFolders = "packageSources";
private ISettings _settings;
public NuGetConfig(CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
{
_settings = new Settings(cliFallbackFolderPathCalculator.NuGetUserSettingsDirectory);
}
internal NuGetConfig(ISettings settings)
{
_settings = settings;
}
public void AddCliFallbackFolder(string fallbackFolderPath)
{
if (!IsCliFallbackFolderSet(fallbackFolderPath))
{
_settings.SetValue(FallbackPackageFolders, "CliFallbackFolder", fallbackFolderPath);
}
}
private bool IsCliFallbackFolderSet(string fallbackFolderPath)
{
return _settings.GetSettingValues(FallbackPackageFolders).Any(s => s.Value == fallbackFolderPath);
}
}
}

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -25,4 +25,4 @@ A command is running to initially populate your local package cache, to improve
</trans-unit>
</body>
</file>
</xliff>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -41,6 +41,25 @@ A command is running to initially populate your local package cache, to improve
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.</target>
<note />
</trans-unit>
<trans-unit id="UnauthorizedAccessMessage">
<source>Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</source>
<target state="new">Permission denied to modify the '{0}' folder.
Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

View file

@ -42,5 +42,10 @@ namespace Microsoft.Extensions.EnvironmentAbstractions
return directoryFullName;
}
public void CreateDirectory(string path)
{
Directory.CreateDirectory(path);
}
}
}

View file

@ -14,5 +14,7 @@ namespace Microsoft.Extensions.EnvironmentAbstractions
IEnumerable<string> GetFiles(string path, string searchPattern);
string GetDirectoryFullName(string path);
void CreateDirectory(string path);
}
}

View file

@ -128,7 +128,7 @@ namespace Microsoft.DotNet.Cli
if (telemetryClient == null)
{
telemetryClient = new Telemetry(nugetCacheSentinel);
telemetryClient = new Telemetry(firstTimeUseNoticeSentinel);
}
}
@ -177,18 +177,17 @@ namespace Microsoft.DotNet.Cli
var nugetPackagesArchiver = new NuGetPackagesArchiver();
var environmentProvider = new EnvironmentProvider();
var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true);
var nugetConfig = new NuGetConfig(cliFallbackFolderPathCalculator);
var nugetCachePrimer = new NuGetCachePrimer(
nugetPackagesArchiver,
nugetCacheSentinel,
nugetConfig,
cliFallbackFolderPathCalculator);
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
nugetCachePrimer,
nugetCacheSentinel,
firstTimeUseNoticeSentinel,
environmentProvider,
Reporter.Output);
Reporter.Output,
cliFallbackFolderPathCalculator.CliFallbackFolderPath);
dotnetConfigurer.Configure();
}

View file

@ -35,9 +35,9 @@ namespace Microsoft.DotNet.Cli
public Telemetry () : this(null) { }
public Telemetry(INuGetCacheSentinel sentinel) : this(sentinel, null) { }
public Telemetry(IFirstTimeUseNoticeSentinel sentinel) : this(sentinel, null) { }
public Telemetry(INuGetCacheSentinel sentinel, string sessionId)
public Telemetry(IFirstTimeUseNoticeSentinel sentinel, string sessionId)
{
Enabled = !Env.GetEnvironmentVariableAsBool(TelemetryOptout) && PermissionExists(sentinel);
@ -53,7 +53,7 @@ namespace Microsoft.DotNet.Cli
_trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry());
}
private bool PermissionExists(INuGetCacheSentinel sentinel)
private bool PermissionExists(IFirstTimeUseNoticeSentinel sentinel)
{
if (sentinel == null)
{

View file

@ -11,7 +11,8 @@ namespace Microsoft.DotNet.Tools.MSBuild
{
public sealed class MSBuildLogger : Logger
{
private readonly INuGetCacheSentinel _sentinel = new NuGetCacheSentinel(new CliFallbackFolderPathCalculator());
private readonly IFirstTimeUseNoticeSentinel _sentinel =
new FirstTimeUseNoticeSentinel(new CliFallbackFolderPathCalculator());
private readonly ITelemetry _telemetry;
public MSBuildLogger()

View file

@ -28,8 +28,10 @@ namespace Microsoft.DotNet.Tools.New
public static int Run(string[] args)
{
var sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
var telemetry = new Telemetry(new NuGetCacheSentinel(new CliFallbackFolderPathCalculator()), sessionId);
var sessionId =
Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
var telemetry =
new Telemetry(new FirstTimeUseNoticeSentinel(new CliFallbackFolderPathCalculator()), sessionId);
var logger = new TelemetryLogger(null);
if (telemetry.Enabled)

View file

@ -13,6 +13,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
{
public class GivenADotnetFirstTimeUseConfigurer
{
private const string CliFallbackFolderPath = "some path";
private Mock<INuGetCachePrimer> _nugetCachePrimerMock;
private Mock<INuGetCacheSentinel> _nugetCacheSentinelMock;
private Mock<IFirstTimeUseNoticeSentinel> _firstTimeUseNoticeSentinelMock;
@ -45,7 +47,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -66,7 +69,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -87,7 +91,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -105,7 +110,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -123,7 +129,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -140,7 +147,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -157,7 +165,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -177,7 +186,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -194,7 +204,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();
@ -212,7 +223,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinelMock.Object,
_firstTimeUseNoticeSentinelMock.Object,
_environmentProviderMock.Object,
_reporterMock.Object);
_reporterMock.Object,
CliFallbackFolderPath);
dotnetFirstTimeUseConfigurer.Configure();

View file

@ -26,7 +26,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
private Mock<INuGetPackagesArchiver> _nugetPackagesArchiverMock;
private Mock<INuGetCacheSentinel> _nugetCacheSentinel;
private Mock<INuGetConfig> _nugetConfigMock;
private CliFallbackFolderPathCalculator _cliFallbackFolderPathCalculator;
public GivenANuGetCachePrimer()
@ -41,14 +40,11 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinel = new Mock<INuGetCacheSentinel>();
_nugetConfigMock = new Mock<INuGetConfig>();
_cliFallbackFolderPathCalculator = new CliFallbackFolderPathCalculator();
var nugetCachePrimer = new NuGetCachePrimer(
_nugetPackagesArchiverMock.Object,
_nugetCacheSentinel.Object,
_nugetConfigMock.Object,
_cliFallbackFolderPathCalculator,
_fileSystemMock.File);
@ -67,7 +63,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
var nugetCachePrimer = new NuGetCachePrimer(
nugetPackagesArchiverMock.Object,
_nugetCacheSentinel.Object,
_nugetConfigMock.Object,
_cliFallbackFolderPathCalculator,
fileSystemMock.File);
@ -76,14 +71,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
nugetPackagesArchiverMock.Verify(n => n.ExtractArchive(It.IsAny<string>()), Times.Never);
}
[Fact]
public void It_adds_the_fallback_folder_to_NuGet_Config()
{
_nugetConfigMock.Verify(n =>
n.AddCliFallbackFolder(_cliFallbackFolderPathCalculator.CliFallbackFolderPath),
Times.Exactly(1));
}
[Fact]
public void It_extracts_the_archive_to_the_fallback_folder()
{
@ -108,7 +95,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
var nugetCachePrimer = new NuGetCachePrimer(
nugetPackagesArchiveMock.Object,
nugetCacheSentinel.Object,
_nugetConfigMock.Object,
_cliFallbackFolderPathCalculator,
_fileSystemMock.File);

View file

@ -2,12 +2,14 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
using Microsoft.Extensions.DependencyModel.Tests;
using Microsoft.Extensions.EnvironmentAbstractions;
using Moq;
using Xunit;
namespace Microsoft.DotNet.Configurer.UnitTests
@ -26,18 +28,44 @@ namespace Microsoft.DotNet.Configurer.UnitTests
[Fact]
public void As_soon_as_it_gets_created_it_tries_to_get_handle_of_the_InProgress_sentinel()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var fileMock = new FileMock();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory);
fileMock.OpenFileWithRightParamsCalled.Should().BeTrue();
}
[Fact]
public void It_returns_true_to_the_in_progress_sentinel_already_exists_when_it_fails_to_get_a_handle_to_it()
public void It_sets_UnauthorizedAccess_to_false_when_no_UnauthorizedAccessException_happens()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var fileMock = new FileMock();
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory);
nugetCacheSentinel.UnauthorizedAccess.Should().BeFalse();
}
[Fact]
public void It_sets_UnauthorizedAccess_to_true_when_an_UnauthorizedAccessException_happens()
{
var fileMock = new FileMock();
var directoryMock = new DirectoryMock();
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, directoryMock);
nugetCacheSentinel.UnauthorizedAccess.Should().BeTrue();
}
[Fact]
public void It_returns_true_to_the_in_progress_sentinel_already_exists_when_it_fails_to_get_a_handle_to_it()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var fileMock = new FileMock();
fileMock.InProgressSentinel = null;
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory);
nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeTrue();
}
@ -45,9 +73,11 @@ namespace Microsoft.DotNet.Configurer.UnitTests
[Fact]
public void It_returns_false_to_the_in_progress_sentinel_already_exists_when_it_succeeds_in_getting_a_handle_to_it()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var fileMock = new FileMock();
fileMock.InProgressSentinel = new MemoryStream();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory);
nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeFalse();
}
@ -55,10 +85,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests
[Fact]
public void It_disposes_of_the_handle_to_the_InProgressSentinel_when_NuGetCacheSentinel_is_disposed()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var mockStream = new MockStream();
var fileMock = new FileMock();
fileMock.InProgressSentinel = mockStream;
using (var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock))
using (var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory))
{}
mockStream.IsDisposed.Should().BeTrue();
@ -77,7 +109,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
var fileSystemMock = _fileSystemMockBuilder.Build();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File, fileSystemMock.Directory);
nugetCacheSentinel.Exists().Should().BeTrue();
}
@ -87,7 +120,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File, fileSystemMock.Directory);
nugetCacheSentinel.Exists().Should().BeFalse();
}
@ -96,7 +130,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
public void It_creates_the_sentinel_in_the_nuget_cache_path_if_it_does_not_exist_already()
{
var fileSystemMock = _fileSystemMockBuilder.Build();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File, fileSystemMock.Directory);
nugetCacheSentinel.Exists().Should().BeFalse();
@ -114,7 +149,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
var fileSystemMock = _fileSystemMockBuilder.Build();
var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);
var nugetCacheSentinel =
new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File, fileSystemMock.Directory);
nugetCacheSentinel.Exists().Should().BeTrue();
@ -123,6 +159,34 @@ namespace Microsoft.DotNet.Configurer.UnitTests
fileSystemMock.File.ReadAllText(sentinel).Should().Be(contentToValidateSentinalWasNotReplaced);
}
private class DirectoryMock : IDirectory
{
public bool Exists(string path)
{
return false;
}
public ITemporaryDirectory CreateTemporaryDirectory()
{
throw new NotImplementedException();
}
public IEnumerable<string> GetFiles(string path, string searchPattern)
{
throw new NotImplementedException();
}
public string GetDirectoryFullName(string path)
{
throw new NotImplementedException();
}
public void CreateDirectory(string path)
{
throw new UnauthorizedAccessException();
}
}
private class FileMock : IFile
{
public bool OpenFileWithRightParamsCalled { get; private set; }

View file

@ -1,53 +0,0 @@
// 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 System.Collections.Generic;
using FluentAssertions;
using Moq;
using NuGet.Configuration;
using Xunit;
namespace Microsoft.DotNet.Configurer.UnitTests
{
public class GivenANuGetConfig
{
private const string PathToFallbackFolderAlreadySet = "some path to fallback folder";
private Mock<ISettings> _settingsMock;
private INuGetConfig _nugetConfig;
public GivenANuGetConfig()
{
_settingsMock = new Mock<ISettings>();
_settingsMock
.Setup(s => s.GetSettingValues(NuGetConfig.FallbackPackageFolders, false))
.Returns(new List<SettingValue>()
{
new SettingValue("CliFallbackFolder", PathToFallbackFolderAlreadySet, false)
});
_nugetConfig = new NuGetConfig(_settingsMock.Object);
}
[Fact]
public void ItAddsACliFallbackFolderIfOneIsNotPresentAlready()
{
const string FallbackFolderNotAlreadySet = "some path not already set";
_nugetConfig.AddCliFallbackFolder(FallbackFolderNotAlreadySet);
_settingsMock.Verify(s =>
s.SetValue(NuGetConfig.FallbackPackageFolders, "CliFallbackFolder", FallbackFolderNotAlreadySet),
Times.Exactly(1));
}
[Fact]
public void ItDoesNotAddTheCliFallbackFolderIfItIsAlreadyPresent()
{
_nugetConfig.AddCliFallbackFolder(PathToFallbackFolderAlreadySet);
_settingsMock.Verify(s =>
s.SetValue(NuGetConfig.FallbackPackageFolders, "CliFallbackFolder", PathToFallbackFolderAlreadySet),
Times.Never);
}
}
}

View file

@ -138,6 +138,11 @@ namespace Microsoft.Extensions.DependencyModel.Tests
{
return _files.Keys.Any(k => k.StartsWith(path));
}
public void CreateDirectory(string path)
{
_files.Add(path, path);
}
}
private class TemporaryDirectoryMock : ITemporaryDirectoryMock

View file

@ -109,7 +109,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
result.Should().Fail();
result.StdOut.Should().ContainVisuallySameFragment(@"source(s): /usr/local/bin, nuget.org");
result.StdOut.Should().ContainVisuallySameFragment("NU1101");
}
[Fact]
@ -186,14 +186,17 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
}
}
public sealed class MockNuGetCacheSentinel : INuGetCacheSentinel
public sealed class MockNuGetCacheSentinel : IFirstTimeUseNoticeSentinel
{
private readonly Func<bool> _exists;
public bool UnauthorizedAccess => true;
public MockNuGetCacheSentinel(Func<bool> exists = null)
{
_exists = exists ?? (() => true);
}
public void Dispose()
{
}

View file

@ -25,19 +25,21 @@ namespace Microsoft.DotNet.Tests
{
var testDirectory = TestAssets.CreateTestDirectory("Dotnet_first_time_experience_tests");
var testNuGetHome = Path.Combine(testDirectory.FullName, "nuget_home");
var cliTestFallbackFolder = Path.Combine(testNuGetHome, ".dotnet", "NuGetFallbackFolder");
var command = new DotnetCommand()
.WithWorkingDirectory(testDirectory);
command.Environment["HOME"] = testNuGetHome;
command.Environment["USERPROFILE"] = testNuGetHome;
command.Environment["APPDATA"] = testNuGetHome;
command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = cliTestFallbackFolder;
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
command.Environment["SkipInvalidConfigurations"] = "true";
_firstDotnetNonVerbUseCommandResult = command.ExecuteWithCapturedOutput("--info");
_firstDotnetVerbUseCommandResult = command.ExecuteWithCapturedOutput("new --debug:ephemeral-hive");
_nugetFallbackFolder = new DirectoryInfo(Path.Combine(testNuGetHome, ".dotnet", "NuGetFallbackFolder"));
_nugetFallbackFolder = new DirectoryInfo(cliTestFallbackFolder);
}
[Fact]