/// <summary> /// This method ensures that the packages.config file is created and all the installed packages are added to it. /// </summary> /// <param name="packageToInstall">The nuget package to install with all its dependencies</param> /// <param name="packageReader">The <see cref="PackageReaderBase"/> to use in reading the package.</param> /// <param name="downloadResult">The <see cref="DownloadResourceResult"/> for the package.</param> /// <param name="nuGetFramework">The <see cref="NuGetFramework"/></param> /// <returns>The <see cref="NuspecReader"/> for reading the package's nuspec files.</returns> private async Task <NuspecReader> UpdatePackagesConfigFile( SourcePackageDependencyInfo packageToInstall, PackageReaderBase packageReader, DownloadResourceResult downloadResult, NuGetFramework nuGetFramework) { NuspecReader nuspecReader = await packageReader.GetNuspecReaderAsync(CancellationToken.None).ConfigureAwait(false); Dictionary <string, object> metadata = new Dictionary <string, object>() { { "Name", packageToInstall.Id }, { "TargetFrameWork", nuGetFramework } }; IDictionary <string, object> metadataObject = new ExpandoObject() as IDictionary <string, object>; foreach (KeyValuePair <string, object> kvp in metadata) { metadataObject.Add(kvp.Key, kvp.Value); } Dictionary <string, object> meta = new Dictionary <string, object> { { "Name", metadataObject.ToList().FirstOrDefault().Value }, { "TargetFramework", metadataObject.ToList().LastOrDefault().Value } }; PackagesConfigNuGetProject packagesConfigNuGetProject = new PackagesConfigNuGetProject(this.project.DirectoryPath, meta); await packagesConfigNuGetProject.InstallPackageAsync( packageToInstall, downloadResult, new EmptyNuGetProjectContext(), CancellationToken.None); return(nuspecReader); }