Fix failure to add tools path on restricted Windows environments.

On environments where registry access is disabled, the first run experience
fails because it could not add the tools path to the user's environment.

This fix properly handles the security exception by printing a warning and
continuing.  Users will have to manually add the PATH environment variable to
their environments to prevent `dotnet tool install` from printing PATH
instructions.

A new file sentinel is added to track whether or not the PATH has been
modified.  The first run experience also now correctly skips modifying the PATH
if `DOTNET_SKIP_FIRST_TIME_EXPERIENCE` is set.

Fixes #8874.
This commit is contained in:
Peter Huene 2018-03-23 12:40:58 -07:00
parent d3f69e2e01
commit 19090744cb
No known key found for this signature in database
GPG key ID: E1D265D820213D6A
31 changed files with 746 additions and 328 deletions

View file

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
@ -23,6 +24,8 @@ namespace Microsoft.DotNet.Cli
{
public class Program
{
private static readonly string ToolPathSentinelFileName = $"{Product.Version}.toolpath.sentinel";
public static int Main(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
@ -94,6 +97,12 @@ namespace Microsoft.DotNet.Cli
{
IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel;
IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel(cliFallbackFolderPathCalculator);
IFileSentinel toolPathSentinel = new FileSentinel(
new FilePath(
Path.Combine(
CliFolderPathCalculator.DotnetUserProfileFolderPath,
ToolPathSentinelFileName)));
for (; lastArg < args.Length; lastArg++)
{
if (IsArg(args[lastArg], "d", "diagnostics"))
@ -138,6 +147,7 @@ namespace Microsoft.DotNet.Cli
{
aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel();
firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel();
toolPathSentinel = new NoOpFileSentinel();
hasSuperUserAccess = true;
}
@ -145,6 +155,7 @@ namespace Microsoft.DotNet.Cli
nugetCacheSentinel,
firstTimeUseNoticeSentinel,
aspNetCertificateSentinel,
toolPathSentinel,
cliFallbackFolderPathCalculator,
hasSuperUserAccess);
@ -209,6 +220,7 @@ namespace Microsoft.DotNet.Cli
INuGetCacheSentinel nugetCacheSentinel,
IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
IAspNetCertificateSentinel aspNetCertificateSentinel,
IFileSentinel toolPathSentinel,
CliFolderPathCalculator cliFolderPathCalculator,
bool hasSuperUserAccess)
{
@ -231,6 +243,7 @@ namespace Microsoft.DotNet.Cli
firstTimeUseNoticeSentinel,
aspNetCertificateSentinel,
aspnetCertificateGenerator,
toolPathSentinel,
environmentProvider,
Reporter.Output,
cliFolderPathCalculator.CliFallbackFolderPath,