示例#1
0
        public static string GetFolderPath(DnuFolderPath folder)
        {
            switch (folder)
            {
            case DnuFolderPath.MachineWideSettingsBaseDirectory:
                var appData = string.Empty;
                if (RuntimeEnvironmentHelper.IsWindows)
                {
                    appData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                }
                else
                {
                    // Only super users have write access to common app data folder on *nix,
                    // so we use roaming local app data folder instead
                    appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                }
                return(Path.Combine(appData, "NuGet"));

            case DnuFolderPath.MachineWideConfigDirectory:
                return(Path.Combine(GetFolderPath(DnuFolderPath.MachineWideSettingsBaseDirectory),
                                    "Config"));

            case DnuFolderPath.UserSettingsDirectory:
                return(Path.Combine(
                           Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                           "NuGet"));

            case DnuFolderPath.DefaultDnxHome:
                var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                return(Path.Combine(userProfile, Constants.DefaultLocalRuntimeHomeDir));

            case DnuFolderPath.DnxHome:
                var runtimeHome = Environment.GetEnvironmentVariable(EnvironmentNames.Home);
                if (string.IsNullOrEmpty(runtimeHome))
                {
                    runtimeHome = GetFolderPath(DnuFolderPath.DefaultDnxHome);
                }
                return(runtimeHome);

            case DnuFolderPath.HttpCacheDirectory:
                var localAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                return(Path.Combine(localAppDataFolder, "dnu", "cache"));

            case DnuFolderPath.DnxGlobalPath:
                return(Environment.GetEnvironmentVariable(EnvironmentNames.GlobalPath));

            case DnuFolderPath.DefaultMsBuildPath:
                var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
                if (string.IsNullOrEmpty(programFilesPath))
                {
                    // On 32-bit Windows
                    programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                }
                return(Path.Combine(programFilesPath, "MSBuild", "14.0", "Bin", "MSBuild.exe"));

            default:
                return(null);
            }
        }
示例#2
0
 public static string GetFolderPath(DnuFolderPath folder)
 {
     switch (folder)
     {
         case DnuFolderPath.MachineWideSettingsBaseDirectory:
             var appData = string.Empty;
             if (RuntimeEnvironmentHelper.IsWindows)
             {
                 appData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
             }
             else
             {
                 // Only super users have write access to common app data folder on *nix,
                 // so we use roaming local app data folder instead
                 appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
             }
             return Path.Combine(appData, "NuGet");
         case DnuFolderPath.MachineWideConfigDirectory:
             return Path.Combine(GetFolderPath(DnuFolderPath.MachineWideSettingsBaseDirectory),
                 "Config");
         case DnuFolderPath.UserSettingsDirectory:
             return Path.Combine(
                 Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                 "NuGet");
         case DnuFolderPath.DefaultDnxHome:
             var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
             return Path.Combine(userProfile, Constants.DefaultLocalRuntimeHomeDir);
         case DnuFolderPath.DnxHome:
             var runtimeHome = Environment.GetEnvironmentVariable(EnvironmentNames.Home);
             if (string.IsNullOrEmpty(runtimeHome))
             {
                 runtimeHome = GetFolderPath(DnuFolderPath.DefaultDnxHome);
             }
             return runtimeHome;
         case DnuFolderPath.HttpCacheDirectory:
             var localAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
             return Path.Combine(localAppDataFolder, "dnu", "cache");
         case DnuFolderPath.DnxGlobalPath:
             return Environment.GetEnvironmentVariable(EnvironmentNames.GlobalPath);
         case DnuFolderPath.DefaultMsBuildPath:
             var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
             if (string.IsNullOrEmpty(programFilesPath))
             {
                 // On 32-bit Windows
                 programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
             }
             return Path.Combine(programFilesPath, "MSBuild", "14.0", "Bin", "MSBuild.exe");
         default:
             return null;
     }
 }