├── .gitattributes ├── .gitignore ├── 35MSSharedLib1024.snk ├── Generate-Resources.ps1 ├── LICENSE.txt ├── Microsoft.PackageManagement.NuGetProvider.nuspec ├── NuGetExtensions.cs ├── NuGetProvider.csproj ├── NuGetResources ├── INuGetAbuseFeed.cs ├── INuGetAutoCompleteFeed.cs ├── INuGetFeed.cs ├── INuGetFilesFeed.cs ├── INuGetGalleryFeed.cs ├── INuGetPackageFeed.cs ├── INuGetQueryFeed.cs ├── INuGetResource.cs ├── INuGetResourceCollection.cs ├── NuGetAbuseFeed3.cs ├── NuGetAutoCompleteFeed3.cs ├── NuGetFilesFeed2.cs ├── NuGetFilesFeed3.cs ├── NuGetGalleryFeedMyGet.cs ├── NuGetGalleryFeedOrg.cs ├── NuGetLocalPackageFeed.cs ├── NuGetPackageFeed2.cs ├── NuGetPackageFeed3.cs ├── NuGetQueryFeed2.cs ├── NuGetQueryFeed3.cs ├── NuGetRemoteFeedBase.cs ├── NuGetResourceCollection2.cs ├── NuGetResourceCollection3.cs ├── NuGetResourceCollectionBase.cs ├── NuGetResourceCollectionFactory.cs ├── NuGetResourceCollectionLocal.cs ├── NuGetServiceInfo.cs └── NuGetServiceType.cs ├── NugetLightClient.cs ├── NugetLightConstant.cs ├── NugetLightProvider.cs ├── NugetLightRequest.cs ├── Package ├── IPackage.cs ├── IPackageName.cs ├── PackageBase.cs ├── PackageDependency.cs ├── PackageDependencySet.cs ├── PackageItem.cs └── PackageName.cs ├── PackageSource.cs ├── Properties └── AssemblyInfo.cs ├── README.md ├── Register-FindPackageNuGetArgumentCompleter.ps1 ├── Repository ├── IPackageRepository.cs ├── IPackageRepositoryFactory.cs ├── LocalPackageRepository.cs ├── NuGetPackageRepository.cs ├── NuGetSearchContext.cs ├── NuGetSearchTerm.cs ├── PackageEntryInfo.cs ├── PackageRepositoryCreateParameters.cs └── PackageRepositoryFactory.cs ├── Sdk ├── Constants.cs ├── ErrorCategory.cs ├── IRequestOutput.cs ├── NuGetRequestOutput.cs ├── NullRequestOutput.cs ├── Request.cs └── RequestWrapper.cs ├── Utility ├── CatalogUrlConverter.cs ├── ConcurrentInMemoryCache.cs ├── DependencyGroupConverter.cs ├── DynamicJsonParser.cs ├── HttpQueryBuilder.cs ├── IDynamicJsonObjectConverter.cs ├── NuGetPathUtility.cs ├── NuGetWebUtility.cs ├── PackageBaseConverter.cs ├── PackageDependencyConverter.cs ├── PackageFilterUtility.cs ├── PackageUtility.cs ├── ProgressTracker.cs ├── PublicObjectView.cs └── TaskGroup.cs ├── appveyor.yml ├── build.ps1 ├── nuget.config ├── pack.ps1 ├── provider.manifest ├── releasenotes.md ├── resources ├── Messages.Designer.cs └── Messages.resx ├── smoketest.tests.ps1 ├── tools └── mt.exe └── vs-csproj ├── NugetLightProvider.csproj └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Build results 12 | 13 | [Dd]ebug/ 14 | [Rr]elease/ 15 | x64/ 16 | build/ 17 | [Bb]in/ 18 | [Oo]bj/ 19 | [Oo]ut/ 20 | [Gg]en/ 21 | 22 | Messages.Designer.cs 23 | Resources/Microsoft.PackageManagement.NuGetProvider.Resources.Messages.resx 24 | 25 | # Windows Installer files 26 | *.cab 27 | *.msi 28 | *.msm 29 | *.msp 30 | 31 | # Visual Studio solution 32 | *.suo 33 | 34 | # Windows shortcuts 35 | *.lnk 36 | 37 | # ========================= 38 | # Operating System Files 39 | # ========================= 40 | 41 | # OSX 42 | # ========================= 43 | 44 | .DS_Store 45 | .AppleDouble 46 | .LSOverride 47 | 48 | # solution file: 49 | *.sln 50 | 51 | # Untracked files: 52 | intermediate/* 53 | output/* 54 | 55 | # Thumbnails 56 | ._* 57 | 58 | # Files that might appear on external disk 59 | .Spotlight-V100 60 | .Trashes 61 | 62 | # Directories potentially created on remote AFP share 63 | .AppleDB 64 | .AppleDesktop 65 | Network Trash Folder 66 | Temporary Items 67 | .apdisk 68 | 35MSSharedLib1024.snk 69 | 70 | # NuGet packaging 71 | nuget.exe 72 | *.nupkg 73 | *.nuspec_template 74 | /.vs/* 75 | -------------------------------------------------------------------------------- /35MSSharedLib1024.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneGet/NuGetProvider/6c486d0de4f4c550615467d2b1298e5fb0cdcd2b/35MSSharedLib1024.snk -------------------------------------------------------------------------------- /Generate-Resources.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param() 3 | 4 | function Get-StronglyTypeCsFileForResx 5 | { 6 | param($xml, $ClassName, $moduleName) 7 | 8 | # Example 9 | # 10 | # $ClassName = Full.Name.Of.The.ClassFoo 11 | # $shortClassName = ClassFoo 12 | # $namespaceName = Full.Name.Of.The 13 | 14 | $shortClassName = $ClassName 15 | $namespaceName = $null 16 | 17 | $lastIndexOfDot = $className.LastIndexOf(".") 18 | if ($lastIndexOfDot -ne -1) 19 | { 20 | $namespaceName = $className.Substring(0, $lastIndexOfDot) 21 | $shortClassName = $className.Substring($lastIndexOfDot + 1) 22 | } 23 | 24 | $banner = @' 25 | //------------------------------------------------------------------------------ 26 | // 27 | // This code was generated by a New-StronglyTypedCsFileForResx funciton. 28 | // To add or remove a member, edit your .ResX file then rerun buildCoreClr.ps1 29 | // 30 | // Changes to this file may cause incorrect behavior and will be lost if 31 | // the code is regenerated. 32 | // 33 | //------------------------------------------------------------------------------ 34 | 35 | {0} 36 | '@ 37 | 38 | $namespace = @' 39 | namespace {0} {{ 40 | {1} 41 | }} 42 | '@ 43 | 44 | $body = @' 45 | using System; 46 | using System.Reflection; 47 | 48 | /// 49 | /// A strongly-typed resource class, for looking up localized strings, etc. 50 | /// 51 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 52 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 53 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 54 | 55 | internal class {0} {{ 56 | 57 | private static global::System.Resources.ResourceManager resourceMan; 58 | 59 | private static global::System.Globalization.CultureInfo resourceCulture; 60 | 61 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 62 | internal {0}() {{ 63 | }} 64 | 65 | /// 66 | /// Returns the cached ResourceManager instance used by this class. 67 | /// 68 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 69 | internal static global::System.Resources.ResourceManager ResourceManager {{ 70 | get {{ 71 | if (object.ReferenceEquals(resourceMan, null)) {{ 72 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("{3}.resources.{2}", typeof({0}).GetTypeInfo().Assembly); 73 | resourceMan = temp; 74 | }} 75 | return resourceMan; 76 | }} 77 | }} 78 | 79 | /// 80 | /// Overrides the current thread's CurrentUICulture property for all 81 | /// resource lookups using this strongly typed resource class. 82 | /// 83 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 84 | internal static global::System.Globalization.CultureInfo Culture {{ 85 | get {{ 86 | return resourceCulture; 87 | }} 88 | set {{ 89 | resourceCulture = value; 90 | }} 91 | }} 92 | {1} 93 | }} 94 | '@ 95 | 96 | $entry = @' 97 | 98 | /// 99 | /// Looks up a localized string similar to {1} 100 | /// 101 | internal static string {0} {{ 102 | get {{ 103 | return ResourceManager.GetString("{0}", resourceCulture); 104 | }} 105 | }} 106 | '@ 107 | $entries = $xml.root.data | % { 108 | if ($_) { 109 | $val = $_.value.Replace("`n", "`n ///") 110 | $name = $_.name.Replace(' ', '_') 111 | $entry -f $name,$val 112 | } 113 | } | Out-String 114 | 115 | $bodyCode = $body -f $shortClassName,$entries,$ClassName,$moduleName 116 | 117 | if ($NamespaceName) 118 | { 119 | $bodyCode = $namespace -f $NamespaceName, $bodyCode 120 | } 121 | 122 | $resultCode = $banner -f $bodyCode 123 | 124 | return $resultCode -replace "`r`n?|`n","`r`n" 125 | } 126 | 127 | $className = "Microsoft.PackageManagement.NuGetProvider.Resources.Messages" 128 | $moduleName = "NuGetProvider" 129 | $xmlFilePath = Join-Path -Path $PSScriptRoot -ChildPath resources | Join-Path -ChildPath Messages.resx 130 | $newResxFile = Join-Path $PSScriptRoot -ChildPath resources | Join-Path -ChildPath "$className.resx" 131 | Copy-Item $xmlFilePath $newResxFile -Force 132 | $outputFilePath = Join-Path -Path $PSScriptRoot -ChildPath gen | Join-Path -ChildPath "$className.cs" 133 | $xml = [xml](Get-Content -raw $xmlFilePath) 134 | $genSource = Get-StronglyTypeCsFileForResx -xml $xml -ClassName $className -moduleName $moduleName 135 | $outputDir = Split-Path $outputFilePath -Parent 136 | if (-not (Test-Path -Path $outputDir)) { 137 | $null = New-Item $outputDir -ItemType Directory 138 | } 139 | if (-not (Test-Path -Path $outputFilePath)) { 140 | $null = New-Item $outputFilePath 141 | } 142 | Set-Content -Encoding Ascii -Path $outputFilePath -Value $genSource 143 | Write-Verbose "Generated '$outputFilePath' from '$xmlFilePath'" -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation 2 | All rights reserved. 3 | 4 | MIT License 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the Software), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /Microsoft.PackageManagement.NuGetProvider.nuspec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneGet/NuGetProvider/6c486d0de4f4c550615467d2b1298e5fb0cdcd2b/Microsoft.PackageManagement.NuGetProvider.nuspec -------------------------------------------------------------------------------- /NuGetExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.PackageManagement.Provider.Utility; 2 | 3 | namespace Microsoft.PackageManagement.NuGetProvider 4 | { 5 | using System; 6 | using System.Globalization; 7 | 8 | internal static class StringExtensions 9 | { 10 | 11 | internal static string MakeFindPackageByIdQuery(this string packageId, string urlFormat) 12 | { 13 | return String.Format(CultureInfo.InvariantCulture, urlFormat, packageId); 14 | } 15 | 16 | internal static string MakeSearchQuery(this string searchTerm, string baseUrl, bool allowPrereleaseVersions, bool allVersions) 17 | { 18 | // Fill in the searchTerm, targetFrameworks, and allowPrereleaseVersions fileds in the query format string. 19 | // Skip and Take will be filled later on 20 | var newSearchTerm = string.Format(CultureInfo.InvariantCulture, NuGetConstant.SearchTerm, searchTerm, allowPrereleaseVersions ? "true" : "false"); 21 | 22 | // Make the uri query string 23 | return PathUtility.UriCombine(baseUrl, String.Concat((allVersions ? NuGetConstant.SearchFilterAllVersions : NuGetConstant.SearchFilter), newSearchTerm)); 24 | } 25 | 26 | internal static string InsertSkipAndTop(this string query) 27 | { 28 | return String.Concat(query, NuGetConstant.SkipAndTop); 29 | } 30 | } 31 | internal static class ExceptionExtensions 32 | { 33 | internal static void Dump(this Exception ex, NuGetRequest request) 34 | { 35 | request.Debug(ex.ToString()); 36 | } 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /NuGetProvider.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net472; 5 | true 6 | true 7 | Microsoft.PackageManagement.NuGetProvider 8 | 35MSSharedLib1024.snk 9 | true 10 | NuGetProvider 11 | false 12 | false 13 | false 14 | false 15 | false 16 | false 17 | false 18 | false 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | $(DefineConstants);CORECLR 65 | portable 66 | 67 | 68 | 69 | $(DefineConstants) 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /NuGetResources/INuGetAbuseFeed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Contract for NuGet abuse URL builder. 19 | /// 20 | public interface INuGetAbuseFeed : INuGetFeed 21 | { 22 | /// 23 | /// Create an abuse URI for the given package and version. 24 | /// 25 | /// Package ID to construct the abuse URI for. Cannot be null. 26 | /// Package version to construct the abuse URI for. Cannot be null. 27 | /// The abuse URI 28 | string MakeAbuseUri(string packageId, string packageVersion); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /NuGetResources/INuGetAutoCompleteFeed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System.Collections.Generic; 18 | using System.Management.Automation; 19 | 20 | /// 21 | /// Contract for NuGet autocomplete service. 22 | /// 23 | public interface INuGetAutoCompleteFeed : INuGetFeed 24 | { 25 | IEnumerable Autocomplete(NuGetSearchTerm autocompleteSearchTerm, NuGetRequest request); 26 | IEnumerable Autocomplete(NuGetSearchTerm autocompleteSearchTerm, RequestWrapper networkAccess, bool allowPrerelease); 27 | IEnumerable Autocomplete(NuGetSearchTerm autocompleteSearchTerm, RequestWrapper networkAccess, WildcardPattern acceptedPattern, bool allowPrerelease); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /NuGetResources/INuGetFeed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Interface for a generic NuGet feed. 19 | /// 20 | public interface INuGetFeed : INuGetResource 21 | { 22 | /// 23 | /// Determine if this feed is currently available. 24 | /// 25 | /// Current request. 26 | /// True if available; false otherwise. 27 | bool IsAvailable(RequestWrapper request); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /NuGetResources/INuGetFilesFeed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.Provider.Utility; 18 | using System.Collections.Generic; 19 | 20 | /// 21 | /// Contract for a NuGet query feed. This type of feed is generally used to access package files like the nuspec, nupkg. 22 | /// 23 | public interface INuGetFilesFeed : INuGetFeed 24 | { 25 | /// 26 | /// Download a package and its dependencies to the specified destination. 27 | /// 28 | /// PublicObjectView containing PackageItem object. 29 | /// Where to download package to. 30 | /// Current request. 31 | /// True if download was successful; false otherwise. 32 | bool DownloadPackage(PublicObjectView packageView, string destination, NuGetRequest request); 33 | 34 | /// 35 | /// Download a package and its dependencies to the specified destination. 36 | /// 37 | /// PublicObjectView containing PackageItem object. 38 | /// Where to download package to. 39 | /// Current request. 40 | /// True if download was successful; false otherwise. 41 | bool DownloadPackage(PublicObjectView packageView, string destination, RequestWrapper request); 42 | 43 | /// 44 | /// Install a package and its dependencies to a common location. 45 | /// 46 | /// PublicObjectView containing PackageItem object. 47 | /// Current request. 48 | /// True if install was successful; false otherwise. 49 | bool InstallPackage(PublicObjectView packageView, NuGetRequest request); 50 | 51 | /// 52 | /// Install a package and its dependencies to a common location. 53 | /// 54 | /// PublicObjectView containing PackageItem object. 55 | /// Current request. 56 | /// True if install was successful; false otherwise. 57 | bool InstallPackage(PublicObjectView packageView, RequestWrapper request); 58 | 59 | /// 60 | /// Creates or gets the content download URI from a given package. 61 | /// 62 | /// Non-null PackageBase 63 | /// Download URI 64 | string MakeDownloadUri(PackageBase package); 65 | 66 | /// 67 | /// Get all versions from blob store. 68 | /// 69 | /// Existing PackageEntryInfo to add versions to 70 | /// Current request. 71 | /// PackageEntryInfo with versions filled in 72 | PackageEntryInfo GetVersionInfo(PackageEntryInfo packageInfo, RequestWrapper request); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /NuGetResources/INuGetGalleryFeed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Contract for NuGet gallery URL builder. 19 | /// 20 | public interface INuGetGalleryFeed : INuGetFeed 21 | { 22 | /// 23 | /// Create a gallery URI for the given package and version. This URI will point to the package's home page. 24 | /// e.g. https://www.nuget.org/packages/Newtonsoft.Json/10.0.1 25 | /// 26 | /// Package ID to construct the abuse URI for. Cannot be null. 27 | /// Package version to construct the abuse URI for. Cannot be null. 28 | /// The gallery URI 29 | string MakeGalleryUri(string packageId, string packageVersion); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /NuGetResources/INuGetPackageFeed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Contract for a NuGet query feed. This type of feed is generally used to get info about a specific package. 19 | /// 20 | public interface INuGetPackageFeed : INuGetFeed 21 | { 22 | /// 23 | /// Find packages using packageId and (optionally) version. 24 | /// 25 | /// Contains search info 26 | /// Current request. 27 | /// All matching packages. 28 | NuGetSearchResult Find(NuGetSearchContext findContext, NuGetRequest request); 29 | 30 | /// 31 | /// Find packages using packageId and (optionally) version. 32 | /// 33 | /// Contains search info 34 | /// Current request. 35 | /// All matching packages. 36 | NuGetSearchResult Find(NuGetSearchContext findContext, RequestWrapper request); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /NuGetResources/INuGetQueryFeed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Contract for a NuGet search feed. This type of feed is generally used to search for multiple packages given some criteria. 19 | /// 20 | public interface INuGetQueryFeed : INuGetFeed 21 | { 22 | /// 23 | /// Search for packages. 24 | /// 25 | /// Contains search info. 26 | /// Current request. 27 | /// All matching packages. 28 | NuGetSearchResult Search(NuGetSearchContext searchContext, NuGetRequest nugetRequest); 29 | 30 | /// 31 | /// Search for packages. 32 | /// 33 | /// Contains search info. 34 | /// Current request. 35 | /// All matching packages. 36 | NuGetSearchResult Search(NuGetSearchContext searchContext, RequestWrapper request); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /NuGetResources/INuGetResource.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Contract for a generic NuGet resource. 19 | /// 20 | public interface INuGetResource 21 | { 22 | /// 23 | /// Gets the resources collection of which this resource is a part. 24 | /// 25 | INuGetResourceCollection ResourcesCollection { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /NuGetResources/INuGetResourceCollection.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | /// 21 | /// Contract for a collection of NuGet resources for a particular API version. 22 | /// 23 | public interface INuGetResourceCollection 24 | { 25 | INuGetPackageFeed PackagesFeed { get; } 26 | 27 | INuGetQueryFeed QueryFeed { get; } 28 | 29 | INuGetFilesFeed FilesFeed { get; } 30 | 31 | INuGetAbuseFeed AbuseFeed { get; } 32 | 33 | INuGetGalleryFeed GalleryFeed { get; } 34 | 35 | INuGetAutoCompleteFeed AutoCompleteFeed { get; } 36 | 37 | Func, string> GetSearchQueryDelegate { get; } 38 | 39 | IDynamicJsonObjectConverter PackageConverter { get; } 40 | 41 | IDynamicJsonObjectConverter CatalogUrlConverter { get; } 42 | 43 | IDynamicJsonObjectConverter PackageDependencyConverter { get; } 44 | 45 | IDynamicJsonObjectConverter PackageDependencySetConverter { get; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /NuGetResources/NuGetAbuseFeed3.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | using Microsoft.PackageManagement.NuGetProvider.Resources; 16 | 17 | namespace Microsoft.PackageManagement.NuGetProvider 18 | { 19 | /// 20 | /// Abuse URI builder for NuGet v3. 21 | /// 22 | public class NuGetAbuseFeed3 : INuGetAbuseFeed 23 | { 24 | /// 25 | /// A URI template like: https://www.nuget.org/packages/{id}/{version}/ReportAbuse 26 | /// 27 | private string uriTemplate; 28 | 29 | public INuGetResourceCollection ResourcesCollection { get; set; } 30 | 31 | /// 32 | /// Creates a v3 resource using the abuse URI template specified in the index.json of NuGet v3. Expected to contain "{id}" and "{version}" 33 | /// 34 | public NuGetAbuseFeed3(string uriTemplate) 35 | { 36 | this.uriTemplate = uriTemplate; 37 | } 38 | 39 | public bool IsAvailable(RequestWrapper request) => true; 40 | 41 | /// 42 | /// Creates the report abuse URI by replacing {id} with packageId and {version} with packageVersion. 43 | /// 44 | public string MakeAbuseUri(string packageId, string packageVersion) 45 | { 46 | return this.uriTemplate.Replace(Constants.PackageIdTemplateParameter, packageId.ToLowerInvariant()).Replace(Constants.PackageVersionTemplateParameter, packageVersion.ToLowerInvariant()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /NuGetResources/NuGetAutoCompleteFeed3.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.NuGetProvider.Resources; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.IO; 21 | using System.Management.Automation; 22 | 23 | /// 24 | /// Implements the client for the AutoComplete service for NuGet v3. 25 | /// 26 | public class NuGetAutoCompleteFeed3 : NuGetRemoteFeedBase, INuGetAutoCompleteFeed 27 | { 28 | public NuGetAutoCompleteFeed3(NuGetServiceInfo primaryServiceEndpoint) 29 | { 30 | this.Endpoints.Add(primaryServiceEndpoint); 31 | } 32 | 33 | public IEnumerable Autocomplete(NuGetSearchTerm autocompleteSearchTerm, NuGetRequest request) 34 | { 35 | return Autocomplete(autocompleteSearchTerm, new RequestWrapper(request), request.AllowPrereleaseVersions.Value); 36 | } 37 | 38 | public override bool IsAvailable(RequestWrapper request) 39 | { 40 | foreach (NuGetServiceInfo endpoint in this.Endpoints) 41 | { 42 | Stream s = NuGetClient.DownloadDataToStream(endpoint.Url, request); 43 | if (s != null) 44 | { 45 | return true; 46 | } 47 | } 48 | 49 | return false; 50 | } 51 | 52 | public IEnumerable Autocomplete(NuGetSearchTerm autocompleteSearchTerm, RequestWrapper request, bool allowPrerelease) 53 | { 54 | return Autocomplete(autocompleteSearchTerm, request, acceptedPattern: null, allowPrerelease: allowPrerelease); 55 | } 56 | 57 | public IEnumerable Autocomplete(NuGetSearchTerm autocompleteSearchTerm, RequestWrapper request, WildcardPattern acceptedPattern, bool allowPrerelease) 58 | { 59 | try 60 | { 61 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetAutoCompleteFeed3", "Autocomplete", autocompleteSearchTerm.ToString()); 62 | return base.Execute>((baseUrl) => 63 | { 64 | HttpQueryBuilder qb = new HttpQueryBuilder(); 65 | if (autocompleteSearchTerm.Term == NuGetSearchTerm.NuGetSearchTermType.Id) 66 | { 67 | qb.Add(Constants.PackageIdQueryParam, autocompleteSearchTerm.Text); 68 | } 69 | else if (autocompleteSearchTerm.Term == NuGetSearchTerm.NuGetSearchTermType.AutoComplete) 70 | { 71 | qb.Add(Constants.QueryQueryParam, autocompleteSearchTerm.Text); 72 | } 73 | 74 | if (allowPrerelease) 75 | { 76 | qb.Add(Constants.PrereleaseQueryParam, "true"); 77 | } 78 | 79 | qb.Add(Constants.TakeQueryParam, Constants.SearchPageCount) 80 | .Add(Constants.SemVerLevelQueryParam, Constants.SemVerLevel2); 81 | 82 | return NuGetWebUtility.GetResults(request, (dynamic root) => 83 | { 84 | long res = -1; 85 | if (root.HasProperty("totalhits")) 86 | { 87 | res = root.totalhits; 88 | request.Debug(Resources.Messages.TotalPackagesDiscovered, res); 89 | } 90 | else 91 | { 92 | request.Warning(Resources.Messages.JsonSchemaMismatch, "totalhits"); 93 | request.Debug(Resources.Messages.JsonObjectDump, DynamicJsonParser.Serialize(root)); 94 | } 95 | 96 | return res; 97 | }, (dynamic root) => GetAutoCompleteResults(root, autocompleteSearchTerm, acceptedPattern), (long resultsToSkip) => 98 | { 99 | if (resultsToSkip > 0) 100 | { 101 | HttpQueryBuilder currentQb = qb.CloneAdd(Constants.SkipQueryParam, resultsToSkip.ToString()); 102 | return currentQb.AddQueryString(baseUrl); 103 | } 104 | 105 | return qb.AddQueryString(baseUrl); 106 | }, (string content) => 107 | { 108 | return DynamicJsonParser.Parse(content); 109 | }, Constants.SearchPageCountInt); 110 | }); 111 | } 112 | finally 113 | { 114 | request.Debug(Messages.DebugInfoReturnCall, "NuGetAutoCompleteFeed3", "Autocomplete"); 115 | } 116 | } 117 | 118 | private IEnumerable> GetAutoCompleteResults(dynamic root, NuGetSearchTerm autocompleteSearchTerm, WildcardPattern acceptedPattern) 119 | { 120 | foreach (string rValue in root.data) 121 | { 122 | // "AutoComplete" for NuGet is slightly different than the PS definition 123 | // We only want the matches that match the input accepted pattern or start with the search term if no accepted pattern is used 124 | if (autocompleteSearchTerm.Term == NuGetSearchTerm.NuGetSearchTermType.AutoComplete && 125 | ((acceptedPattern == null && !rValue.StartsWith(autocompleteSearchTerm.Text, StringComparison.OrdinalIgnoreCase)) || 126 | acceptedPattern.IsMatch(rValue))) 127 | { 128 | continue; 129 | } 130 | 131 | yield return YieldResultAsEnumerable(rValue); 132 | } 133 | } 134 | 135 | private IEnumerable YieldResultAsEnumerable(string result) 136 | { 137 | yield return result; 138 | } 139 | 140 | 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /NuGetResources/NuGetFilesFeed2.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System.Collections.Generic; 18 | using Microsoft.PackageManagement.NuGetProvider.Resources; 19 | using Microsoft.PackageManagement.Provider.Utility; 20 | 21 | /// 22 | /// Implements the install/download functions for NuGet v2. 23 | /// 24 | public class NuGetFilesFeed2 : INuGetFilesFeed 25 | { 26 | public INuGetResourceCollection ResourcesCollection { get; set; } 27 | 28 | public bool InstallPackage(PublicObjectView packageView, NuGetRequest request) 29 | { 30 | return InstallPackage(packageView, new RequestWrapper(request)); 31 | } 32 | 33 | public bool DownloadPackage(PublicObjectView packageView, string destination, NuGetRequest request) 34 | { 35 | return DownloadPackage(packageView, destination, new RequestWrapper(request)); 36 | } 37 | 38 | public bool IsAvailable(RequestWrapper request) => true; 39 | 40 | public string MakeDownloadUri(PackageBase package) 41 | { 42 | // v2 doesn't really build this dynamically, so assume ContentSrcUrl is already set. This shouldn't be called for v2 as it doesn't make sense. 43 | return package.ContentSrcUrl; 44 | } 45 | 46 | public PackageEntryInfo GetVersionInfo(PackageEntryInfo packageInfo, RequestWrapper request) 47 | { 48 | throw new System.NotImplementedException(); 49 | } 50 | 51 | public bool DownloadPackage(PublicObjectView packageView, string destination, RequestWrapper request) 52 | { 53 | try 54 | { 55 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetFilesFeed2", "DownloadPackage", destination); 56 | PackageItem package = packageView.GetValue(); 57 | // TODO: For now this has to require NuGetRequest, due to its usage of stuff like request.GetOptionValue and request.YieldPackage 58 | return NuGetClient.InstallOrDownloadPackageHelper(package, request.Request, Constants.Install, 59 | (packageItem, progressTracker) => NuGetClient.DownloadSinglePackage(packageItem, request.Request, destination, progressTracker)); 60 | } 61 | finally 62 | { 63 | request.Debug(Messages.DebugInfoReturnCall, "NuGetFilesFeed2", "InstallPackage"); 64 | } 65 | } 66 | 67 | public bool InstallPackage(PublicObjectView packageView, RequestWrapper request) 68 | { 69 | try 70 | { 71 | request.Debug(Messages.DebugInfoCallMethod, "NuGetFilesFeed2", "InstallPackage"); 72 | PackageItem package = packageView.GetValue(); 73 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetFilesFeed2", "InstallPackage", package.FastPath); 74 | // TODO: For now this has to require NuGetRequest, due to its usage of stuff like request.GetOptionValue and request.YieldPackage 75 | return NuGetClient.InstallOrDownloadPackageHelper(package, request.Request, Constants.Install, 76 | (packageItem, progressTracker) => NuGetClient.InstallSinglePackage(packageItem, request.Request, progressTracker)); 77 | } 78 | finally 79 | { 80 | request.Debug(Messages.DebugInfoReturnCall, "NuGetFilesFeed2", "InstallPackage"); 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /NuGetResources/NuGetGalleryFeedMyGet.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System; 18 | using System.Text.RegularExpressions; 19 | 20 | /// 21 | /// Implements the gallery template for MyGet. 22 | /// e.g. https://powershell.myget.org/feed/powershell-core/package/nuget/System.Management.Automation/6.0.0-beta.9 23 | /// 24 | public class NuGetGalleryFeedMyGet : INuGetGalleryFeed 25 | { 26 | private string galleryTemplateUri = null; 27 | 28 | public INuGetResourceCollection ResourcesCollection { get; set; } 29 | 30 | public NuGetGalleryFeedMyGet(string myGetUrl) 31 | { 32 | // For now, assume myGetUrl is a NuGet v3 feed 33 | // First get the feed name 34 | Match m = Constants.MyGetFeedRegex.Match(myGetUrl); 35 | if (m.Success) 36 | { 37 | string feedName = m.Groups[1].Value; 38 | // Then build the gallery template 39 | Uri uri = new Uri(myGetUrl); 40 | this.galleryTemplateUri = String.Format(Constants.MyGetGalleryUriTemplate, uri.Scheme, uri.Host, feedName); 41 | } 42 | } 43 | 44 | public bool IsAvailable(RequestWrapper request) => true; 45 | 46 | public string MakeGalleryUri(string packageId, string packageVersion) 47 | { 48 | return this.galleryTemplateUri.Replace(Constants.PackageIdLowerTemplateParameter, packageId.ToLowerInvariant()).Replace(Constants.PackageVersionLowerTemplateParameter, packageVersion.ToLowerInvariant()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /NuGetResources/NuGetGalleryFeedOrg.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Implements the gallery feed for nuget.org 19 | /// 20 | public class NuGetGalleryFeedOrg : INuGetGalleryFeed 21 | { 22 | private string galleryTemplateUri; 23 | public NuGetGalleryFeedOrg() 24 | { 25 | // For nuget.org, use the template: https://www.nuget.org/packages/{id-lower}/{version-lower} 26 | this.galleryTemplateUri = Constants.NuGetGalleryUriTemplate; 27 | } 28 | 29 | public INuGetResourceCollection ResourcesCollection { get; set; } 30 | 31 | public bool IsAvailable(RequestWrapper request) => true; 32 | 33 | public string MakeGalleryUri(string packageId, string packageVersion) 34 | { 35 | return this.galleryTemplateUri.Replace(Constants.PackageIdLowerTemplateParameter, packageId.ToLowerInvariant()).Replace(Constants.PackageVersionLowerTemplateParameter, packageVersion.ToLowerInvariant()); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /NuGetResources/NuGetLocalPackageFeed.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.NuGetProvider.Resources; 18 | using Microsoft.PackageManagement.Provider.Utility; 19 | using System; 20 | using System.Collections.Generic; 21 | 22 | /// 23 | /// Implements the package finding and downloading for local repositories. 24 | /// 25 | public class NuGetLocalPackageFeed : INuGetPackageFeed, INuGetFilesFeed 26 | { 27 | public INuGetResourceCollection ResourcesCollection { get; set; } 28 | 29 | public NuGetSearchResult Find(NuGetSearchContext findContext, NuGetRequest request) 30 | { 31 | throw new NotImplementedException(); 32 | } 33 | 34 | public bool DownloadPackage(PublicObjectView packageView, string destination, NuGetRequest request) 35 | { 36 | return DownloadPackage(packageView, destination, new RequestWrapper(request)); 37 | } 38 | 39 | public bool InstallPackage(PublicObjectView packageView, NuGetRequest request) 40 | { 41 | return InstallPackage(packageView, new RequestWrapper(request)); 42 | } 43 | 44 | public bool IsAvailable(RequestWrapper request) 45 | { 46 | return true; 47 | } 48 | 49 | /// 50 | /// No download URI. 51 | /// 52 | public string MakeDownloadUri(PackageBase package) 53 | { 54 | throw new NotImplementedException(); 55 | } 56 | 57 | public PackageEntryInfo GetVersionInfo(PackageEntryInfo packageInfo, RequestWrapper request) 58 | { 59 | throw new NotImplementedException(); 60 | } 61 | 62 | public NuGetSearchResult Find(NuGetSearchContext findContext, RequestWrapper request) 63 | { 64 | throw new NotImplementedException(); 65 | } 66 | 67 | public bool DownloadPackage(PublicObjectView packageView, string destination, RequestWrapper request) 68 | { 69 | try 70 | { 71 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetLocalPackageFeed", "DownloadPackage", destination); 72 | PackageItem package = packageView.GetValue(); 73 | // TODO: For now this has to require NuGetRequest, due to its usage of stuff like request.GetOptionValue and request.YieldPackage 74 | return NuGetClient.InstallOrDownloadPackageHelper(package, request.Request, Constants.Install, 75 | (packageItem, progressTracker) => NuGetClient.DownloadSinglePackage(packageItem, request.Request, destination, progressTracker)); 76 | } 77 | finally 78 | { 79 | request.Debug(Messages.DebugInfoReturnCall, "NuGetLocalPackageFeed", "DownloadPackage"); 80 | } 81 | } 82 | 83 | public bool InstallPackage(PublicObjectView packageView, RequestWrapper request) 84 | { 85 | try 86 | { 87 | request.Debug(Messages.DebugInfoCallMethod, "NuGetLocalPackageFeed", "InstallPackage"); 88 | PackageItem package = packageView.GetValue(); 89 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetLocalPackageFeed", "InstallPackage", package.FastPath); 90 | // TODO: For now this has to require NuGetRequest, due to its usage of stuff like request.GetOptionValue and request.YieldPackage 91 | return NuGetClient.InstallOrDownloadPackageHelper(package, request.Request, Constants.Install, 92 | (packageItem, progressTracker) => NuGetClient.InstallSinglePackage(packageItem, request.Request, progressTracker)); 93 | } 94 | finally 95 | { 96 | request.Debug(Messages.DebugInfoReturnCall, "NuGetLocalPackageFeed", "InstallPackage"); 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /NuGetResources/NuGetPackageFeed2.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.NuGetProvider.Resources; 18 | using Microsoft.PackageManagement.Provider.Utility; 19 | using System; 20 | using System.Linq; 21 | using System.Net.Http; 22 | 23 | /// 24 | /// Implements NuGet v2 package feed. 25 | /// 26 | public class NuGetPackageFeed2 : INuGetPackageFeed 27 | { 28 | private string baseUrl; 29 | private string nugetFindPackageIdQueryFormat; 30 | 31 | public INuGetResourceCollection ResourcesCollection { get; set; } 32 | 33 | public NuGetPackageFeed2(string baseUrl) 34 | { 35 | this.baseUrl = baseUrl; 36 | // if a query is http://www.nuget.org/api/v2 then we add / to the end 37 | if (!this.baseUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase)) 38 | { 39 | this.baseUrl = String.Concat(this.baseUrl, "/"); 40 | } 41 | 42 | //we are constructing the url query like http://www.nuget.org/api/v2/FindPackagesById()?id='JQuery' 43 | this.nugetFindPackageIdQueryFormat = PathUtility.UriCombine(this.baseUrl, NuGetConstant.FindPackagesById); 44 | } 45 | 46 | public NuGetSearchResult Find(NuGetSearchContext findContext, NuGetRequest request) 47 | { 48 | return Find(findContext, new RequestWrapper(request)); 49 | } 50 | 51 | public bool IsAvailable(RequestWrapper request) 52 | { 53 | bool valid = false; 54 | HttpClient client = request.GetClient(); 55 | string queryUri = Constants.DummyPackageId.MakeFindPackageByIdQuery(PathUtility.UriCombine(this.baseUrl, NuGetConstant.FindPackagesById)); 56 | 57 | HttpResponseMessage response = PathUtility.GetHttpResponse(client, queryUri, (() => request.IsCanceled()), 58 | ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg)); 59 | 60 | // The link is not valid 61 | if (response != null && response.IsSuccessStatusCode) 62 | { 63 | valid = true; 64 | } 65 | 66 | return valid; 67 | } 68 | 69 | public NuGetSearchResult Find(NuGetSearchContext findContext, RequestWrapper request) 70 | { 71 | if (string.IsNullOrWhiteSpace(findContext.PackageInfo.Id)) 72 | { 73 | return null; 74 | } 75 | 76 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetPackageFeed2", "FindPackage", findContext.PackageInfo.Id); 77 | 78 | var query = findContext.PackageInfo.Id.MakeFindPackageByIdQuery(this.nugetFindPackageIdQueryFormat); 79 | 80 | var packages = NuGetClient.FindPackage(query, request).Where(package => findContext.PackageInfo.Id.Equals(package.Id, StringComparison.OrdinalIgnoreCase)); 81 | 82 | if (findContext.RequiredVersion != null) 83 | { 84 | //Usually versions has a limited number, ToArray should be ok. 85 | var versions = findContext.RequiredVersion.GetComparableVersionStrings().ToArray(); 86 | packages = packages.Where(package => versions.Contains(package.Version, StringComparer.OrdinalIgnoreCase)); 87 | } 88 | 89 | //Will only enumerate packages once 90 | return findContext.MakeResult(packages); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /NuGetResources/NuGetQueryFeed2.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.NuGetProvider.Resources; 18 | using System; 19 | 20 | /// 21 | /// Implements NuGet v2 query feed. 22 | /// 23 | public class NuGetQueryFeed2 : INuGetQueryFeed 24 | { 25 | private string baseUrl; 26 | 27 | public INuGetResourceCollection ResourcesCollection { get; set; } 28 | 29 | public NuGetQueryFeed2(string baseUrl) 30 | { 31 | this.baseUrl = baseUrl; 32 | if (!this.baseUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase)) 33 | { 34 | this.baseUrl = String.Concat(this.baseUrl, "/"); 35 | } 36 | } 37 | 38 | public bool IsAvailable(RequestWrapper request) => true; 39 | 40 | public NuGetSearchResult Search(NuGetSearchContext searchContext, NuGetRequest nugetRequest) 41 | { 42 | nugetRequest.Debug(Messages.DebugInfoCallMethod, "NuGetSearchFeed2", "Search"); 43 | if (nugetRequest == null) 44 | { 45 | return searchContext.MakeResult(); 46 | } 47 | 48 | return Search(searchContext, new RequestWrapper(nugetRequest)); 49 | } 50 | 51 | public NuGetSearchResult Search(NuGetSearchContext searchContext, RequestWrapper request) 52 | { 53 | request.Debug(Messages.DebugInfoCallMethod, "NuGetSearchFeed2", "Search"); 54 | if (request == null) 55 | { 56 | return searchContext.MakeResult(); 57 | } 58 | 59 | string searchString = this.ResourcesCollection.GetSearchQueryDelegate(searchContext.SearchTerms); 60 | 61 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetSearchFeed2", "Search", searchString); 62 | 63 | var searchQuery = searchString.MakeSearchQuery(this.baseUrl, searchContext.AllowPrerelease, searchContext.AllVersions); 64 | return searchContext.MakeResult(NuGetWebUtility.SendRequest(searchQuery, request)); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /NuGetResources/NuGetRemoteFeedBase.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System; 18 | using System.Collections.Generic; 19 | using System.Threading.Tasks; 20 | 21 | /// 22 | /// Base for any web feed. 23 | /// 24 | public abstract class NuGetRemoteFeedBase : INuGetFeed 25 | { 26 | public IList Endpoints { get; private set; } 27 | 28 | public INuGetResourceCollection ResourcesCollection { get; set; } 29 | 30 | public abstract bool IsAvailable(RequestWrapper request); 31 | 32 | public NuGetRemoteFeedBase() 33 | { 34 | this.Endpoints = new List(); 35 | } 36 | 37 | /// 38 | /// Execute using default retry count and default backoff strategy. 39 | /// 40 | /// Result type 41 | /// Process a given endpoint. 42 | /// Result of executeWithBaseUrl 43 | internal T Execute(Func executeWithBaseUrl) 44 | { 45 | return Execute(executeWithBaseUrl, Constants.DefaultRetryCount, Constants.SimpleBackoffStrategy); 46 | } 47 | 48 | /// 49 | /// Execute a delegate using all known endpoints, retrying times for each endpoint. 50 | /// 51 | /// Result type 52 | /// Process a given endpoint. 53 | /// Retry count 54 | /// Given original wait time between retries, get a new wait time. 55 | /// Result of executeWithBaseUrl 56 | internal T Execute(Func executeWithBaseUrl, int retryCount, Func backoffStrategy) 57 | { 58 | IList allErrors = new List(); 59 | foreach (NuGetServiceInfo endpointCandidate in this.Endpoints) 60 | { 61 | try 62 | { 63 | return SingleExecuteWithRetries(endpointCandidate, executeWithBaseUrl, retryCount, backoffStrategy); 64 | } catch (Exception ex) 65 | { 66 | allErrors.Add(ex); 67 | } 68 | } 69 | 70 | // If we get here, we've tried all services without success 71 | throw new AggregateException(allErrors); 72 | } 73 | 74 | /// 75 | /// Execute a single endpoint. 76 | /// 77 | /// Result type. 78 | /// Endpoint to try 79 | /// Process the endpoint 80 | /// Retry count 81 | /// >Given original wait time between retries, get a new wait time. 82 | /// Result of executeWithBaseUrl 83 | internal T SingleExecuteWithRetries(NuGetServiceInfo endpointInfo, Func executeWithBaseUrl, int retryCount, Func backoffStrategy) 84 | { 85 | int sleepInMs = 0; 86 | // I don't think there's a huge penalty to collecting an individual service's errors over the course of the retries, and it could be helpful for debugging 87 | IList allErrors = new List(); 88 | while (retryCount-- > 0) 89 | { 90 | try 91 | { 92 | return executeWithBaseUrl(endpointInfo.Url); 93 | } 94 | catch (Exception ex) 95 | { 96 | allErrors.Add(ex); 97 | } 98 | 99 | // If we get here, the previous attempt has failed. Recalculate the sleep time and wait. 100 | if (retryCount > 0) 101 | { 102 | sleepInMs = backoffStrategy(sleepInMs); 103 | Task.Delay(sleepInMs).Wait(); 104 | } 105 | } 106 | 107 | // If we get here, we've tried {retryCount} times without success 108 | throw new AggregateException(allErrors); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /NuGetResources/NuGetResourceCollection2.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System; 18 | using System.Collections.Generic; 19 | using System.Linq; 20 | 21 | /// 22 | /// Collection of NuGet v2 resources. 23 | /// 24 | public class NuGetResourceCollection2 : NuGetResourceCollectionBase 25 | { 26 | private NuGetResourceCollection2() { } 27 | 28 | public INuGetResourceCollection ResourcesCollection { get; set; } 29 | 30 | public static NuGetResourceCollection2 Make(string baseUrl) 31 | { 32 | NuGetResourceCollection2 collection = new NuGetResourceCollection2(); 33 | if (baseUrl != null) 34 | { 35 | collection.PackagesFeed = new NuGetPackageFeed2(baseUrl); 36 | collection.QueryFeed = new NuGetQueryFeed2(baseUrl); 37 | collection.FilesFeed = new NuGetFilesFeed2(); 38 | } 39 | 40 | collection.GetSearchQueryDelegate = (terms) => 41 | { 42 | string searchString = String.Empty; 43 | IEnumerable tagTerms = terms.Where(st => st.Term == NuGetSearchTerm.NuGetSearchTermType.Tag); 44 | NuGetSearchTerm searchTerm = terms.Where(st => st.Term == NuGetSearchTerm.NuGetSearchTermType.SearchTerm).FirstOrDefault(); 45 | if (searchTerm != null) 46 | { 47 | searchString = searchTerm.Text; 48 | } 49 | 50 | searchString = terms.Where(st => st.Term == NuGetSearchTerm.NuGetSearchTermType.Tag) 51 | .Aggregate(searchString, (current, tag) => current + " tag:" + tag.Text); 52 | 53 | return searchString; 54 | }; 55 | 56 | return collection; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /NuGetResources/NuGetResourceCollection3.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.NuGetProvider.Resources; 18 | using Microsoft.PackageManagement.Provider.Utility; 19 | using System; 20 | using System.Collections.Generic; 21 | 22 | /// 23 | /// Collection of NuGet v3 resources. 24 | /// 25 | public class NuGetResourceCollection3 : NuGetResourceCollectionBase 26 | { 27 | private NuGetResourceCollection3() { } 28 | 29 | public INuGetResourceCollection ResourcesCollection { get; set; } 30 | 31 | public static NuGetResourceCollection3 Make(dynamic root, string baseUrl, RequestWrapper request) 32 | { 33 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetResourceCollection3", "Make", baseUrl); 34 | NuGetResourceCollection3 collection = new NuGetResourceCollection3(); 35 | Dictionary currentServiceMap = new Dictionary(); 36 | foreach (dynamic resourceElement in root.resources) 37 | { 38 | NuGetServiceInfo serviceInfo = NuGetServiceInfo.GetV3Endpoint(resourceElement); 39 | if (serviceInfo == null) 40 | { 41 | continue; 42 | } 43 | 44 | bool serviceUsed = currentServiceMap.ContainsKey(serviceInfo.Type) && currentServiceMap[serviceInfo.Type].Preference <= serviceInfo.Preference; 45 | bool serviceSupplement = currentServiceMap.ContainsKey(serviceInfo.Type) && currentServiceMap[serviceInfo.Type].Preference == serviceInfo.Preference; 46 | switch (serviceInfo.Type) 47 | { 48 | case NuGetServiceType.AutoComplete: 49 | // No feed yet OR no version (lowest possible stable version) OR greater version 50 | if (serviceUsed || collection.AutoCompleteFeed == null) 51 | { 52 | serviceUsed = true; 53 | if (serviceSupplement) 54 | { 55 | ((NuGetAutoCompleteFeed3)collection.AutoCompleteFeed).Endpoints.Add(serviceInfo); 56 | } 57 | else 58 | { 59 | collection.AutoCompleteFeed = new NuGetAutoCompleteFeed3(serviceInfo); 60 | } 61 | } 62 | 63 | break; 64 | case NuGetServiceType.Registrations: 65 | if (serviceUsed || collection.PackagesFeed == null) 66 | { 67 | serviceUsed = true; 68 | if (serviceSupplement) 69 | { 70 | ((NuGetPackageFeed3)collection.PackagesFeed).Endpoints.Add(serviceInfo); 71 | } 72 | else 73 | { 74 | collection.PackagesFeed = new NuGetPackageFeed3(serviceInfo); 75 | } 76 | } 77 | 78 | break; 79 | case NuGetServiceType.Query: 80 | if (serviceUsed || collection.QueryFeed == null) 81 | { 82 | serviceUsed = true; 83 | if (serviceSupplement) 84 | { 85 | ((NuGetQueryFeed3)collection.QueryFeed).Endpoints.Add(serviceInfo); 86 | } 87 | else 88 | { 89 | collection.QueryFeed = new NuGetQueryFeed3(serviceInfo); 90 | } 91 | } 92 | 93 | break; 94 | case NuGetServiceType.Files: 95 | if (serviceUsed || collection.FilesFeed == null) 96 | { 97 | serviceUsed = true; 98 | collection.FilesFeed = new NuGetFilesFeed3(serviceInfo.Url); 99 | } 100 | 101 | break; 102 | case NuGetServiceType.ReportAbuse: 103 | if (serviceUsed || collection.AbuseFeed == null) 104 | { 105 | serviceUsed = true; 106 | collection.AbuseFeed = new NuGetAbuseFeed3(serviceInfo.Url); 107 | } 108 | 109 | break; 110 | } 111 | 112 | if (serviceUsed) 113 | { 114 | request.Debug(Messages.NuGetEndpointDiscovered, serviceInfo.Type, serviceInfo.Url); 115 | if (!serviceSupplement) 116 | { 117 | currentServiceMap[serviceInfo.Type] = serviceInfo; 118 | } 119 | } 120 | } 121 | 122 | collection.GetSearchQueryDelegate = (searchTerms) => 123 | { 124 | string searchString = String.Empty; 125 | // TODO: encode search terms? 126 | foreach (NuGetSearchTerm searchTerm in searchTerms) 127 | { 128 | switch (searchTerm.Term) 129 | { 130 | case NuGetSearchTerm.NuGetSearchTermType.SearchTerm: 131 | searchString += searchTerm.Text; 132 | break; 133 | case NuGetSearchTerm.NuGetSearchTermType.Tag: 134 | HttpQueryBuilder tQb = new HttpQueryBuilder().Add(Constants.TagQueryParam, searchTerm.Text, separator: ":", encode: false); 135 | searchString += " " + tQb.ToQueryString(); 136 | break; 137 | case NuGetSearchTerm.NuGetSearchTermType.Contains: 138 | HttpQueryBuilder cQb = new HttpQueryBuilder().Add(Constants.DescriptionQueryParam, searchTerm.Text, separator: ":", encode: false); 139 | searchString += " " + cQb.ToQueryString(); 140 | break; 141 | default: 142 | break; 143 | } 144 | } 145 | 146 | return searchString.Trim(); 147 | }; 148 | 149 | collection.PackageConverter = new PackageBaseConverter(); 150 | collection.PackageDependencyConverter = new PackageDependencyConverter(); 151 | collection.PackageDependencySetConverter = new DependencyGroupConverter(); 152 | collection.CatalogUrlConverter = new CatalogUrlConverter(); 153 | Uri uri = new Uri(baseUrl); 154 | if (uri.Host.Contains(Constants.NuGetOrgHost)) 155 | { 156 | collection.GalleryFeed = new NuGetGalleryFeedOrg(); 157 | } else if (uri.Host.Contains(Constants.MyGetOrgHost)) 158 | { 159 | collection.GalleryFeed = new NuGetGalleryFeedMyGet(baseUrl); 160 | } 161 | 162 | request.Debug(Messages.DebugInfoReturnCall, "NuGetResourceCollection3", "Make"); 163 | return collection; 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /NuGetResources/NuGetResourceCollectionBase.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | /// 21 | /// Helps tie INuGetResources and their INuGetResourceCollection property to this collection. 22 | /// 23 | public class NuGetResourceCollectionBase : INuGetResourceCollection 24 | { 25 | private INuGetPackageFeed packagesFeed = null; 26 | private INuGetQueryFeed queryFeed = null; 27 | private INuGetFilesFeed filesFeed = null; 28 | private INuGetAbuseFeed abuseFeed = null; 29 | private INuGetGalleryFeed galleryFeed = null; 30 | private INuGetAutoCompleteFeed autoCompleteFeed = null; 31 | private IDynamicJsonObjectConverter catalogUrlConverter = null; 32 | private IDynamicJsonObjectConverter packageConverter = null; 33 | private IDynamicJsonObjectConverter packageDependencyConverter = null; 34 | private IDynamicJsonObjectConverter packageDependencySetConverter = null; 35 | 36 | public INuGetPackageFeed PackagesFeed 37 | { 38 | get 39 | { 40 | return packagesFeed; 41 | } 42 | protected set 43 | { 44 | packagesFeed = value; 45 | SetParentCollection(packagesFeed); 46 | } 47 | } 48 | 49 | public INuGetQueryFeed QueryFeed 50 | { 51 | get 52 | { 53 | return queryFeed; 54 | } 55 | protected set 56 | { 57 | queryFeed = value; 58 | SetParentCollection(queryFeed); 59 | } 60 | } 61 | 62 | public INuGetFilesFeed FilesFeed 63 | { 64 | get 65 | { 66 | return filesFeed; 67 | } 68 | protected set 69 | { 70 | filesFeed = value; 71 | SetParentCollection(filesFeed); 72 | } 73 | } 74 | 75 | public INuGetAbuseFeed AbuseFeed 76 | { 77 | get 78 | { 79 | return abuseFeed; 80 | } 81 | protected set 82 | { 83 | abuseFeed = value; 84 | SetParentCollection(abuseFeed); 85 | } 86 | } 87 | 88 | public INuGetGalleryFeed GalleryFeed 89 | { 90 | get 91 | { 92 | return galleryFeed; 93 | } 94 | protected set 95 | { 96 | galleryFeed = value; 97 | SetParentCollection(galleryFeed); 98 | } 99 | } 100 | 101 | public INuGetAutoCompleteFeed AutoCompleteFeed 102 | 103 | { 104 | get 105 | { 106 | return autoCompleteFeed; 107 | } 108 | protected set 109 | { 110 | autoCompleteFeed = value; 111 | SetParentCollection(autoCompleteFeed); 112 | } 113 | } 114 | 115 | public IDynamicJsonObjectConverter CatalogUrlConverter 116 | { 117 | get 118 | { 119 | return catalogUrlConverter; 120 | } 121 | protected set 122 | { 123 | catalogUrlConverter = value; 124 | SetParentCollection(catalogUrlConverter); 125 | } 126 | } 127 | 128 | public IDynamicJsonObjectConverter PackageConverter 129 | { 130 | get 131 | { 132 | return packageConverter; 133 | } 134 | protected set 135 | { 136 | packageConverter = value; 137 | SetParentCollection(packageConverter); 138 | } 139 | } 140 | 141 | public IDynamicJsonObjectConverter PackageDependencyConverter 142 | { 143 | get 144 | { 145 | return packageDependencyConverter; 146 | } 147 | protected set 148 | { 149 | packageDependencyConverter = value; 150 | SetParentCollection(packageDependencyConverter); 151 | } 152 | } 153 | 154 | public IDynamicJsonObjectConverter PackageDependencySetConverter 155 | { 156 | get 157 | { 158 | return packageDependencySetConverter; 159 | } 160 | protected set 161 | { 162 | packageDependencySetConverter = value; 163 | SetParentCollection(packageDependencySetConverter); 164 | } 165 | } 166 | 167 | public Func, string> GetSearchQueryDelegate { get; protected set; } 168 | 169 | private void SetParentCollection(INuGetResource resource) 170 | { 171 | if (resource != null) 172 | { 173 | resource.ResourcesCollection = this; 174 | } 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /NuGetResources/NuGetResourceCollectionFactory.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.Provider.Utility; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.IO; 21 | using System.Net.Http; 22 | 23 | /// 24 | /// Creates the correct INuGetResourceCollection 25 | /// 26 | public class NuGetResourceCollectionFactory 27 | { 28 | // Simple dictionary to keep track of already-parsed base URLs. PackageManagement does this parse an excessive number of times. No reason to persist this past the session. 29 | private static Dictionary sessionResourceCollectionCache = new Dictionary(); 30 | private static Dictionary sessionResourceCollectionCacheLocks = new Dictionary(); 31 | 32 | private NuGetResourceCollectionFactory() { } 33 | 34 | /// 35 | /// Gets all feeds discovered from the NuGet base URL. 36 | /// v2 example: nuget.org/api/v2 37 | /// v3 example: api.nuget.org/v3/index.json 38 | /// 39 | /// NuGet base URL. 40 | /// Current request 41 | /// All NuGet feeds discovered from the base URL. Exceptions thrown on invalid base URL. 42 | public static INuGetResourceCollection GetResources(string baseUrl, NuGetRequest request) 43 | { 44 | return GetResources(baseUrl, new RequestWrapper(request)); 45 | } 46 | 47 | public static INuGetResourceCollection GetResources(string baseUrl, RequestWrapper request) 48 | { 49 | object cacheLock; 50 | if (String.IsNullOrEmpty(baseUrl)) 51 | { 52 | return NuGetResourceCollectionLocal.Make(); 53 | } 54 | 55 | if (!sessionResourceCollectionCacheLocks.ContainsKey(baseUrl)) 56 | { 57 | lock (sessionResourceCollectionCacheLocks) 58 | { 59 | if (!sessionResourceCollectionCacheLocks.ContainsKey(baseUrl)) 60 | { 61 | sessionResourceCollectionCacheLocks[baseUrl] = new object(); 62 | } 63 | } 64 | } 65 | 66 | cacheLock = sessionResourceCollectionCacheLocks[baseUrl]; 67 | 68 | lock (cacheLock) 69 | { 70 | if (!sessionResourceCollectionCache.ContainsKey(baseUrl)) 71 | { 72 | sessionResourceCollectionCache[baseUrl] = GetResourcesImpl(baseUrl, request); 73 | } 74 | } 75 | 76 | return sessionResourceCollectionCache[baseUrl]; 77 | } 78 | 79 | private static INuGetResourceCollection GetResourcesImpl(string baseUrl, RequestWrapper request) 80 | { 81 | INuGetResourceCollection res = null; 82 | HttpClient client = request.GetClientWithHeaders(); 83 | HttpResponseMessage response = PathUtility.GetHttpResponse(client, baseUrl, (() => request.IsCanceled()), 84 | ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg)); 85 | if (!response.IsSuccessStatusCode) 86 | { 87 | throw new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed); 88 | } 89 | 90 | string content = new StreamReader(NuGetClient.DownloadDataToStream(baseUrl, request)).ReadToEnd(); 91 | // If the response starts with the magic XML header, it's v2 92 | if (content.StartsWith(Constants.XmlStartContent)) 93 | { 94 | res = NuGetResourceCollection2.Make(baseUrl); 95 | } 96 | else 97 | { 98 | try 99 | { 100 | dynamic root = DynamicJsonParser.Parse(content); 101 | string version = root.version; 102 | if (version != null && version.StartsWith("3.")) 103 | { 104 | // v3 feed 105 | res = NuGetResourceCollection3.Make(root, baseUrl, request); 106 | } 107 | } 108 | catch (Exception ex) 109 | { 110 | Exception discoveryException = new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed, ex); 111 | throw discoveryException; 112 | } 113 | } 114 | 115 | if (res == null) 116 | { 117 | // Couldn't figure out what this is 118 | throw new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed); 119 | } 120 | 121 | return res; 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /NuGetResources/NuGetResourceCollectionLocal.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Contains local repository resources. 19 | /// 20 | public class NuGetResourceCollectionLocal : NuGetResourceCollectionBase 21 | { 22 | private NuGetResourceCollectionLocal() { } 23 | 24 | public static NuGetResourceCollectionLocal Make() 25 | { 26 | NuGetResourceCollectionLocal collection = new NuGetResourceCollectionLocal(); 27 | NuGetLocalPackageFeed localPackageFeed = new NuGetLocalPackageFeed(); 28 | collection.PackagesFeed = localPackageFeed; 29 | collection.FilesFeed = localPackageFeed; 30 | // Use the v2 search syntax 31 | collection.GetSearchQueryDelegate = NuGetResourceCollection2.Make(null).GetSearchQueryDelegate; 32 | 33 | return collection; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /NuGetResources/NuGetServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.Provider.Utility; 18 | using System; 19 | using System.Collections.Generic; 20 | 21 | /// 22 | /// Parse and store a NuGet endpoint. 23 | /// 24 | public class NuGetServiceInfo 25 | { 26 | /// 27 | /// Maps known @type values to preference attributes. New @type values should be added only after testing. 28 | /// 29 | private static readonly Dictionary KnownServiceTypeStrings = new Dictionary() 30 | { 31 | { "searchqueryservice", new NuGetServiceInfo(NuGetServiceType.Query, 0) }, 32 | { "searchqueryservice/3.0.0-beta", new NuGetServiceInfo(NuGetServiceType.Query, 1) }, 33 | { "searchqueryservice/3.0.0-rc", new NuGetServiceInfo(NuGetServiceType.Query, 2) }, 34 | 35 | { "searchautocompleteservice", new NuGetServiceInfo(NuGetServiceType.AutoComplete, 0) }, 36 | { "searchautocompleteservice/3.0.0-beta", new NuGetServiceInfo(NuGetServiceType.AutoComplete, 1) }, 37 | { "searchautocompleteservice/3.0.0-rc", new NuGetServiceInfo(NuGetServiceType.AutoComplete, 2) }, 38 | 39 | { "registrationsbaseurl", new NuGetServiceInfo(NuGetServiceType.Registrations, 0) }, 40 | { "registrationsbaseurl/versioned", new NuGetServiceInfo(NuGetServiceType.Registrations, 1) }, // not sure if this will change versions or not, since it uses clientversion property, so it's low in priority 41 | { "registrationsbaseurl/3.0.0-beta", new NuGetServiceInfo(NuGetServiceType.Registrations, 2) }, 42 | { "registrationsbaseurl/3.4.0", new NuGetServiceInfo(NuGetServiceType.Registrations, 3) }, 43 | { "registrationsbaseurl/3.6.0", new NuGetServiceInfo(NuGetServiceType.Registrations, 4) }, 44 | 45 | { "packagebaseaddress/3.0.0", new NuGetServiceInfo(NuGetServiceType.Files, 0) }, 46 | 47 | { "reportabuseuritemplate/3.0.0-beta", new NuGetServiceInfo(NuGetServiceType.ReportAbuse, 0) }, 48 | { "reportabuseuritemplate/3.0.0-rc", new NuGetServiceInfo(NuGetServiceType.ReportAbuse, 1) }, 49 | }; 50 | 51 | /// 52 | /// Gets or sets the service URL. Can be templated if that's how it was given to us by the service index. 53 | /// 54 | public string Url { get; set; } 55 | 56 | /// 57 | /// Gets the type of service. 58 | /// 59 | public NuGetServiceType Type { get; private set; } 60 | 61 | /// 62 | /// Gets the preference flag. Higher means more preferred. 63 | /// 64 | public int Preference { get; private set; } 65 | 66 | public NuGetServiceInfo(string serviceUrl, NuGetServiceType type, int preference) 67 | { 68 | this.Url = serviceUrl; 69 | this.Type = type; 70 | this.Preference = preference; 71 | } 72 | 73 | public NuGetServiceInfo(NuGetServiceType type, int preference) : this(null, type, preference) 74 | { 75 | } 76 | 77 | /// 78 | /// Extract a NuGet v3 endpoint from the service's entry root in NuGet v3's service index 79 | /// 80 | public static NuGetServiceInfo GetV3Endpoint(dynamic serviceEntryRoot) 81 | { 82 | string typeName, serviceUrl; 83 | typeName = serviceUrl = null; 84 | if (serviceEntryRoot.Metadata.HasProperty("type")) 85 | { 86 | typeName = serviceEntryRoot.Metadata.type.ToLowerInvariant(); 87 | } 88 | 89 | if (serviceEntryRoot.Metadata.HasProperty("id")) 90 | { 91 | serviceUrl = serviceEntryRoot.Metadata.id; 92 | } 93 | 94 | if (KnownServiceTypeStrings.ContainsKey(typeName)) 95 | { 96 | NuGetServiceInfo templateServiceInfo = KnownServiceTypeStrings[typeName]; 97 | return new NuGetServiceInfo(serviceUrl, templateServiceInfo.Type, templateServiceInfo.Preference); 98 | } 99 | 100 | return null; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /NuGetResources/NuGetServiceType.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Types of NuGet services. 19 | /// 20 | public enum NuGetServiceType 21 | { 22 | Query, 23 | Files, 24 | Registrations, 25 | AutoComplete, 26 | ReportAbuse 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /NugetLightConstant.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Microsoft.PackageManagement.NuGetProvider 3 | { 4 | using System; 5 | 6 | public static class NuGetConstant 7 | { 8 | /// 9 | /// Represents the ".nupkg" extension. 10 | /// 11 | public static readonly string PackageExtension = ".nupkg"; 12 | 13 | /// 14 | /// Represents the ".nuspec" extension. 15 | /// 16 | public static readonly string ManifestExtension = ".nuspec"; 17 | 18 | /// 19 | /// Represents the default nuget uri 20 | /// 21 | public static readonly string NugetSite = "www.nuget.org"; 22 | 23 | /// 24 | /// Name of this provider 25 | /// 26 | public static readonly string ProviderName = "NuGet"; 27 | 28 | /// 29 | /// Version of this provider 30 | /// 31 | public static readonly string ProviderVersion = "3.0.0.1"; 32 | 33 | /// 34 | /// Represents a method that the V2 web service supports to find a package 35 | /// 36 | public static readonly string FindPackagesById= "/FindPackagesById()?id='{0}'"; 37 | 38 | /// 39 | /// Represents how many packages to be returned by an api call 40 | /// 41 | public static readonly string SkipAndTop = "&$skip={0}&$top={1}"; 42 | 43 | /// 44 | /// Represents a method that the V2 web service supports to search packages 45 | /// 46 | public static readonly string SearchTerm = "&searchTerm='{0}'&targetFramework=''&includePrerelease={1}"; 47 | 48 | /// 49 | /// Represents a method that the V2 web service supports to search packages with filtering 50 | /// 51 | public static readonly string SearchFilterAllVersions = "Search()?$orderby=DownloadCount%20desc,Id"; 52 | 53 | /// 54 | /// Represents a method that the V2 web service supports to search packages with filtering. The result returned is already 55 | /// sorted by download count. 56 | /// 57 | public static readonly string SearchFilter = "Search()?$filter=IsLatestVersion"; 58 | 59 | 60 | /// 61 | /// Config file storing the info as a result of registering a package source 62 | /// 63 | public static readonly string SettingsFileName = "nuget.config"; 64 | 65 | /// 66 | /// The magic unpublished date is 1900-01-01T00:00:00. This is from NugetCore 67 | /// 68 | public static readonly DateTimeOffset Unpublished = new DateTimeOffset(1900, 1, 1, 0, 0, 0, TimeSpan.FromHours(-8)); 69 | } 70 | } -------------------------------------------------------------------------------- /Package/IPackage.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | public interface IPackage : IPackageName 7 | { 8 | //NugetClient:IPackage 9 | Uri ReportAbuseUrl { get; } 10 | Uri LicenseReportUrl { get; } 11 | long DownloadCount { get; } 12 | long PackageSize { get; } 13 | long VersionDownloadCount { get; } 14 | bool IsAbsoluteLatestVersion { get; } 15 | bool IsLatestVersion { get; } 16 | bool Listed { get; } 17 | DateTimeOffset? Published { get; } 18 | DateTimeOffset? Created { get; } 19 | DateTimeOffset? LastUpdated { get; } 20 | DateTimeOffset? LastEdited { get; } 21 | string FullFilePath { get; set; } 22 | 23 | //NugetClient:IPackageMetadata 24 | string Title { get; } 25 | IEnumerable Authors { get; } 26 | IEnumerable Owners { get; } 27 | Uri IconUrl { get; } 28 | Uri LicenseUrl { get;} 29 | Uri ProjectUrl { get; } 30 | Uri GalleryDetailsUrl { get; } 31 | bool RequireLicenseAcceptance { get; } 32 | bool DevelopmentDependency { get; } 33 | string LicenseNames { get; } 34 | string Description { get; } 35 | string Summary { get; } 36 | string ContentSrcUrl { get;} 37 | string ReleaseNotes { get; } 38 | string Language { get; } 39 | string Tags { get; } 40 | string Copyright { get; } 41 | Version MinClientVersion { get; } 42 | List DependencySetList { get; } 43 | string PackageHash { get; } 44 | string PackageHashAlgorithm { get; } 45 | bool IsPrerelease { get; } 46 | } 47 | } -------------------------------------------------------------------------------- /Package/IPackageName.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | using Microsoft.PackageManagement.Provider.Utility; 4 | public interface IPackageName 5 | { 6 | string Id { get; } 7 | SemanticVersion Version { get; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Package/PackageBase.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using Microsoft.PackageManagement.Provider.Utility; 7 | 8 | public class PackageBase : IPackage 9 | { 10 | private long _downloadCount = -1; 11 | private long _versionDownloadCount = -1; 12 | private long _packageSize = -1; 13 | 14 | public PackageBase() 15 | { 16 | AdditionalProperties = new Dictionary(); 17 | } 18 | 19 | string IPackageName.Id 20 | { 21 | get 22 | { 23 | return Id; 24 | } 25 | } 26 | 27 | SemanticVersion IPackageName.Version 28 | { 29 | get 30 | { 31 | if (Version != null) 32 | { 33 | return new SemanticVersion(Version); 34 | } 35 | return null; 36 | } 37 | } 38 | 39 | public bool IsAbsoluteLatestVersion { get; set; } 40 | 41 | public bool IsLatestVersion { get; set;} 42 | 43 | public bool Listed{ get; set;} 44 | 45 | public string FullFilePath { get; set; } 46 | 47 | public DateTimeOffset? Published { get; set;} 48 | 49 | public DateTimeOffset? Created { get; set; } 50 | 51 | public DateTimeOffset? LastUpdated { get; set; } 52 | 53 | public DateTimeOffset? LastEdited { get; set; } 54 | 55 | public string Title{ get; set;} 56 | 57 | public Uri IconUrl{ get; set;} 58 | 59 | public Uri LicenseUrl{ get; set;} 60 | 61 | public Uri ProjectUrl{ get; set;} 62 | 63 | public Uri GalleryDetailsUrl { get; set; } 64 | 65 | public bool RequireLicenseAcceptance{ get; set;} 66 | 67 | public bool DevelopmentDependency{ get; set;} 68 | 69 | public string Description{ get; set;} 70 | 71 | public string Summary{ get; set;} 72 | 73 | public string ContentSrcUrl { get; set; } 74 | 75 | public string ReleaseNotes{ get; set;} 76 | 77 | public string Language{ get; set;} 78 | 79 | public string Tags{ get; set;} 80 | 81 | public string Copyright{ get; set;} 82 | 83 | public string LicenseNames { get; set; } 84 | 85 | public Version MinClientVersion{ get; set;} 86 | 87 | public long DownloadCount 88 | { 89 | get 90 | { 91 | return _downloadCount; 92 | } 93 | set 94 | { 95 | _downloadCount = value; 96 | } 97 | } 98 | 99 | public Uri ReportAbuseUrl{ get; set; } 100 | 101 | public Uri LicenseReportUrl { get; set; } 102 | 103 | public long VersionDownloadCount 104 | { 105 | get 106 | { 107 | return _versionDownloadCount; 108 | } 109 | set 110 | { 111 | _versionDownloadCount = value; 112 | } 113 | } 114 | 115 | public long PackageSize 116 | { 117 | get 118 | { 119 | return _packageSize; 120 | } 121 | set 122 | { 123 | _packageSize = value; 124 | } 125 | } 126 | 127 | IEnumerable IPackage.Authors 128 | { 129 | get 130 | { 131 | if (String.IsNullOrWhiteSpace(Authors)) 132 | { 133 | return Enumerable.Empty(); 134 | } 135 | return Authors.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); 136 | } 137 | } 138 | 139 | IEnumerable IPackage.Owners 140 | { 141 | get 142 | { 143 | if (String.IsNullOrWhiteSpace(Owners)) 144 | { 145 | return Enumerable.Empty(); 146 | } 147 | return Owners.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); 148 | } 149 | } 150 | 151 | internal string Id { get; set; } 152 | 153 | internal string Version { get; set; } 154 | 155 | internal string Authors { get; set; } 156 | 157 | internal string Owners { get; set; } 158 | 159 | public string GetFullName() 160 | { 161 | return Id + " " + Version; 162 | } 163 | 164 | public List DependencySetList { get; set; } 165 | 166 | public string PackageHashAlgorithm { get; set; } 167 | 168 | public string PackageHash { get; set; } 169 | 170 | public Dictionary AdditionalProperties { get; set; } 171 | public bool IsPrerelease { get; set; } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /Package/PackageDependency.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.PackageManagement.Provider.Utility; 7 | 8 | namespace Microsoft.PackageManagement.NuGetProvider 9 | { 10 | /// 11 | /// This class represents PackageDependency 12 | /// 13 | public sealed class PackageDependency 14 | { 15 | /// 16 | /// Name of the dependency 17 | /// 18 | public string Id { get; set; } 19 | 20 | /// 21 | /// The dependency version required. this may include min and max version 22 | /// 23 | public DependencyVersion DependencyVersion { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Package/PackageDependencySet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.PackageManagement.NuGetProvider 8 | { 9 | /// 10 | /// This class represents a set of dependencies within a framework 11 | /// 12 | public sealed class PackageDependencySet 13 | { 14 | /// 15 | /// The target framework of this dependency set 16 | /// 17 | public string TargetFramework { get; set; } 18 | 19 | /// 20 | /// The list of dependencies 21 | /// 22 | public List Dependencies { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Package/PackageItem.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | 7 | internal class PackageItem 8 | { 9 | private string _fullPath; 10 | 11 | internal IPackage Package { get; set; } 12 | 13 | internal PackageSource PackageSource { get; set; } 14 | 15 | internal string FastPath { get; set; } 16 | 17 | internal bool IsPackageFile { get; set; } 18 | 19 | internal string[] Sources { get; set; } 20 | 21 | internal string Id 22 | { 23 | get 24 | { 25 | if (Package != null) 26 | { 27 | return Package.Id; 28 | } 29 | return null; 30 | } 31 | 32 | } 33 | 34 | internal string InstalledDirectory 35 | { 36 | get 37 | { 38 | try 39 | { 40 | // if this package file is in a folder with the same name, 41 | // we'll consider that 'installed' 42 | if (IsPackageFile) 43 | { 44 | var dir = Path.GetDirectoryName(PackageSource.Location); 45 | if (!string.IsNullOrWhiteSpace(dir)) 46 | { 47 | var dirName = Path.GetFileName(dir); 48 | var name = Path.GetFileNameWithoutExtension(PackageSource.Location); 49 | 50 | //There is a case where we keep .nuspec 51 | //c:\...\jQuery.2.1.4 52 | // jQuery.nuspec 53 | //dirName = jQuery.2.1.4 54 | //name = jQuery 55 | //conduct case insensitive comparison between name and dirName 56 | if (!string.IsNullOrEmpty(name) && (dirName.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0) && Directory.Exists(dir)) 57 | { 58 | return dir; 59 | } 60 | } 61 | } 62 | } 63 | catch 64 | { 65 | } 66 | return null; 67 | } 68 | } 69 | 70 | internal bool IsInstalled 71 | { 72 | get 73 | { 74 | return !string.IsNullOrWhiteSpace(InstalledDirectory); 75 | } 76 | } 77 | 78 | internal string Version 79 | { 80 | get 81 | { 82 | if ((Package != null) && (Package.Version != null)) 83 | { 84 | return Package.Version.ToString(); 85 | } 86 | return null; 87 | } 88 | } 89 | 90 | //internal string FullName 91 | //{ 92 | // get 93 | // { 94 | // if (Package != null) 95 | // { 96 | // return Package.GetFullName(); 97 | // } 98 | 99 | // return string.Format("{0}.{1}", Id, Version); 100 | // } 101 | //} 102 | 103 | internal string PackageFilename 104 | { 105 | get 106 | { 107 | if (IsPackageFile) 108 | { 109 | return Path.GetFileName(PackageSource.Location); 110 | } 111 | 112 | return Id + "." + Version + NuGetConstant.PackageExtension; 113 | } 114 | } 115 | 116 | internal string FullPath 117 | { 118 | get 119 | { 120 | if (IsPackageFile) 121 | { 122 | return Path.GetFileName(PackageSource.Location); 123 | } 124 | return _fullPath; 125 | } 126 | set 127 | { 128 | _fullPath = value; 129 | } 130 | } 131 | } 132 | 133 | //Comparer for packages using version and id 134 | internal class PackageItemComparer : IEqualityComparer 135 | { 136 | public bool Equals(PackageItem packageOne, PackageItem packageTwo) 137 | { 138 | return String.Equals(packageOne.Id, packageTwo.Id, StringComparison.OrdinalIgnoreCase) && String.Equals(packageOne.Version, packageTwo.Version, StringComparison.OrdinalIgnoreCase); 139 | } 140 | 141 | public int GetHashCode(PackageItem obj) 142 | { 143 | return (String.IsNullOrWhiteSpace(obj.Id) ? String.Empty : obj.Id).GetHashCode() * 31 144 | + (String.IsNullOrWhiteSpace(obj.Version) ? String.Empty : obj.Version).GetHashCode(); 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /Package/PackageName.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | using System; 4 | using Microsoft.PackageManagement.Provider.Utility; 5 | 6 | public class PackageName : IPackageName, IEquatable 7 | { 8 | private readonly string _packageId; 9 | private readonly SemanticVersion _version; 10 | 11 | public PackageName(string packageId, SemanticVersion version) 12 | { 13 | _packageId = packageId; 14 | _version = version; 15 | } 16 | 17 | public string Id 18 | { 19 | get { return _packageId; } 20 | } 21 | 22 | public SemanticVersion Version 23 | { 24 | get 25 | { 26 | return _version; 27 | } 28 | } 29 | 30 | public string Name 31 | { 32 | get 33 | { 34 | return _packageId + "." + _version; 35 | } 36 | } 37 | 38 | public bool Equals(PackageName other) 39 | { 40 | if (other == null) { 41 | return ReferenceEquals(_packageId, null); 42 | } 43 | 44 | return _packageId.Equals(other._packageId, StringComparison.OrdinalIgnoreCase) && 45 | _version.Equals(other._version); 46 | } 47 | 48 | public override int GetHashCode() 49 | { 50 | return _packageId.GetHashCode() * 3137 + _version.GetHashCode(); 51 | } 52 | 53 | public override string ToString() 54 | { 55 | return _packageId + " " + _version; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /PackageSource.cs: -------------------------------------------------------------------------------- 1 |  2 | using Microsoft.PackageManagement.Provider.Utility; 3 | 4 | namespace Microsoft.PackageManagement.NuGetProvider 5 | { 6 | using System; 7 | using System.IO; 8 | 9 | internal class PackageSource 10 | { 11 | private IPackageRepository _repository; 12 | 13 | //Parameters must be filled in during the instantiation. 14 | 15 | internal string Name { get; set; } 16 | 17 | internal string Location { get; set; } 18 | 19 | internal bool Trusted { get; set; } 20 | 21 | internal bool IsRegistered { get; set; } 22 | 23 | internal bool IsValidated { get; set; } 24 | 25 | internal NuGetRequest Request { get; set; } 26 | 27 | internal IPackageRepository Repository 28 | { 29 | get 30 | { 31 | if (!IsSourceAFile) 32 | { 33 | return _repository ?? (_repository = PackageRepositoryFactory.Default.CreateRepository(new PackageRepositoryCreateParameters(Location, Request))); 34 | } 35 | return null; 36 | } 37 | } 38 | 39 | internal bool IsSourceAFile 40 | { 41 | get 42 | { 43 | try 44 | { 45 | if (!string.IsNullOrWhiteSpace(Location) && ((!Uri.IsWellFormedUriString(Location, UriKind.Absolute) || new Uri(Location).IsFile) && File.Exists(Location))) 46 | { 47 | return true; 48 | } 49 | } 50 | catch 51 | { 52 | // no worries. 53 | } 54 | return false; 55 | } 56 | } 57 | 58 | internal string Serialized 59 | { 60 | get 61 | { 62 | if (IsRegistered && !string.IsNullOrWhiteSpace(Name)) 63 | { 64 | return Name.ToBase64(); 65 | } 66 | 67 | return Location.ToBase64(); 68 | } 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Microsoft.PackageManagement.NuGetProvider")] 9 | [assembly: AssemblyDescription("NuGet Provider for OneGet")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft Corporation")] 12 | [assembly: AssemblyProduct("Microsoft.PackageManagement.NuGetProvider")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9e5b0990-975f-4033-b98b-3e81dfecacf4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("3.0.0.2")] 33 | [assembly: AssemblyFileVersion("3.0.0.2")] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![Build status](https://ci.appveyor.com/api/projects/status/vd65p4kpgi0pvto5?svg=true)](https://ci.appveyor.com/project/jianyunt/nugetprovider) 3 | 4 | 5 | NuGet provider 6 | ============== 7 | 8 | NuGetProvider is a OneGet (PackageManagement) provider. 9 | It primarily supports finding and installing packages from [NuGet.org][nugetorg]. 10 | It is also used by [PowerShellGet][psget] for finding and installing PowerShell modules from [PowerShellGallery][psgallery]. 11 | 12 | It supports FullCLR and CoreCLR, meaning works for Windows, Linux, and OSX as part of [PowerShellCore][pscore]. 13 | 14 | As a git submodule, it is compiled and tested with [OneGet][oneget] together. 15 | 16 | For more information, see [OneGet wiki][wiki]. 17 | 18 | [nugetorg]: https://www.nuget.org 19 | [psgallery]: https://www.PowerShellGallery.com 20 | [psget]: https://github.com/PowerShell/PowerShellget 21 | [oneget]: https://www.oneget.org 22 | [pscore]: https://github.com/PowerShell/PowerShell 23 | [wiki]: https://github.com/oneget/oneget/wiki 24 | -------------------------------------------------------------------------------- /Register-FindPackageNuGetArgumentCompleter.ps1: -------------------------------------------------------------------------------- 1 | <#PSScriptInfo 2 | .VERSION 0.0.1 3 | .AUTHOR PowerShell Team 4 | .COPYRIGHT (c) Microsoft Corporation 5 | .GUID b4267027-4764-47fa-928f-61e7f6db43c3 6 | .TAGS Find-Package, PackageManagement, TabExpansion2, Register-ArgumentCompleter 7 | .LICENSEURI http://www.apache.org/licenses/LICENSE-2.0 8 | .PROJECTURI https://github.com/oneget/NuGetProvider 9 | #> 10 | 11 | <# 12 | .Synopsis 13 | Argument completers for Find-Package -Name for NuGet v3. 14 | .Description 15 | The script registers argument completers for Find-Package -Name when a single source is registered OR -Source is specified. All credential parameters should be specified before pressing . 16 | Installation: 17 | * Using PowerShell v5+: 18 | Invoke Find-Package.NuGet.ArgumentCompleters.ps1 (or add it to your profile) 19 | * TabExpansionPlusPlus: 20 | Find-Package.NuGet.ArgumentCompleters.ps1 should be placed in the same directory as TabExpansionPlusPlus. Optionally, invoke Find-Package.NuGet.ArgumentCompleters.ps1 (or add it to your profile) 21 | * TabExpansion2.ps1 22 | Find-Package.NuGet.ArgumentCompleters.ps1 should be added to the path. Optionally, AFTER invoking TabExpansion2.ps1, invoke Find-Package.NuGet.ArgumentCompleters.ps1 (or add it to your profile) 23 | #> 24 | Register-ArgumentCompleter -CommandName Find-Package -ParameterName Name -ScriptBlock { 25 | param($commandName, $parameterName, $wordToComplete, $commandAst, $boundParameters) 26 | 27 | # Check that the loaded PackageManagement module is new enough 28 | if (-not ("Microsoft.PackageManagement.NuGetProvider.RequestWrapper" -as [Type])) { 29 | return 30 | } 31 | 32 | # This is a workaround until we can figure out how to properly page results. Currently argument completers seem to fully enumerate the results, so we have to limit the number of results ourselves. 33 | # Change this if you want more results, but be aware that the script's signing becomes invalid. 34 | $MAX_COMPLETION_RESULTS = 20 35 | 36 | 37 | [string]$location = $null 38 | [string]$credentialUserName = $null 39 | [System.Security.SecureString]$credentialUserPassword = $null 40 | [System.Net.IWebProxy]$proxy = $null 41 | [string[]]$headers = $null 42 | 43 | if ($boundParameters.ContainsKey('Source')) { 44 | $sourceValue = $boundParameters['Source'] 45 | $ps = Get-PackageSource $sourceValue -ProviderName NuGet -ErrorAction Ignore -WarningAction Ignore | Select-Object -First 1 46 | if ($ps -ne $null) { 47 | $location = $ps.Location 48 | } elseif ([System.Uri]::IsWellFormedUriString($sourceValue, [System.UriKind]::Absolute)) { 49 | $location = $sourceValue 50 | } 51 | } else { 52 | $ps = Get-PackageSource -ProviderName NuGet -ErrorAction Ignore -WarningAction Ignore 53 | if ($ps -and ($ps.Count -eq 1)) { 54 | $location = $ps.Location 55 | } 56 | } 57 | 58 | if ($boundParameters.ContainsKey('Credential')) { 59 | $credentialUserName = $boundParameters['Credential'].UserName 60 | $credentialUserPassword = $boundParameters['Credential'].Password 61 | } 62 | 63 | if ($boundParameters.ContainsKey('Headers')) { 64 | $headers = $boundParameters['Headers'] 65 | } 66 | 67 | if ($boundParameters.ContainsKey('Proxy')) { 68 | $proxyUrl = $boundParameters['Proxy'] 69 | $proxy = [System.Net.WebProxy]::new($proxyUrl) 70 | } 71 | 72 | if ($location) 73 | { 74 | $fakeRequest = New-Object -TypeName Microsoft.PackageManagement.NuGetProvider.RequestWrapper 75 | $resources = [Microsoft.PackageManagement.NuGetProvider.NuGetResourceCollectionFactory]::GetResources($location, $fakeRequest) 76 | if ($resources.AutoCompleteFeed -ne $null) { 77 | $searchTerm = New-Object -TypeName Microsoft.PackageManagement.NuGetProvider.NuGetSearchTerm -ArgumentList [Microsoft.PackageManagement.NuGetProvider.NuGetSearchTerm+NuGetSearchTermType]::AutoComplete,$wordToComplete 78 | $resources.AutoCompleteFeed.Autocomplete($searchTerm, $fakeRequest, $false) | Select-Object -First $MAX_COMPLETION_RESULTS | ForEach-Object { 79 | New-Object System.Management.Automation.CompletionResult $_, $_, 'ParameterValue', $_ 80 | } 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /Repository/IPackageRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Microsoft.PackageManagement.Provider.Utility; 6 | 7 | public interface IPackageRepository 8 | { 9 | /// 10 | /// Gets the resources for this package repository. 11 | /// 12 | INuGetResourceCollection ResourceProvider { get; } 13 | 14 | /// 15 | /// Package source location 16 | /// 17 | string Source { get; } 18 | 19 | /// 20 | /// True if a file repository. 21 | /// 22 | bool IsFile { get; } 23 | 24 | /// 25 | /// Finds packages that match the exact Id and version. 26 | /// 27 | /// The package if found, null otherwise. 28 | IPackage FindPackage(NuGetSearchContext findContext, NuGetRequest request); 29 | 30 | /// 31 | /// Returns a sequence of packages with the specified id. 32 | /// 33 | NuGetSearchResult FindPackagesById(NuGetSearchContext findContext, NuGetRequest request); 34 | 35 | /// 36 | /// Nuget V2 metadata supports a method 'Search'. It takes three parameters, searchTerm, targetFramework, and includePrerelease. 37 | /// 38 | /// search uri 39 | /// 40 | /// 41 | NuGetSearchResult Search(NuGetSearchContext searchContext, NuGetRequest request); 42 | 43 | /// 44 | /// Download a package from this repository. 45 | /// 46 | /// PublicObjectView containing PackageItem object to download. 47 | /// Location to download package to. 48 | /// Currently executing request. 49 | /// True if package download was successful; false otherwise. 50 | bool DownloadPackage(PublicObjectView packageView, string destination, NuGetRequest request); 51 | 52 | /// 53 | /// Install a package from this repository. 54 | /// 55 | /// PublicObjectView containing PackageItem object to download. 56 | /// Currently executing request. 57 | /// True if package install was successful; false otherwise. 58 | bool InstallPackage(PublicObjectView packageView, NuGetRequest request); 59 | } 60 | } -------------------------------------------------------------------------------- /Repository/IPackageRepositoryFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | 4 | public interface IPackageRepositoryFactory 5 | { 6 | IPackageRepository CreateRepository(PackageRepositoryCreateParameters parameters); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Repository/NuGetPackageRepository.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.NuGetProvider.Resources; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Globalization; 21 | using System.Linq; 22 | 23 | public class NuGetPackageRepository : IPackageRepository 24 | { 25 | private string baseUrl; 26 | 27 | public string Source 28 | { 29 | get 30 | { 31 | return this.baseUrl; 32 | } 33 | } 34 | 35 | public bool IsFile => false; 36 | 37 | public INuGetResourceCollection ResourceProvider { get; private set; } 38 | 39 | public NuGetPackageRepository(PackageRepositoryCreateParameters parameters) 40 | { 41 | // First validate the input package source location 42 | if (!parameters.ValidateLocation()) 43 | { 44 | throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Messages.InvalidQueryUrl, parameters.Location)); 45 | } 46 | 47 | this.ResourceProvider = NuGetResourceCollectionFactory.GetResources(parameters.Location, parameters.Request); 48 | this.baseUrl = parameters.Location; 49 | } 50 | 51 | public IPackage FindPackage(NuGetSearchContext findContext, NuGetRequest request) 52 | { 53 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetPackageRepository", "FindPackage", findContext.PackageInfo.Id); 54 | NuGetSearchResult result = this.ResourceProvider.PackagesFeed.Find(findContext, request); 55 | if (result.Result != null) 56 | { 57 | return result.Result.FirstOrDefault(); 58 | } else 59 | { 60 | return null; 61 | } 62 | } 63 | 64 | public NuGetSearchResult FindPackagesById(NuGetSearchContext findContext, NuGetRequest request) 65 | { 66 | request.Debug(Messages.DebugInfoCallMethod3, "NuGetPackageRepository", "FindPackagesById", findContext.PackageInfo.Id); 67 | return this.ResourceProvider.PackagesFeed.Find(findContext, request); 68 | } 69 | 70 | public NuGetSearchResult Search(NuGetSearchContext searchContext, NuGetRequest request) 71 | { 72 | request.Debug(Messages.DebugInfoCallMethod, "NuGetPackageRepository", "Search"); 73 | return this.ResourceProvider.QueryFeed.Search(searchContext, request); 74 | } 75 | 76 | public bool DownloadPackage(PublicObjectView packageView, string destination, NuGetRequest request) 77 | { 78 | request.Debug(Messages.DebugInfoCallMethod, "NuGetPackageRepository", "DownloadPackage"); 79 | return this.ResourceProvider.FilesFeed.DownloadPackage(packageView, destination, request); 80 | } 81 | 82 | public bool InstallPackage(PublicObjectView packageView, NuGetRequest request) 83 | { 84 | request.Debug(Messages.DebugInfoCallMethod, "NuGetPackageRepository", "InstallPackage"); 85 | return this.ResourceProvider.FilesFeed.InstallPackage(packageView, request); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Repository/NuGetSearchContext.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.Provider.Utility; 18 | using System.Collections.Generic; 19 | 20 | /// 21 | /// Contains all required search information. 22 | /// 23 | public class NuGetSearchContext 24 | { 25 | /// 26 | /// Gets or sets the specific package to find. 27 | /// 28 | public PackageEntryInfo PackageInfo { get; set; } 29 | 30 | /// 31 | /// Gets or sets the search terms to execute. 32 | /// 33 | public IEnumerable SearchTerms { get; set; } 34 | 35 | /// 36 | /// Gets or sets the required version. 37 | /// 38 | public SemanticVersion RequiredVersion { get; set; } 39 | 40 | /// 41 | /// Gets or sets the minimum version. 42 | /// 43 | public SemanticVersion MinimumVersion { get; set; } 44 | 45 | /// 46 | /// Gets or sets the maximum version. 47 | /// 48 | public SemanticVersion MaximumVersion { get; set; } 49 | 50 | /// 51 | /// Gets or sets if prerelease versions are allowed. 52 | /// 53 | public bool AllowPrerelease { get; set; } 54 | 55 | /// 56 | /// Gets or sets if all versions should be returned. 57 | /// 58 | public bool AllVersions { get; set; } 59 | 60 | /// 61 | /// Gets or sets if "deep" (but required) metadata should be skipped. Safe to enable for search scenarios, but not find scenarios. 62 | /// 63 | public bool EnableDeepMetadataBypass { get; set; } 64 | 65 | /// 66 | /// Create a result after executing this search. 67 | /// 68 | /// Result packages 69 | /// True if versions haven't been filtered by the search, meaning the client should still filter versions; false otherwise. 70 | /// Search result object. 71 | public NuGetSearchResult MakeResult(IEnumerable result, bool versionPostFilterRequired = true, bool namePostFilterRequired = true, bool containsPostFilterRequired = true) 72 | { 73 | return new NuGetSearchResult() 74 | { 75 | Result = result, 76 | VersionPostFilterRequired = versionPostFilterRequired, 77 | NamePostFilterRequired = namePostFilterRequired, 78 | ContainsPostFilterRequired = containsPostFilterRequired 79 | }; 80 | } 81 | 82 | public NuGetSearchResult MakeResult() 83 | { 84 | return new NuGetSearchResult(); 85 | } 86 | } 87 | 88 | /// 89 | /// Result of a NuGet Find/Search request. 90 | /// 91 | public class NuGetSearchResult 92 | { 93 | public IEnumerable Result { get; set; } 94 | 95 | public bool VersionPostFilterRequired { get; set; } 96 | 97 | public bool NamePostFilterRequired { get; set; } 98 | 99 | public bool ContainsPostFilterRequired { get; set; } 100 | 101 | public NuGetSearchResult() 102 | { 103 | this.VersionPostFilterRequired = true; 104 | this.NamePostFilterRequired = true; 105 | this.ContainsPostFilterRequired = true; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Repository/NuGetSearchTerm.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// A single NuGet API search term. 19 | /// 20 | public class NuGetSearchTerm 21 | { 22 | public enum NuGetSearchTermType 23 | { 24 | Tag, 25 | SearchTerm, 26 | Id, 27 | PackageType, 28 | AutoComplete, 29 | OriginalPSPattern, 30 | Contains 31 | } 32 | 33 | /// 34 | /// Gets the type of search term. 35 | /// 36 | public NuGetSearchTermType Term { get; private set; } 37 | 38 | /// 39 | /// Gets the search text. 40 | /// 41 | public string Text { get; private set; } 42 | 43 | public NuGetSearchTerm(NuGetSearchTermType type, string text) 44 | { 45 | this.Term = type; 46 | this.Text = text; 47 | } 48 | 49 | public override string ToString() 50 | { 51 | return this.Term.ToString() + "@" + this.Term; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Repository/PackageEntryInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.Provider.Utility; 18 | using System; 19 | using System.Collections.Generic; 20 | 21 | /// 22 | /// Contains information about a package as a whole entity (i.e. not versioned). For example, 'awssdk'. 23 | /// 24 | public class PackageEntryInfo 25 | { 26 | private HashSet allVersionsSet = new HashSet(); 27 | private object addVersionLock = new object(); 28 | 29 | public string Id { get; private set; } 30 | 31 | public IList AllVersions { get; private set; } 32 | 33 | public SemanticVersion LatestVersion { get; private set; } 34 | 35 | public SemanticVersion AbsoluteLatestVersion { get; private set; } 36 | 37 | public PackageEntryInfo(string packageId) 38 | { 39 | this.Id = packageId; 40 | this.AllVersions = new List(); 41 | } 42 | 43 | public PackageEntryInfo AddVersion(SemanticVersion version) 44 | { 45 | string versionStr = version.ToString(); 46 | if (!allVersionsSet.Contains(versionStr)) 47 | { 48 | lock (addVersionLock) 49 | { 50 | if (!allVersionsSet.Contains(versionStr)) 51 | { 52 | this.AllVersions.Add(version); 53 | if (String.IsNullOrWhiteSpace(version.SpecialVersion)) 54 | { 55 | if (LatestVersion == null || LatestVersion < version) 56 | { 57 | LatestVersion = version; 58 | } 59 | } 60 | 61 | if (AbsoluteLatestVersion == null || AbsoluteLatestVersion < version) 62 | { 63 | AbsoluteLatestVersion = version; 64 | } 65 | 66 | allVersionsSet.Add(versionStr); 67 | } 68 | } 69 | } 70 | 71 | return this; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Repository/PackageRepositoryCreateParameters.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System; 18 | 19 | /// 20 | /// Parameters to create IPackageRepository 21 | /// 22 | public class PackageRepositoryCreateParameters 23 | { 24 | private object validationLock = new object(); 25 | 26 | /// 27 | /// Gets or sets PackageSource location 28 | /// 29 | public string Location { get; set; } 30 | 31 | /// 32 | /// Gets or sets the flag determining if the location is valid. Null if the location has not been tested. 33 | /// 34 | public bool? LocationValid { get; set; } 35 | 36 | /// 37 | /// Gets or sets the NuGet request object associated with creation. 38 | /// 39 | public NuGetRequest Request { get; set; } 40 | public PackageRepositoryCreateParameters(string location, NuGetRequest request) : this(location, request, null) { } 41 | 42 | 43 | public PackageRepositoryCreateParameters(string location, NuGetRequest request, bool? locationValid) 44 | { 45 | this.Location = location; 46 | this.Request = request; 47 | this.LocationValid = locationValid; 48 | } 49 | 50 | /// 51 | /// Gets if the Location URI is valid. 52 | /// 53 | /// True if Location is valid and sets Location to the validated URI; false otherwise. 54 | public bool ValidateLocation() 55 | { 56 | if (!this.LocationValid.HasValue) 57 | { 58 | lock (validationLock) 59 | { 60 | if (!this.LocationValid.HasValue) 61 | { 62 | Uri locationUri; 63 | if (Uri.TryCreate(this.Location, UriKind.Absolute, out locationUri)) 64 | { 65 | Uri validatedUri = NuGetPathUtility.ValidateUri(locationUri, this.Request); 66 | if (validatedUri != null) 67 | { 68 | this.Location = validatedUri.AbsoluteUri; 69 | this.LocationValid = true; 70 | } 71 | else 72 | { 73 | this.LocationValid = false; 74 | } 75 | } 76 | } 77 | } 78 | } 79 | 80 | return this.LocationValid.Value; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Repository/PackageRepositoryFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | using System; 4 | using System.Net; 5 | 6 | public class PackageRepositoryFactory : IPackageRepositoryFactory 7 | { 8 | private static readonly PackageRepositoryFactory _default = new PackageRepositoryFactory(); 9 | 10 | public static PackageRepositoryFactory Default 11 | { 12 | get { return _default;} 13 | } 14 | 15 | public IPackageRepository CreateRepository(PackageRepositoryCreateParameters parameters) 16 | { 17 | if (parameters == null) 18 | { 19 | throw new ArgumentNullException("parameters"); 20 | } 21 | 22 | if (parameters.Location == null) 23 | { 24 | throw new ArgumentNullException("parameters.Location"); 25 | } 26 | 27 | if (parameters.Request == null) 28 | { 29 | throw new ArgumentNullException("parameters.Request"); 30 | } 31 | 32 | IPackageRepository repository = ConcurrentInMemoryCache.Instance.GetOrAdd(parameters.Location, () => 33 | { 34 | // we cannot call new uri on file path on linux because it will error out 35 | if (System.IO.Directory.Exists(parameters.Location)) 36 | { 37 | return new LocalPackageRepository(parameters.Location, parameters.Request); 38 | } 39 | 40 | Uri uri = new Uri(parameters.Location); 41 | 42 | if (uri.IsFile) 43 | { 44 | return new LocalPackageRepository(uri.LocalPath, parameters.Request); 45 | } 46 | 47 | return new NuGetPackageRepository(parameters); 48 | }); 49 | 50 | return repository; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Sdk/Constants.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.PackageManagement.NuGetProvider 2 | { 3 | using System; 4 | using System.Text.RegularExpressions; 5 | 6 | internal static class Constants 7 | { 8 | #region copy common-constants-implementation /internal/public 9 | 10 | internal const string MinVersion = "0.0.0.1"; 11 | internal const string MSGPrefix = "MSG:"; 12 | internal const string Download = "Download"; 13 | internal const string Install = "Install"; 14 | public readonly static string[] FeaturePresent = new string[0]; 15 | internal const string CurrentUser = "CurrentUser"; 16 | internal const string AllUsers = "AllUsers"; 17 | internal const string SearchPageCount = "200"; 18 | internal const int SearchPageCountInt = 200; 19 | internal const string PackageIdTemplateParameter = "{id}"; 20 | internal const string PackageVersionTemplateParameter = "{version}"; 21 | internal const string PackageIdLowerTemplateParameter = "{id-lower}"; 22 | internal const string PackageVersionLowerTemplateParameter = "{version-lower}"; 23 | internal const string PackageIdQueryParam = "id"; 24 | internal const string PrereleaseQueryParam = "prerelease"; 25 | internal const string QueryQueryParam = "q"; 26 | internal const string TakeQueryParam = "take"; 27 | internal const string SkipQueryParam = "skip"; 28 | /// 29 | /// {0} = base URL 30 | /// {1} = id lower 31 | /// {2} = version lower 32 | /// {3} = / or empty, depending on last character of {0} 33 | /// 34 | internal const string NuGetDownloadUriTemplate = "{0}{3}{1}/{2}/{1}.{2}.nupkg"; 35 | internal static readonly Regex MyGetFeedRegex = new Regex("myget.org/F/(.*?)/api/v3/index.json"); 36 | /// 37 | /// {0} = Scheme 38 | /// {1} = Host 39 | /// {2} = Feed name 40 | /// 41 | internal const string MyGetGalleryUriTemplate = "{0}://{1}/feed/{2}/package/nuget/{{id-lower}}/{{version-lower}}"; 42 | internal const string NuGetGalleryUriTemplate = "https://www.nuget.org/packages/{id-lower}/{version-lower}"; 43 | internal const string DummyPackageId = "FoooBarr"; 44 | internal const string PackageServiceType = "PackageDisplayMetadataUriTemplate"; 45 | internal const string PackageVersionServiceType = "PackageVersionDisplayMetadataUriTemplate"; 46 | internal const string RegistrationBaseServiceType = "RegistrationsBaseUrl"; 47 | internal const string SearchQueryServiceType = "SearchQueryService"; 48 | internal const string PackageBaseAddressType = "PackageBaseAddress"; 49 | internal const string ReportAbuseAddressType = "ReportAbuseUriTemplate"; 50 | internal const string AutocompleteAddressType = "SearchAutocompleteService"; 51 | internal const string TagQueryParam = "tag"; 52 | internal const string DescriptionQueryParam = "description"; 53 | internal const string NuGetOrgHost = "nuget.org"; 54 | internal const string MyGetOrgHost = "myget.org"; 55 | internal const string XmlStartContent = " 57 | /// {0} = base URL for registrations 58 | /// {1} = / or empty 59 | /// {2} = package id lowercase 60 | /// 61 | internal const string NuGetRegistrationUrlTemplatePackage = "{0}{1}{2}/index.json"; 62 | /// 63 | /// {0} = base URL for registrations 64 | /// {1} = / or empty 65 | /// {2} = package id lowercase 66 | /// {3} = package version lowercase 67 | /// 68 | internal const string NuGetRegistrationUrlTemplatePackageVersion = "{0}{1}{2}/{3}.json"; 69 | internal const string SemVerLevelQueryParam = "semverlevel"; 70 | internal const string SemVerLevel2 = "2.0.0"; 71 | /// 72 | /// {0} = base URL for blob store 73 | /// {1} = / or empty 74 | /// {2} = package id 75 | /// 76 | internal const string VersionIndexTemplate = "{0}{1}{2}/index.json"; 77 | internal const int DefaultRetryCount = 3; 78 | internal static readonly Func SimpleBackoffStrategy = (int oldSleep) => { if (oldSleep <= 0) { return 1000; } else { return oldSleep * 2; } }; 79 | internal const int DefaultExtraPackageCount = 5; 80 | //public static string[] Empty = new string[0]; 81 | 82 | internal static class Features 83 | { 84 | public const string AutomationOnly = "automation-only"; 85 | public const string MagicSignatures = "magic-signatures"; 86 | public const string SupportedExtensions = "file-extensions"; 87 | public const string SupportedSchemes = "uri-schemes"; 88 | public const string SupportsPowerShellModules = "supports-powershell-modules"; 89 | public const string SupportsRegexSearch = "supports-regex-search"; 90 | public const string SupportsSubstringSearch = "supports-substring-search"; 91 | public const string SupportsWildcardSearch = "supports-wildcard-search"; 92 | } 93 | 94 | internal static class Messages 95 | { 96 | public const string UnableToFindDependencyPackage = "MSG:UnableToFindDependencyPackage"; 97 | public const string DependentPackageFailedInstallOrDownload = "MSG:DependentPackageFailedInstallOrDownload"; 98 | public const string MissingRequiredParameter = "MSG:MissingRequiredParameter"; 99 | public const string PackageFailedInstallOrDownload = "MSG:PackageFailedInstallOrDownload"; 100 | public const string PackageSourceExists = "MSG:PackageSourceExists"; 101 | public const string ProtocolNotSupported = "MSG:ProtocolNotSupported"; 102 | public const string ProviderPluginLoadFailure = "MSG:ProviderPluginLoadFailure"; 103 | public const string ProviderSwidtagUnavailable = "MSG:ProviderSwidtagUnavailable"; 104 | public const string RemoveEnvironmentVariableRequiresElevation = "MSG:RemoveEnvironmentVariableRequiresElevation"; 105 | public const string SchemeNotSupported = "MSG:SchemeNotSupported"; 106 | public const string SourceLocationNotValid = "MSG:SourceLocationNotValid"; 107 | public const string UnableToCopyFileTo = "MSG:UnableToCopyFileTo"; 108 | public const string UnableToCreateShortcutTargetDoesNotExist = "MSG:UnableToCreateShortcutTargetDoesNotExist"; 109 | public const string UnableToDownload = "MSG:UnableToDownload"; 110 | public const string UnableToOverwriteExistingFile = "MSG:UnableToOverwriteExistingFile"; 111 | public const string UnableToRemoveFile = "MSG:UnableToRemoveFile"; 112 | public const string UnableToResolvePackage = "MSG:UnableToResolvePackage"; 113 | public const string UnableToResolveSource = "MSG:UnableToResolveSource"; 114 | public const string UnableToUninstallPackage = "MSG:UnableToUninstallPackage"; 115 | public const string UnknownFolderId = "MSG:UnknownFolderId"; 116 | public const string UnknownProvider = "MSG:UnknownProvider"; 117 | public const string UnsupportedArchive = "MSG:UnsupportedArchive"; 118 | public const string UnsupportedProviderType = "MSG:UnsupportedProviderType"; 119 | public const string UriSchemeNotSupported = "MSG:UriSchemeNotSupported"; 120 | public const string UserDeclinedUntrustedPackageInstall = "MSG:UserDeclinedUntrustedPackageInstall"; 121 | public const string HashNotFound = "MSG:HashNotFound"; 122 | public const string HashNotMatch = "MSG:HashNotMatch"; 123 | public const string HashNotSupported = "MSG:HashNotSupported"; 124 | public const string DependencyLoopDetected = "MSG:DependencyLoopDetected"; 125 | public const string CouldNotGetResponseFromQuery = "MSG:CouldNotGetResponseFromQuery"; 126 | public const string SkippedDownloadedPackage = "MSG:SkippedDownloadedPackage"; 127 | public const string InstallRequiresCurrentUserScopeParameterForNonAdminUser = "MSG:InstallRequiresCurrentUserScopeParameterForNonAdminUser"; 128 | 129 | } 130 | 131 | internal static class OptionType { 132 | public const string String = "String"; 133 | public const string StringArray = "StringArray"; 134 | public const string Int = "Int"; 135 | public const string Switch = "Switch"; 136 | public const string Folder = "Folder"; 137 | public const string File = "File"; 138 | public const string Path = "Path"; 139 | public const string Uri = "Uri"; 140 | public const string SecureString = "SecureString"; 141 | } 142 | 143 | internal static class PackageStatus 144 | { 145 | public const string Available = "Available"; 146 | public const string Dependency = "Dependency"; 147 | public const string Installed = "Installed"; 148 | public const string Uninstalled = "Uninstalled"; 149 | } 150 | 151 | internal static class Parameters 152 | { 153 | public const string IsUpdate = "IsUpdatePackageSource"; 154 | public const string Name = "Name"; 155 | public const string Location = "Location"; 156 | } 157 | 158 | internal static class Signatures 159 | { 160 | public const string Cab = "4D534346"; 161 | public const string OleCompoundDocument = "D0CF11E0A1B11AE1"; 162 | public const string Zip = "504b0304"; 163 | //public static string[] ZipVariants = new[] {Zip, /* should have EXEs? */}; 164 | } 165 | 166 | internal static class SwidTag 167 | { 168 | public const string SoftwareIdentity = "SoftwareIdentity"; 169 | } 170 | 171 | #endregion 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /Sdk/ErrorCategory.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Microsoft.PackageManagement.NuGetProvider 3 | { 4 | public enum ErrorCategory { 5 | NotSpecified, 6 | OpenError, 7 | CloseError, 8 | DeviceError, 9 | DeadlockDetected, 10 | InvalidArgument, 11 | InvalidData, 12 | InvalidOperation, 13 | InvalidResult, 14 | InvalidType, 15 | MetadataError, 16 | NotImplemented, 17 | NotInstalled, 18 | ObjectNotFound, 19 | OperationStopped, 20 | OperationTimeout, 21 | SyntaxError, 22 | ParserError, 23 | PermissionDenied, 24 | ResourceBusy, 25 | ResourceExists, 26 | ResourceUnavailable, 27 | ReadError, 28 | WriteError, 29 | FromStdErr, 30 | SecurityError, 31 | ProtocolError, 32 | ConnectionError, 33 | AuthenticationError, 34 | LimitsExceeded, 35 | QuotaExceeded, 36 | NotEnabled, 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Sdk/IRequestOutput.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Interface that wraps output logging for Request objects (or RequestWrapper). 19 | /// 20 | public interface IRequestOutput 21 | { 22 | void Verbose(string msg, params object[] args); 23 | void Debug(string msg, params object[] args); 24 | void Warning(string msg, params object[] args); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sdk/NuGetRequestOutput.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Output using the inner NuGetRequest object. 19 | /// 20 | internal class NuGetRequestOutput : IRequestOutput 21 | { 22 | private NuGetRequest internalRequest; 23 | public NuGetRequestOutput(NuGetRequest request) 24 | { 25 | this.internalRequest = request; 26 | } 27 | 28 | public void Debug(string msg, params object[] args) 29 | { 30 | this.internalRequest.Debug(msg, args); 31 | } 32 | 33 | public void Verbose(string msg, params object[] args) 34 | { 35 | this.internalRequest.Verbose(msg, args); 36 | } 37 | 38 | public void Warning(string msg, params object[] args) 39 | { 40 | this.internalRequest.Warning(msg, args); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Sdk/NullRequestOutput.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// For cases where no output is expected (like argument completers) 19 | /// 20 | internal class NullRequestOutput : IRequestOutput 21 | { 22 | public void Debug(string msg, params object[] args) 23 | { 24 | } 25 | 26 | public void Verbose(string msg, params object[] args) 27 | { 28 | } 29 | 30 | public void Warning(string msg, params object[] args) 31 | { 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Utility/CatalogUrlConverter.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Extracts the catalog entry URI from the given object. 19 | /// 20 | internal class CatalogUrlConverter : IDynamicJsonObjectConverter 21 | { 22 | public INuGetResourceCollection ResourcesCollection { get; set; } 23 | 24 | public string Make(dynamic jsonObject) 25 | { 26 | if (jsonObject.catalogentry is string) 27 | { 28 | return jsonObject.catalogentry; 29 | } 30 | else 31 | { 32 | return jsonObject.catalogentry.Metadata.id; 33 | } 34 | } 35 | 36 | public string Make(dynamic jsonObject, string existingObject) 37 | { 38 | return Make(jsonObject); 39 | } 40 | 41 | public string Make(dynamic jsonObject, object args) 42 | { 43 | return Make(jsonObject); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Utility/ConcurrentInMemoryCache.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | internal class ConcurrentInMemoryCache 21 | { 22 | private static ConcurrentInMemoryCache instance = new ConcurrentInMemoryCache(); 23 | public static ConcurrentInMemoryCache Instance 24 | { 25 | get 26 | { 27 | return instance; 28 | } 29 | } 30 | 31 | private Dictionary cache = new Dictionary(); 32 | public T GetOrAdd(string key, Func constructor) 33 | { 34 | T res = default(T); 35 | if (!cache.ContainsKey(key)) 36 | { 37 | lock (cache) 38 | { 39 | if (!cache.ContainsKey(key)) 40 | { 41 | res = constructor(); 42 | cache[key] = res; 43 | } 44 | } 45 | } 46 | 47 | return (T)cache[key]; 48 | } 49 | 50 | public bool TryGet(string key, out T val) 51 | { 52 | if (cache.ContainsKey(key)) 53 | { 54 | val = (T)cache[key]; 55 | return true; 56 | } 57 | 58 | val = default(T); 59 | return false; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Utility/DependencyGroupConverter.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System.Collections.Generic; 18 | 19 | /// 20 | /// Extracts the PackageDependencySet. 21 | /// 22 | internal class DependencyGroupConverter : IDynamicJsonObjectConverter 23 | { 24 | public INuGetResourceCollection ResourcesCollection { get; set; } 25 | 26 | public PackageDependencySet Make(dynamic jsonObject) 27 | { 28 | PackageDependencySet pds = new PackageDependencySet(); 29 | pds.Dependencies = new List(); 30 | 31 | if (jsonObject.HasProperty("targetframework")) 32 | { 33 | pds.TargetFramework = jsonObject.targetframework; 34 | } 35 | 36 | if (jsonObject.HasProperty("dependencies")) 37 | { 38 | foreach (dynamic dependencyObject in jsonObject.dependencies) 39 | { 40 | pds.Dependencies.Add(this.ResourcesCollection.PackageDependencyConverter.Make(dependencyObject)); 41 | } 42 | } 43 | 44 | return pds; 45 | } 46 | 47 | public PackageDependencySet Make(dynamic jsonObject, PackageDependencySet existingObject) 48 | { 49 | if (jsonObject.HasProperty("targetframework")) 50 | { 51 | existingObject.TargetFramework = jsonObject.targetframework; 52 | } 53 | 54 | if (jsonObject.HasProperty("dependencies")) 55 | { 56 | foreach (dynamic dependencyObject in jsonObject.dependencies) 57 | { 58 | existingObject.Dependencies.Add(this.ResourcesCollection.PackageDependencyConverter.Make(dependencyObject)); 59 | } 60 | } 61 | 62 | return existingObject; 63 | } 64 | 65 | public PackageDependencySet Make(dynamic jsonObject, object args) 66 | { 67 | return Make(jsonObject); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Utility/HttpQueryBuilder.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System; 18 | using System.Globalization; 19 | using System.Text; 20 | 21 | /// 22 | /// Builds URL query parameters. 23 | /// 24 | public class HttpQueryBuilder 25 | { 26 | private StringBuilder sb = new StringBuilder(); 27 | private bool appendAmpersand = false; 28 | private HttpQueryBuilder innerQueryBuilder = null; 29 | 30 | /// 31 | /// Adds a given name-value pair to this query string. 32 | /// 33 | public HttpQueryBuilder Add(string name, string val, string separator = "=", bool encode = true) 34 | { 35 | sb.AppendFormat("{0}{1}{2}{3}", appendAmpersand ? "&" : String.Empty, encode ? System.Net.WebUtility.UrlEncode(name) : name, 36 | separator, encode ? System.Net.WebUtility.UrlEncode(val) : val); 37 | appendAmpersand = true; 38 | return this; 39 | } 40 | 41 | /// 42 | /// Adds the name-value pair to a new instance of HttpQueryBuilder, while keeping this instance's name-value pairs in the new instance. 43 | /// 44 | public HttpQueryBuilder CloneAdd(string name, string val, string separator = "=") 45 | { 46 | HttpQueryBuilder clone = new HttpQueryBuilder(); 47 | clone.innerQueryBuilder = this; 48 | clone.Add(name, val, separator); 49 | return clone; 50 | } 51 | 52 | /// 53 | /// Creates the query string (without ?). 54 | /// 55 | /// Query string 56 | public string ToQueryString() 57 | { 58 | if (this.innerQueryBuilder != null) 59 | { 60 | string query = this.innerQueryBuilder.ToQueryString(); 61 | if (!String.IsNullOrEmpty(query)) 62 | { 63 | query += "&"; 64 | } 65 | 66 | return query + sb.ToString(); 67 | } 68 | 69 | return sb.ToString(); 70 | } 71 | 72 | /// 73 | /// Append this query string to the given url. 74 | /// 75 | /// Base URL without any query string. 76 | /// Base URL + this query string. 77 | public string AddQueryString(string baseUrl) 78 | { 79 | return String.Format(CultureInfo.InvariantCulture, "{0}?{1}", baseUrl, this.ToQueryString()); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Utility/IDynamicJsonObjectConverter.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Interface to convert a dynamic JSON object to a strongly-typed object. 19 | /// 20 | /// Type of object to create. 21 | /// Args type 22 | public interface IDynamicJsonObjectConverter : INuGetResource 23 | { 24 | T Make(dynamic jsonObject); 25 | T Make(dynamic jsonObject, A args); 26 | T Make(dynamic jsonObject, T existingObject); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Utility/NuGetPathUtility.cs: -------------------------------------------------------------------------------- 1 |  2 | using Microsoft.PackageManagement.Provider.Utility; 3 | 4 | namespace Microsoft.PackageManagement.NuGetProvider 5 | { 6 | using System; 7 | using System.Collections.Generic; 8 | using System.ComponentModel; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Net; 12 | using System.Net.Http; 13 | using System.Net.Http.Headers; 14 | using System.Text; 15 | using System.Threading; 16 | using System.Threading.Tasks; 17 | using System.Runtime.InteropServices; 18 | using System.Diagnostics; 19 | 20 | internal static class NuGetPathUtility 21 | { 22 | private static readonly char[] _invalidPathChars = Path.GetInvalidPathChars(); 23 | 24 | 25 | internal static bool IsManifest(string path) 26 | { 27 | if (string.IsNullOrWhiteSpace(path)) 28 | { 29 | return false; 30 | } 31 | 32 | return Path.GetExtension(path).Equals(NuGetConstant.ManifestExtension, StringComparison.OrdinalIgnoreCase); 33 | } 34 | 35 | internal static bool IsPackageFile(string path) 36 | { 37 | if (string.IsNullOrWhiteSpace(path)) 38 | { 39 | return false; 40 | } 41 | 42 | return Path.GetExtension(path).Equals(NuGetConstant.PackageExtension, StringComparison.OrdinalIgnoreCase); 43 | } 44 | 45 | internal static bool ValidateSourceUri(IEnumerable supportedSchemes, Uri srcUri, NuGetRequest request) 46 | { 47 | 48 | if (!supportedSchemes.Contains(srcUri.Scheme.ToLowerInvariant())) 49 | { 50 | return false; 51 | } 52 | 53 | if (srcUri.IsFile) 54 | { 55 | //validate file source location 56 | if (Directory.Exists(srcUri.LocalPath)) 57 | { 58 | return true; 59 | } 60 | return false; 61 | } 62 | 63 | //validate uri source location 64 | return ValidateUri(srcUri, request) != null; 65 | } 66 | 67 | /// 68 | /// Returns the validated uri. Returns null if we cannot validate it 69 | /// 70 | /// 71 | /// 72 | /// 73 | internal static Uri ValidateUri(Uri query, NuGetRequest request) 74 | { 75 | // Validation takes place in two steps: 76 | // 1. Validate the given URI is valid, resolving redirection 77 | // 2. Validate we can hit the query service 78 | NetworkCredential credentials = null; 79 | var client = request.ClientWithoutAcceptHeader; 80 | 81 | var response = PathUtility.GetHttpResponse(client, query.AbsoluteUri, (() => request.IsCanceled), 82 | ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg)); 83 | 84 | if (response == null) 85 | { 86 | return null; 87 | } 88 | 89 | // if response is not success, we need to check for redirection 90 | if (!response.IsSuccessStatusCode) 91 | { 92 | // Check for redirection (http status code 3xx) 93 | if (response.StatusCode == HttpStatusCode.MultipleChoices || response.StatusCode == HttpStatusCode.MovedPermanently 94 | || response.StatusCode == HttpStatusCode.Found || response.StatusCode == HttpStatusCode.SeeOther 95 | || response.StatusCode == HttpStatusCode.TemporaryRedirect) 96 | { 97 | // get the redirected direction 98 | string location = response.Headers.GetValues("Location").FirstOrDefault(); 99 | if (String.IsNullOrWhiteSpace(location)) 100 | { 101 | return null; 102 | } 103 | 104 | // make a new query based on location 105 | query = new Uri(location); 106 | } 107 | else 108 | { 109 | if (response.StatusCode == HttpStatusCode.Unauthorized && request.CredentialUsername.IsNullOrEmpty() && !(request.suppressCredentialProvider)) 110 | { 111 | // If the uri is not validated, try again using credentials retrieved from credential provider 112 | // First call to the credential provider is to get credentials, but if those credentials fail, 113 | // we call the cred provider again to ask the user for new credentials, and then search try to validate uri again using new creds 114 | credentials = request.GetCredsFromCredProvider(query.AbsoluteUri, request, false); 115 | var newClient = PathUtility.GetHttpClientHelper(credentials.UserName, credentials.SecurePassword, request.WebProxy); 116 | 117 | var newResponse = PathUtility.GetHttpResponse(newClient, query.AbsoluteUri, (() => request.IsCanceled), 118 | ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg)); 119 | query = new Uri(newResponse.RequestMessage.RequestUri.AbsoluteUri); 120 | 121 | request.SetHttpClient(newClient); 122 | 123 | if (newResponse.StatusCode == HttpStatusCode.Unauthorized) 124 | { 125 | // Calling the credential provider for a second time, using -IsRetry 126 | credentials = request.GetCredsFromCredProvider(query.AbsoluteUri, request, true); 127 | newClient = PathUtility.GetHttpClientHelper(credentials.UserName, credentials.SecurePassword, request.WebProxy); 128 | 129 | newResponse = PathUtility.GetHttpResponse(newClient, query.AbsoluteUri, (() => request.IsCanceled), 130 | ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg)); 131 | query = new Uri(newResponse.RequestMessage.RequestUri.AbsoluteUri); 132 | 133 | request.SetHttpClient(newClient); 134 | 135 | if (newResponse.StatusCode == HttpStatusCode.Unauthorized) 136 | { 137 | request.WriteError(ErrorCategory.PermissionDenied, "ValidateUri", Resources.Messages.AccessPermissionDenied, query); 138 | return null; 139 | } 140 | } 141 | } 142 | else 143 | { 144 | // other status code is wrong 145 | return null; 146 | } 147 | } 148 | } 149 | else 150 | { 151 | query = new Uri(response.RequestMessage.RequestUri.AbsoluteUri); 152 | } 153 | 154 | IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository(new PackageRepositoryCreateParameters(query.AbsoluteUri, request, locationValid: true)); 155 | if (repo.ResourceProvider != null) 156 | { 157 | // If the query feed exists, it's a non-local repo 158 | // Check the query feed to make sure it's available 159 | // Optionally we could change this to check the packages feed for availability 160 | if (repo.ResourceProvider.QueryFeed == null || !repo.ResourceProvider.QueryFeed.IsAvailable(new RequestWrapper(request, credentials))) 161 | { 162 | return null; 163 | } 164 | } 165 | 166 | return query; 167 | } 168 | 169 | #region CryptProtectData 170 | //internal struct DATA_BLOB 171 | //{ 172 | // public int cbData; 173 | // public IntPtr pbData; 174 | //} 175 | 176 | //internal static void CopyByteToBlob(ref DATA_BLOB blob, byte[] data) 177 | //{ 178 | // blob.pbData = Marshal.AllocHGlobal(data.Length); 179 | 180 | // blob.cbData = data.Length; 181 | 182 | // Marshal.Copy(data, 0, blob.pbData, data.Length); 183 | //} 184 | 185 | //internal const uint CRYPTPROTECT_UI_FORBIDDEN = 0x1; 186 | 187 | //[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)] 188 | //private static extern bool CryptUnprotectData(ref DATA_BLOB pDataIn, ref string ppszDataDescr, ref DATA_BLOB pOptionalEntropy, 189 | // IntPtr pvReserved, IntPtr pPromptStruct, uint dwFlags, ref DATA_BLOB pDataOut); 190 | 191 | //[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)] 192 | //private static extern bool CryptProtectData(ref DATA_BLOB pDataIn, string szDataDescr, ref DATA_BLOB pOptionalEntropy, 193 | // IntPtr pvReserved, IntPtr pPromptStruct, uint dwFlags, ref DATA_BLOB pDataOut); 194 | 195 | //public static byte[] CryptProtect(byte[] dataIn, byte[] optionalEntropy, bool encryptionOperation) 196 | //{ 197 | // DATA_BLOB dataInBlob = new DATA_BLOB(); 198 | // DATA_BLOB optionalEntropyBlob = new DATA_BLOB(); 199 | // DATA_BLOB resultBlob = new DATA_BLOB(); 200 | // string description = String.Empty; 201 | 202 | // try 203 | // { 204 | // // copy the encrypted blob 205 | // CopyByteToBlob(ref dataInBlob, dataIn); 206 | // CopyByteToBlob(ref optionalEntropyBlob, optionalEntropy); 207 | 208 | // // use local user 209 | // uint flags = CRYPTPROTECT_UI_FORBIDDEN; 210 | 211 | // bool success = false; 212 | 213 | // // doing decryption 214 | // if (!encryptionOperation) 215 | // { 216 | // // call win32 api 217 | // success = CryptUnprotectData(ref dataInBlob, ref description, ref optionalEntropyBlob, IntPtr.Zero, IntPtr.Zero, flags, ref resultBlob); 218 | // } 219 | // else 220 | // { 221 | // // doing encryption 222 | // success = CryptProtectData(ref dataInBlob, description, ref optionalEntropyBlob, IntPtr.Zero, IntPtr.Zero, flags, ref resultBlob); 223 | // } 224 | 225 | // if (!success) 226 | // { 227 | // throw new Win32Exception(Marshal.GetLastWin32Error()); 228 | // } 229 | 230 | // byte[] unencryptedBytes = new byte[resultBlob.cbData]; 231 | 232 | // Marshal.Copy(resultBlob.pbData, unencryptedBytes, 0, resultBlob.cbData); 233 | 234 | // return unencryptedBytes; 235 | // } 236 | // finally 237 | // { 238 | // // free memory 239 | // if (dataInBlob.pbData != IntPtr.Zero) 240 | // { 241 | // Marshal.FreeHGlobal(dataInBlob.pbData); 242 | // } 243 | 244 | // if (optionalEntropyBlob.pbData != IntPtr.Zero) 245 | // { 246 | // Marshal.FreeHGlobal(optionalEntropyBlob.pbData); 247 | // } 248 | 249 | // if (resultBlob.pbData != IntPtr.Zero) 250 | // { 251 | // Marshal.FreeHGlobal(resultBlob.pbData); 252 | // } 253 | // } 254 | //} 255 | #endregion 256 | } 257 | } -------------------------------------------------------------------------------- /Utility/PackageDependencyConverter.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.Provider.Utility; 18 | using System; 19 | 20 | /// 21 | /// Extracts a PackageDependency. 22 | /// 23 | internal class PackageDependencyConverter : IDynamicJsonObjectConverter 24 | { 25 | public INuGetResourceCollection ResourcesCollection { get; set; } 26 | 27 | public PackageDependency Make(dynamic jsonObject) 28 | { 29 | PackageDependency pd = new PackageDependency(); 30 | if (jsonObject.HasProperty("id")) 31 | { 32 | pd.Id = jsonObject.id; 33 | } 34 | 35 | if (jsonObject.HasProperty("range")) 36 | { 37 | pd.DependencyVersion = DependencyVersion.ParseDependencyVersion(jsonObject.range); 38 | } 39 | 40 | return pd; 41 | } 42 | 43 | /// 44 | /// Not currently needed. Implement when required. 45 | /// 46 | public PackageDependency Make(dynamic jsonObject, PackageDependency existingObject) 47 | { 48 | throw new NotImplementedException(); 49 | } 50 | 51 | public PackageDependency Make(dynamic jsonObject, object args) 52 | { 53 | return Make(jsonObject); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Utility/PackageFilterUtility.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using Microsoft.PackageManagement.Provider.Utility; 18 | using System; 19 | using System.Collections.Generic; 20 | using System.Linq; 21 | using SMA = System.Management.Automation; 22 | 23 | /// 24 | /// Utilities to filter packages by various criteria. 25 | /// 26 | internal class PackageFilterUtility 27 | { 28 | public static IEnumerable FilterOnTags(IEnumerable pkgs, string[] tag) 29 | { 30 | if (tag.Length == 0) 31 | { 32 | return pkgs; 33 | } 34 | 35 | //Tags should be performed as *AND* intead of *OR" 36 | //For example -FilterOnTag:{ "A", "B"}, the returned package should have both A and B. 37 | return pkgs.Where(pkg => tag.All( 38 | tagFromUser => 39 | { 40 | if (string.IsNullOrWhiteSpace(pkg.Tags)) 41 | { 42 | // if there are tags and a package has no tag, don't return it 43 | return false; 44 | } 45 | var tagArray = pkg.Tags.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); 46 | return tagArray.Any(tagFromPackage => tagFromPackage.EqualsIgnoreCase(tagFromUser)); 47 | } 48 | )); 49 | } 50 | 51 | public static IEnumerable FilterOnContains(IEnumerable pkgs, string containsPattern) 52 | { 53 | if (string.IsNullOrWhiteSpace(containsPattern)) 54 | { 55 | return pkgs; 56 | } 57 | 58 | return pkgs.Where(each => each.Description.IndexOf(containsPattern, StringComparison.OrdinalIgnoreCase) > -1 || 59 | each.Id.IndexOf(containsPattern, StringComparison.OrdinalIgnoreCase) > -1); 60 | } 61 | 62 | public static IEnumerable FilterOnVersion(IEnumerable pkgs, string requiredVersion, string minimumVersion, string maximumVersion, bool minInclusive = true, bool maxInclusive = true) 63 | { 64 | if (!String.IsNullOrWhiteSpace(requiredVersion)) 65 | { 66 | pkgs = pkgs.Where(each => each.Version == new SemanticVersion(requiredVersion)); 67 | } 68 | else 69 | { 70 | if (!String.IsNullOrWhiteSpace(minimumVersion)) 71 | { 72 | // if minInclusive, then use >= else use > 73 | if (minInclusive) 74 | { 75 | pkgs = pkgs.Where(each => each.Version >= new SemanticVersion(minimumVersion)); 76 | } 77 | else 78 | { 79 | pkgs = pkgs.Where(each => each.Version > new SemanticVersion(minimumVersion)); 80 | } 81 | } 82 | 83 | if (!String.IsNullOrWhiteSpace(maximumVersion)) 84 | { 85 | // if maxInclusive, then use < else use <= 86 | if (maxInclusive) 87 | { 88 | pkgs = pkgs.Where(each => each.Version <= new SemanticVersion(maximumVersion)); 89 | } 90 | else 91 | { 92 | pkgs = pkgs.Where(each => each.Version < new SemanticVersion(maximumVersion)); 93 | } 94 | } 95 | } 96 | 97 | return pkgs; 98 | } 99 | 100 | public static IEnumerable FilterOnName(IEnumerable pkgs, string searchTerm, bool useWildCard) 101 | { 102 | if (useWildCard) 103 | { 104 | // Applying the wildcard pattern matching 105 | const SMA.WildcardOptions wildcardOptions = SMA.WildcardOptions.CultureInvariant | SMA.WildcardOptions.IgnoreCase; 106 | var wildcardPattern = new SMA.WildcardPattern(searchTerm, wildcardOptions); 107 | 108 | return pkgs.Where(p => wildcardPattern.IsMatch(p.Id)); 109 | } 110 | else 111 | { 112 | return pkgs.Where(each => each.Id.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) > -1); 113 | } 114 | } 115 | 116 | public static bool IsValidByName(PackageEntryInfo packageEntry, NuGetSearchContext searchContext) 117 | { 118 | NuGetSearchTerm originalPsTerm = searchContext.SearchTerms == null ? 119 | null : searchContext.SearchTerms.Where(st => st.Term == NuGetSearchTerm.NuGetSearchTermType.OriginalPSPattern).FirstOrDefault(); 120 | bool valid = true; 121 | if (originalPsTerm != null) 122 | { 123 | if (!String.IsNullOrWhiteSpace(originalPsTerm.Text) && SMA.WildcardPattern.ContainsWildcardCharacters(originalPsTerm.Text)) 124 | { 125 | // Applying the wildcard pattern matching 126 | const SMA.WildcardOptions wildcardOptions = SMA.WildcardOptions.CultureInvariant | SMA.WildcardOptions.IgnoreCase; 127 | var wildcardPattern = new SMA.WildcardPattern(originalPsTerm.Text, wildcardOptions); 128 | 129 | valid = wildcardPattern.IsMatch(packageEntry.Id); 130 | } 131 | else if (!String.IsNullOrWhiteSpace(originalPsTerm.Text)) 132 | { 133 | valid = packageEntry.Id.IndexOf(originalPsTerm.Text, StringComparison.OrdinalIgnoreCase) > -1; 134 | } 135 | } 136 | 137 | return valid; 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /Utility/ProgressTracker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.PackageManagement.NuGetProvider.Utility 8 | { 9 | internal class ProgressTracker 10 | { 11 | private static Random randomGen = new Random(); 12 | internal int ProgressID; 13 | internal int StartPercent; 14 | internal int EndPercent; 15 | 16 | internal ProgressTracker(int progressID) : this(progressID, 0, 100) { } 17 | 18 | internal ProgressTracker(int progressID, int startPercent, int endPercent) 19 | { 20 | ProgressID = progressID; 21 | StartPercent = startPercent; 22 | EndPercent = endPercent; 23 | } 24 | 25 | internal int ConvertPercentToProgress(double percent) 26 | { 27 | // for example, if startprogress is 50, end progress is 100, and if we want to complete 50% of that, 28 | // then the progress returned would be 75 29 | return StartPercent + (int)((EndPercent - StartPercent) * percent); 30 | } 31 | 32 | internal static ProgressTracker StartProgress(ProgressTracker parentTracker, string message, NuGetRequest request) 33 | { 34 | if (request == null) 35 | { 36 | return null; 37 | } 38 | 39 | // if parent tracker is null, use 0 for parent id, else use the progressid of parent tracker 40 | return new ProgressTracker(request.StartProgress(parentTracker == null ? 0 : parentTracker.ProgressID, message)); 41 | } 42 | 43 | /// 44 | /// Generate a random progress ID that's not 0 (0 is used a lot, so it's dangerous to use here). Eventually we want to change this to 45 | /// GetUniqueId 46 | /// but we need a way to remove used IDs first. 47 | /// 48 | /// Random progress ID in the range (0, Int32.MaxValue) 49 | internal static int GetRandomId() 50 | { 51 | return randomGen.Next(1, Int32.MaxValue); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Utility/PublicObjectView.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | /// 18 | /// Allows internal object to be used in "public" APIs 19 | /// 20 | public class PublicObjectView 21 | { 22 | internal object Value { get; private set; } 23 | 24 | public PublicObjectView(object val) 25 | { 26 | this.Value = val; 27 | } 28 | 29 | internal T GetValue() where T : class 30 | { 31 | return this.Value as T; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Utility/TaskGroup.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | // 14 | 15 | namespace Microsoft.PackageManagement.NuGetProvider 16 | { 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Threading.Tasks; 20 | 21 | /// 22 | /// Tracks a group of tasks with the same result type. 23 | /// 24 | /// Result type of tasks. 25 | internal class TaskGroup 26 | { 27 | /// 28 | /// Inner tasks 29 | /// 30 | private List> tasks; 31 | 32 | /// 33 | /// Gets if this task group has any tasks remaining 34 | /// 35 | public bool HasAny 36 | { 37 | get 38 | { 39 | return tasks.Count > 0; 40 | } 41 | } 42 | 43 | public TaskGroup() 44 | { 45 | tasks = new List>(); 46 | } 47 | 48 | /// 49 | /// Add a task for this TaskGroup to track 50 | /// 51 | public void Add(Task task) 52 | { 53 | tasks.Add(task); 54 | } 55 | 56 | /// 57 | /// Wait for any task to complete and get the result. 58 | /// 59 | /// Result of the first completed task. 60 | public TResult WaitAny() 61 | { 62 | int index = Task.WaitAny(tasks.Cast().ToArray()); 63 | TResult result = tasks[index].Result; 64 | tasks.RemoveAt(index); 65 | return result; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | image: Visual Studio 2017 3 | configuration: Release 4 | platform: Any CPU 5 | 6 | # Install Pester 7 | init: 8 | - cinst -y pester --force 9 | 10 | install: 11 | 12 | - ps: $psversiontable 13 | - reg ADD "HKLM\Software\Microsoft\StrongName\Verification\Microsoft.PackageManagement.NuGetProvider,31bf3856ad364e35" /f 14 | - reg ADD "HKLM\Software\Wow6432Node\Microsoft\StrongName\Verification\Microsoft.PackageManagement.NuGetProvider,31bf3856ad364e35" /f 15 | 16 | before_build: 17 | - ps: | 18 | .\Generate-Resources.ps1 19 | Push-Location .\vs-csproj 20 | nuget restore -PackagesDirectory (Join-Path $pwd packages) 21 | Pop-Location 22 | build_script: 23 | - msbuild "vs-csproj\NugetLightProvider.csproj" /verbosity:normal 24 | - ps: .\build.ps1 -Framework all -Configuration Release -Destination temp # Binaries are not used, just to verify compilation is not broken 25 | after_build: 26 | - ps: | 27 | Get-ChildItem "C:\output\release\bin" -Recurse | ForEach-Object { Push-AppveyorArtifact $_.FullName -FileName $_.Name -DeploymentName releasebits -Type Auto } 28 | 29 | before_test: 30 | - ps: | 31 | # Import the Nuget provider just built 32 | Import-PackageProvider C:\output\release\bin\Microsoft.PackageManagement.NuGetProvider.dll -Force -Verbose 33 | 34 | & .\smoketest.tests.ps1 35 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | <# Build NuGetProvider to be used immediately by PackageManagement #> 2 | param( 3 | [Parameter(Mandatory=$false)] 4 | [string] 5 | [ValidateSet('net472', 'netstandard2.0', 'all')] 6 | $Framework = 'net472', 7 | 8 | [Parameter(Mandatory=$false)] 9 | [string] 10 | $Destination, 11 | 12 | [Parameter(Mandatory=$false)] 13 | [string] 14 | $Configuration = "Debug" 15 | ) 16 | 17 | & "$PSScriptRoot\Generate-Resources.ps1" 18 | 19 | if ($Framework -eq 'all') { 20 | $frameworks = @('net472', 'netstandard2.0') 21 | } else { 22 | $frameworks = @($Framework) 23 | } 24 | 25 | foreach ($f in $frameworks) { 26 | dotnet build --framework $f --configuration $Configuration 27 | if ($Destination) { 28 | $copyDir = $Destination.Replace("{Root}", $OneGetRepositoryRoot) 29 | if ($f -eq 'net472') { 30 | $copyDir += "\\fullclr" 31 | } else { 32 | $copyDir += "\\coreclr\\$f" 33 | } 34 | 35 | if (-not (Test-Path -Path $copyDir)) { 36 | $null = New-Item -Path $copyDir -ItemType Directory 37 | } 38 | 39 | $outDir = Join-Path -Path $PSScriptRoot -ChildPath "bin" | Join-Path -ChildPath "Debug" | Join-Path -ChildPath $f 40 | $dllPath = Join-Path -Path $outDir -ChildPath "Microsoft.PackageManagement.NuGetProvider.dll" 41 | $pdbPath = Join-Path -Path $outDir -ChildPath "Microsoft.PackageManagement.NuGetProvider.pdb" 42 | if (Test-Path -Path $dllPath) { 43 | Copy-Item -Path $dllPath -Destination (Join-Path -Path $copyDir -ChildPath "Microsoft.PackageManagement.NuGetProvider.dll") -Force 44 | } 45 | 46 | if (Test-Path -Path $pdbPath) { 47 | Copy-Item -Path $pdbPath -Destination (Join-Path -Path $copyDir -ChildPath "Microsoft.PackageManagement.NuGetProvider.pdb") -Force 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pack.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Create a NuGet package from an output location 3 | #> 4 | [CmdletBinding()] 5 | param( 6 | # e.g. C:\git\nugetprovider\bin\Release 7 | [Parameter(Mandatory = $true)] 8 | [string] 9 | $OutputRootDir, 10 | 11 | [Parameter(Mandatory = $false)] 12 | [string] 13 | $PackageId = "Microsoft.PowerShell.PackageManagement.NuGetProvider", 14 | 15 | [Parameter(Mandatory = $false)] 16 | [string] 17 | $Authors = "Microsoft", 18 | 19 | [Parameter(Mandatory = $false)] 20 | [string] 21 | $Owners = "brywang", 22 | 23 | [Parameter(Mandatory = $false)] 24 | [string[]] 25 | $ReleaseNotes, 26 | 27 | [Parameter(Mandatory = $false)] 28 | [string] 29 | $ReleaseNotesFile, 30 | 31 | [Parameter(Mandatory = $false)] 32 | [switch] 33 | $IncludePdbs, 34 | 35 | [Parameter(Mandatory = $false)] 36 | [switch] 37 | $RefreshNuGetClient, 38 | 39 | [Parameter(Mandatory = $false)] 40 | [string] 41 | $PackageOutDir, 42 | 43 | [Parameter(Mandatory = $false)] 44 | [string] 45 | $PrereleaseString 46 | ) 47 | 48 | if (-not $PackageOutDir) { 49 | $PackageOutDir = $PSScriptRoot 50 | } 51 | 52 | $nugetCommand = Get-Command nuget -ErrorAction Ignore 53 | if ((-not $nugetCommand) -or $RefreshNuGetClient) { 54 | Write-Verbose "Downloading latest NuGet.exe" 55 | $null = Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile (Join-Path -Path $PSScriptRoot -ChildPath nuget.exe) 56 | $nugetCommand = Get-Command nuget -ErrorAction Ignore 57 | } 58 | 59 | Write-Verbose "Using NuGet version: $($nugetCommand.Version)" 60 | $nugetPath = $nugetCommand.Source 61 | $tempDir = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetRandomFileName()) 62 | $null = New-Item -Path $tempDir -ItemType Directory 63 | try { 64 | $version = $null 65 | foreach ($frameworkPathItem in (Get-ChildItem -Path $OutputRootDir -Directory)) { 66 | $framework = Split-Path -Path $frameworkPathItem.FullName -Leaf 67 | $libDir = Join-Path -Path $tempDir -ChildPath 'lib' | Join-Path -ChildPath $framework 68 | if (-not (Test-Path -Path $libDir)) { 69 | $null = New-Item -Path $libDir -ItemType Directory 70 | } 71 | 72 | $dllPath = Join-Path -Path $frameworkPathItem.FullName -ChildPath "Microsoft.PackageManagement.NuGetProvider.dll" 73 | Write-Verbose "Preparing file: $($dllPath)" 74 | Copy-Item -Path $dllPath -Destination $libDir 75 | if (-not $version) { 76 | $version = [System.Reflection.AssemblyName]::GetAssemblyName($dllPath).Version.ToString() 77 | } 78 | 79 | if ($IncludePdbs) { 80 | $dllPath = Join-Path -Path $frameworkPathItem.FullName -ChildPath "Microsoft.PackageManagement.NuGetProvider.pdb" 81 | Write-Verbose "Preparing file: $($dllPath)" 82 | Copy-Item -Path $dllPath -Destination $libDir 83 | } 84 | } 85 | 86 | if (-not $version) { 87 | throw "Couldn't discover version of package - is Microsoft.PackageManagement.dll there?" 88 | } 89 | 90 | if ($PrereleaseString) { 91 | $version += "-$PrereleaseString" 92 | } 93 | 94 | $nuspecContents = Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath 'NuGetProvider.nuspec') | Out-String 95 | Write-Verbose "Setting Package.Id = $PackageId" 96 | $nuspecContents = $nuspecContents -replace "{name}",$PackageId 97 | Write-Verbose "Setting Package.Version = $version" 98 | $nuspecContents = $nuspecContents -replace "{version}",$version 99 | Write-Verbose "Setting Package.Authors = $Authors" 100 | $nuspecContents = $nuspecContents -replace "{authors}",$Authors 101 | Write-Verbose "Setting Package.Owners = $Owners" 102 | $nuspecContents = $nuspecContents -replace "{owners}",$Owners 103 | if ($ReleaseNotesFile) { 104 | if (-not (Test-Path -Path $ReleaseNotesFile)) { 105 | throw "Release notes file '$ReleaseNotesFile' does not exist" 106 | } 107 | 108 | $ReleaseNotes = Get-Content -Path $ReleaseNotesFile | Out-String 109 | } else { 110 | $ReleaseNotes = $ReleaseNotes | Out-String 111 | } 112 | 113 | Write-Verbose "Setting Package.ReleaseNotes = '$ReleaseNotes'" 114 | $nuspecContents = $nuspecContents -replace "{releaseNotes}",$ReleaseNotes 115 | $nuspecName = "temp.nuspec" 116 | $nuspecContents | Out-File -FilePath (Join-Path -Path $tempDir -ChildPath $nuspecName) 117 | Write-Verbose "Packing..." 118 | Push-Location -Path $tempDir 119 | & $nugetPath pack $nuspecName 120 | Pop-Location 121 | if ($LastExitCode -gt 0) { 122 | throw 'NuGet.exe pack failed. See previous error messages.' 123 | } 124 | 125 | Write-Verbose "Copying package to $PackageOutDir" 126 | Get-ChildItem -Path (Join-Path -Path $tempDir -ChildPath "*.nupkg") | Select-Object -First 1 | Select-Object -ExpandProperty FullName | Copy-Item -Destination $PackageOutDir 127 | } finally { 128 | $tries = 3 129 | while ((Test-Path -Path $tempDir) -and ($tries -gt 0)) { 130 | try { 131 | $null = Remove-Item -Path $tempDir -Recurse -Force -ErrorAction Ignore 132 | } catch { 133 | } 134 | 135 | if ((Test-Path -Path $tempDir) -and ($tries -gt 0)) { 136 | Start-Sleep -Milliseconds (100 * $tries) 137 | $tries = $tries - 1 138 | } 139 | } 140 | 141 | if (Test-Path -path $tempDir) { 142 | Write-Warning "Failed to remove temp directory: $tempDir" 143 | } 144 | } 145 | 146 | Write-Verbose "Done" -------------------------------------------------------------------------------- /provider.manifest: -------------------------------------------------------------------------------- 1 |  2 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /releasenotes.md: -------------------------------------------------------------------------------- 1 | # 3.0.0.2 2 | ## What's new? 3 | - Packaged as a NuGet package on https://powershell.myget.org/feed/Packages/powershellmodule 4 | 5 | # 3.0.0.1 6 | ## What's new? 7 | - Now supports NuGet v3 URLs, like https://api.nuget.org/v3/index.json -------------------------------------------------------------------------------- /smoketest.tests.ps1: -------------------------------------------------------------------------------- 1 |  2 | Describe "Smoke testing" -Tags "Feature" { 3 | 4 | BeforeAll{ 5 | Register-PackageSource -Name Nugettest -provider NuGet -Location https://www.nuget.org/api/v2 -force 6 | 7 | } 8 | 9 | it "EXPECTED: Find a package" { 10 | $a = Find-Package -ProviderName NuGet -Name jquery -source Nugettest 11 | $a.Name -contains "jquery" | should be $true 12 | } 13 | 14 | it "EXPECTED: Install a package" { 15 | $a = install-Package -ProviderName NuGet -Name jquery -force -source Nugettest 16 | $a.Name -contains "jquery" | should be $true 17 | } 18 | 19 | 20 | it "EXPECTED: Get a package" { 21 | $a = Get-Package -ProviderName NuGet -Name jquery 22 | $a.Name -contains "jquery" | should be $true 23 | } 24 | 25 | it "EXPECTED: save a package" { 26 | $a = save-Package -ProviderName NuGet -Name jquery -path $TestDrive -force -source Nugettest 27 | $a.Name -contains "jquery" | should be $true 28 | } 29 | 30 | it "EXPECTED: uninstall a package" { 31 | $a = uninstall-Package -ProviderName NuGet -Name jquery 32 | $a.Name -contains "jquery" | should be $true 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /tools/mt.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneGet/NuGetProvider/6c486d0de4f4c550615467d2b1298e5fb0cdcd2b/tools/mt.exe -------------------------------------------------------------------------------- /vs-csproj/NugetLightProvider.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Release 6 | AnyCPU 7 | {CE99A5EB-84AF-4445-B689-3E1C50F071DF} 8 | Library 9 | Properties 10 | Microsoft.PackageManagement.NuGetProvider 11 | Microsoft.PackageManagement.NuGetProvider 12 | 512 13 | $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), solution.props))\solution.props 14 | 15 | v4.5 16 | 17 | 18 | true 19 | 20 | 21 | ..\35MSSharedLib1024.snk 22 | 23 | 24 | true 25 | 26 | 27 | 28 | 29 | $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), PackageProvider.sln))\ 30 | $(SolutionDir) 31 | 32 | v4.0 33 | v4.5.2 34 | $(SolutionRootDir)..\output\$(Configuration)\bin\ 35 | $(SolutionRootDir)..\intermediate\$(TargetFrameworkVersion.Replace(".",""))\$(Configuration)\$(AssemblyName)\ 36 | $(BaseIntermediateOutputPath) 37 | $(OutputPath)$(AssemblyName).XML 38 | 1591 39 | true 40 | FRAMEWORK$(TargetFrameworkVersion.Replace(".","")) 41 | ..\output\$(TargetFrameworkVersion.Replace(".",""))\$(Configuration)\bin\ 42 | 43 | 44 | true 45 | full 46 | false 47 | $(DefineConstants);DEBUG;TRACE 48 | prompt 49 | 4 50 | ..\output\v40\Debug\bin\Microsoft.PackageManagement.NuGetProvider.xml 51 | false 52 | ..\output\bin\ 53 | 54 | 55 | pdbonly 56 | false 57 | TRACE 58 | prompt 59 | 4 60 | 61 | 62 | false 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | Code 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | Code 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | True 127 | True 128 | Messages.resx 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | ResXFileCodeGenerator 158 | Messages.Designer.cs 159 | Designer 160 | Microsoft.PackageManagement.NuGetProvider.Resources 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | False 173 | C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | .\packages\Microsoft.PowerShell.PackageManagement.Core.1.2.1-preview\lib\net45\Microsoft.PackageManagement.dll 183 | True 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | :Locate MT.EXE Tool: 195 | set MTEXE=$(ProjectDir)\..\tools\mt.exe 196 | 197 | :Run the tool to add the manifest to the binary. 198 | 199 | "%25MTEXE%25" -manifest $(ProjectDir)..\provider.manifest -outputresource:$(TargetPath);#101 200 | 201 | 208 | -------------------------------------------------------------------------------- /vs-csproj/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | --------------------------------------------------------------------------------