private void AddOrUpdatePackageReference(string packageName, VersionRange packageVersion, string[] metadataElements, string[] metadataValues) { _threadingService.ThrowIfNotOnUIThread(); // Note that API behavior is: // - specify a metadata element name with a value => add/replace that metadata item on the package reference // - specify a metadata element name with no value => remove that metadata item from the project reference // - don't specify a particular metadata name => if it exists on the package reference, don't change it (e.g. for user defined metadata) AsVSProject4.PackageReferences.AddOrUpdate( packageName, packageVersion.OriginalString ?? packageVersion.ToShortString(), metadataElements, metadataValues); }
public async Task <Boolean> InstallPackageWithMetadataAsync( string packageId, VersionRange range, IEnumerable <string> metadataElements, IEnumerable <string> metadataValues) { var success = false; await NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async delegate { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); // We don't adjust package reference metadata from UI _project.AddOrUpdateLegacyCSProjPackage( packageId, range.OriginalString ?? range.ToShortString(), metadataElements?.ToArray() ?? new string[0], metadataValues?.ToArray() ?? new string[0]); success = true; }); return(success); }