/// <summary> /// Find the first project item with the given filename. /// </summary> /// <param name="projectItems"> /// The list of project items to inspect recursively. /// </param> /// <param name="filename"> /// The name of the project item to find. /// </param> /// <param name="recurse"> /// Whether to recurse into project items. Optional, true by default. /// </param> /// <returns> /// Returns the first project item with the given filename. /// </returns> public static ProjectItem FindProjectItem(ProjectItems projectItems, string filename, bool recurse = true) { if (projectItems == null) { return(null); } foreach (ProjectItem item in projectItems) { if (string.Equals(item.Name, filename, StringComparison.OrdinalIgnoreCase)) { return(item); } else if (recurse && item.ProjectItems != null) { var subItem = ProjectUtilities.FindProjectItem(item.ProjectItems, filename); if (subItem != null) { return(subItem); } } } return(null); }
private async Task AddSdkReferenceAsync(ConnectedServiceHandlerContext context, HandlerManifest manifest, CancellationToken ct) { ct.ThrowIfCancellationRequested(); foreach (var nuget in manifest.PackageReferences) { Dictionary <string, string> packages = new Dictionary <string, string>(); packages.Add(nuget.Id, nuget.Version); try { await NuGetUtilities.InstallPackagesAsync( packages, "ConnectedServiceForAzureIoTHub.9e26cafb-e929-4d85-a8af-42c42f72f771", context.Logger, ProjectUtilities.GetDteProject(context.ProjectHierarchy), this.PackageInstallerServices, this.PackageInstaller); } catch (Exception ex) { var status = string.Format("Package {0} installation failed. Exception: '{1}'. WARNING: The project might not compile!", nuget.Id, ex.Message); await context.Logger.WriteMessageAsync(LoggerMessageCategory.Warning, status); } } }