private bool NeedsExtensionsInstall() { string warningMessage = "No action performed because no functions in your app require extensions."; // CASE 1: If users need a package to be installed if (!string.IsNullOrEmpty(Package) || !string.IsNullOrEmpty(Version)) { return(true); } // CASE 2: If there are any bindings that need to install extensions if (ExtensionsHelper.GetExtensionPackages().Count() > 0) { return(true); } var extensionsProjDir = string.IsNullOrEmpty(ConfigPath) ? Environment.CurrentDirectory : ConfigPath; var extensionsProjFile = Path.Combine(extensionsProjDir, Constants.ExtenstionsCsProjFile); // CASE 3: No extensions.csproj if (!FileSystemHelpers.FileExists(extensionsProjFile)) { if (_showNoActionWarning) { ColoredConsole.WriteLine(WarningColor(warningMessage)); } return(false); } // CASE 4: extensions.csproj present with only ExtensionsMetaDataGenerator in it // We look for this special case because we had added ExtensionsMetaDataGenerator to all function apps. // These apps do not need to do a restore, so if only ExtensionsMetaDataGenerator is present, we don't need to continue var extensionsProject = ProjectHelpers.GetProject(extensionsProjFile); var extensionsInProject = extensionsProject.Items .Where(item => item.ItemType.Equals(Constants.PackageReferenceElementName, StringComparison.OrdinalIgnoreCase)) .ToList(); if (extensionsInProject.Count == 1 && extensionsInProject.FirstOrDefault(item => item.Include.Equals(Constants.ExtensionsMetadataGeneratorPackage.Name, StringComparison.OrdinalIgnoreCase)) != null) { if (_showNoActionWarning) { ColoredConsole.WriteLine(WarningColor(warningMessage)); } if (StaticSettings.IsDebug) { ColoredConsole.WriteLine(VerboseColor($"InstallExtensionAction: No action performed because only {Constants.ExtensionsMetadataGeneratorPackage.Name} reference was found." + $" This extension package does not require and extension install by itself." + $" No other required extensions were found.")); } return(false); } return(true); }
public async override Task RunAsync() { if (CommandChecker.CommandExists("dotnet")) { if (!string.IsNullOrEmpty(ConfigPath) && !FileSystemHelpers.DirectoryExists(ConfigPath)) { throw new CliArgumentsException("Invalid config path, please verify directory exists"); } var extensionsProj = await ExtensionsHelper.EnsureExtensionsProjectExistsAsync(_secretsManager, Csx, ConfigPath); if (string.IsNullOrEmpty(Package) && string.IsNullOrEmpty(Version)) { var project = ProjectHelpers.GetProject(extensionsProj); foreach (var extensionPackage in ExtensionsHelper.GetExtensionPackages()) { // Only add / update package referece if it does not exist or forced update is enabled if (!ProjectHelpers.PackageReferenceExists(project, extensionPackage.Name) || Force) { await AddPackage(extensionsProj, extensionPackage.Name, extensionPackage.Version); } } } else if (!string.IsNullOrEmpty(Package) && !string.IsNullOrEmpty(Version)) { await AddPackage(extensionsProj, Package, Version); } else { throw new CliArgumentsException("Must specify extension package name and version", new CliArgument { Name = nameof(Package), Description = "Extension package name" }, new CliArgument { Name = nameof(Version), Description = "Extension package version" } ); } var syncAction = new SyncExtensionsAction(_secretsManager) { OutputPath = OutputPath, ConfigPath = ConfigPath }; await syncAction.RunAsync(); } else { ColoredConsole.Error.WriteLine(ErrorColor(Constants.Errors.ExtensionsNeedDotnet)); } }
private string GetOutputFileName() { if (!string.IsNullOrEmpty(_outputFile)) { return(_outputFile); } IVsSolution solution = WebEssentialsPackage.GetGlobalService <IVsSolution>(typeof(SVsSolution)); Project project = ProjectHelpers.GetProject(SourceFilePath); IVsHierarchy hierarchy = null; if (project != null && solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy) != VSConstants.S_OK) { return(string.Empty); } IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage == null) { _outputFile = Path.ChangeExtension(SourceFilePath, ".js"); } else { string outputFile, outputDir; string config = WebEssentialsPackage.DTE.Solution.SolutionBuild.ActiveConfiguration.Name; int resultFile = buildPropertyStorage.GetPropertyValue("TypeScriptOutFile", config, (uint)_PersistStorageType.PST_PROJECT_FILE, out outputFile); int resultDir = buildPropertyStorage.GetPropertyValue("TypeScriptOutDir", config, (uint)_PersistStorageType.PST_PROJECT_FILE, out outputDir); if (!string.IsNullOrEmpty(outputFile) && resultFile == VSConstants.S_OK) { _outputFile = Path.Combine(ProjectHelpers.GetRootFolder(project), outputFile); } else if (!string.IsNullOrEmpty(outputDir) && resultDir == VSConstants.S_OK) { string dir = Path.Combine(ProjectHelpers.GetRootFolder(project), outputDir); string file = Path.ChangeExtension(Path.GetFileName(SourceFilePath), ".js"); _outputFile = Path.Combine(dir, file); } } if (string.IsNullOrEmpty(_outputFile)) { _outputFile = Path.ChangeExtension(SourceFilePath, ".js"); } return(_outputFile); }
private string GetOutputFileName() { if (!string.IsNullOrEmpty(_outputFile)) { return(_outputFile); } IVsSolution solution = EditorExtensionsPackage.GetGlobalService <IVsSolution>(typeof(SVsSolution)); Project project = ProjectHelpers.GetProject(SourceFilePath); IVsHierarchy hierarchy; ErrorHandler.ThrowOnFailure(solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy)); IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage == null) { _outputFile = Path.ChangeExtension(SourceFilePath, ".js"); } else { string outputFile, outputDir; string config = EditorExtensionsPackage.DTE.Solution.SolutionBuild.ActiveConfiguration.Name; ErrorHandler.ThrowOnFailure(buildPropertyStorage.GetPropertyValue("TypeScriptOutFile", config, (uint)_PersistStorageType.PST_PROJECT_FILE, out outputFile)); ErrorHandler.ThrowOnFailure(buildPropertyStorage.GetPropertyValue("TypeScriptOutDir", config, (uint)_PersistStorageType.PST_PROJECT_FILE, out outputDir)); if (!string.IsNullOrEmpty(outputFile)) { _outputFile = Path.Combine(ProjectHelpers.GetRootFolder(project), outputFile); } else if (!string.IsNullOrEmpty(outputDir)) { string dir = Path.Combine(ProjectHelpers.GetRootFolder(project), outputDir); string file = Path.ChangeExtension(Path.GetFileName(SourceFilePath), ".js"); _outputFile = Path.Combine(dir, file); } } if (string.IsNullOrEmpty(_outputFile)) { _outputFile = Path.ChangeExtension(SourceFilePath, ".js"); } return(_outputFile); }
public async override Task RunAsync() { var extensionBundleManager = ExtensionBundleHelper.GetExtensionBundleManager(); if (extensionBundleManager.IsExtensionBundleConfigured()) { var hostFilePath = Path.Combine(Environment.CurrentDirectory, ScriptConstants.HostMetadataFileName); if (_showNoActionWarning) { ColoredConsole.WriteLine(WarningColor($"No action performed. Extension bundle is configured in {hostFilePath}.")); } return; } if (!string.IsNullOrEmpty(ConfigPath) && !FileSystemHelpers.DirectoryExists(ConfigPath)) { throw new CliArgumentsException("Invalid config path, please verify directory exists"); } if (!NeedsExtensionsInstall()) { return; } if (CommandChecker.CommandExists("dotnet")) { var extensionsProj = await ExtensionsHelper.EnsureExtensionsProjectExistsAsync(_secretsManager, Csx, ConfigPath); if (string.IsNullOrEmpty(Package) && string.IsNullOrEmpty(Version)) { var project = ProjectHelpers.GetProject(extensionsProj); foreach (var extensionPackage in ExtensionsHelper.GetExtensionPackages()) { // Only add / update package referece if it does not exist or forced update is enabled if (!ProjectHelpers.PackageReferenceExists(project, extensionPackage.Name) || Force) { await AddPackage(extensionsProj, extensionPackage.Name, extensionPackage.Version); } } } else if (!string.IsNullOrEmpty(Package) && !string.IsNullOrEmpty(Version)) { await AddPackage(extensionsProj, Package, Version); } else { throw new CliArgumentsException("Must specify extension package name and version", new CliArgument { Name = nameof(Package), Description = "Extension package name" }, new CliArgument { Name = nameof(Version), Description = "Extension package version" } ); } var syncAction = new SyncExtensionsAction(_secretsManager, false) { OutputPath = OutputPath, ConfigPath = ConfigPath }; await syncAction.RunAsync(); } else { throw new CliException(Constants.Errors.ExtensionsNeedDotnet); } }