예제 #1
0
        /// <summary>
        /// Installs function app dependencies specified in functionAppRoot\requirements.psd1.
        /// </summary>
        internal void InstallFunctionAppDependencies(PowerShell pwsh, ILogger logger)
        {
            try
            {
                // Install the function dependencies.
                logger.Log(LogLevel.Trace, PowerShellWorkerStrings.InstallingFunctionAppDependentModules, isUserLog: true);

                if (Directory.Exists(DependenciesPath))
                {
                    // Save-Module supports downloading side-by-size module versions. However, we only want to keep one version at the time.
                    // If the ManagedDependencies folder exits, remove all its contents.
                    DependencyManagementUtils.EmptyDirectory(DependenciesPath);
                }
                else
                {
                    // If the destination path does not exist, create it.
                    Directory.CreateDirectory(DependenciesPath);
                }

                try
                {
                    foreach (DependencyInfo module in Dependencies)
                    {
                        string moduleName    = module.Name;
                        string latestVersion = module.LatestVersion;

                        // Save the module to the given path
                        pwsh.AddCommand("PowerShellGet\\Save-Module")
                        .AddParameter("Repository", Repository)
                        .AddParameter("Name", moduleName)
                        .AddParameter("RequiredVersion", latestVersion)
                        .AddParameter("Path", DependenciesPath)
                        .AddParameter("Force", true)
                        .AddParameter("ErrorAction", "Stop")
                        .InvokeAndClearCommands();

                        var message = string.Format(PowerShellWorkerStrings.ModuleHasBeenInstalled, moduleName, latestVersion);
                        logger.Log(LogLevel.Trace, message, isUserLog: true);
                    }
                }
                finally
                {
                    // Clean up
                    pwsh.AddCommand(Utils.RemoveModuleCmdletInfo)
                    .AddParameter("Name", "PackageManagement, PowerShellGet")
                    .AddParameter("Force", true)
                    .AddParameter("ErrorAction", "SilentlyContinue")
                    .InvokeAndClearCommands();
                }
            }
            catch (Exception e)
            {
                var errorMsg = string.Format(PowerShellWorkerStrings.FailToInstallFuncAppDependencies, e.Message);
                _dependencyError = new DependencyInstallationException(errorMsg, e);
            }
        }
 /// <summary>
 /// Sets/prepares the destination path where the function app dependencies will be installed.
 /// </summary>
 internal void SetDependenciesDestinationPath(string path)
 {
     // Save-Module supports downloading side-by-size module versions. However, we only want to keep one version at the time.
     // If the ManagedDependencies folder exits, remove all its contents.
     if (Directory.Exists(path))
     {
         DependencyManagementUtils.EmptyDirectory(path);
     }
     else
     {
         // If the destination path does not exist, create it.
         // If the user does not have write access to the path, an exception will be raised.
         try
         {
             Directory.CreateDirectory(path);
         }
         catch (Exception e)
         {
             var errorMsg = string.Format(PowerShellWorkerStrings.FailToCreateFunctionAppDependenciesDestinationPath, path, e.Message);
             throw new InvalidOperationException(errorMsg);
         }
     }
 }