77using NuGet . Versioning ;
88
99namespace NugetInspector
10- {
11- #pragma warning disable IDE1006
10+ {
11+ #pragma warning disable IDE1006
1212 public class Dependency
1313 {
1414 public string ? name ;
1515 public NuGetFramework ? framework ;
1616 public VersionRange ? version_range ;
17+ public string type ;
1718 public bool is_direct ;
1819
1920 //True only for legacy packages.config-based projects only when set there
2021 public bool is_development_dependency = false ;
2122
2223 public Dependency (
2324 string ? name ,
25+ string type ,
2426 VersionRange ? version_range ,
2527 NuGetFramework ? framework = null ,
2628 bool is_direct = false ,
2729 bool is_development_dependency = false )
2830 {
2931 this . framework = framework ;
3032 this . name = name ;
33+ this . type = type ;
3134 this . version_range = version_range ;
3235 this . is_direct = is_direct ;
3336 this . is_development_dependency = is_development_dependency ;
@@ -40,6 +43,7 @@ public BasePackage CreateEmptyBasePackage()
4043 {
4144 return new BasePackage (
4245 name : name ! ,
46+ type : type ,
4347 version : version_range ? . MinVersion . ToNormalizedString ( ) ,
4448 framework : framework ? . ToString ( )
4549 ) ;
@@ -144,6 +148,12 @@ public VersionPair(string rawVersion, NuGetVersion version)
144148 }
145149 }
146150
151+ public static class ComponentType
152+ {
153+ public const string NuGet = "nuget" ;
154+ public const string Project = "project" ;
155+ }
156+
147157 /// <summary>
148158 /// Package data object using purl as identifying attributes as
149159 /// specified here https://github.com/package-url/purl-spec
@@ -192,13 +202,14 @@ public class BasePackage : IEquatable<BasePackage>, IComparable<BasePackage>
192202
193203 // Track if we updated this package metadata
194204 [ JsonIgnore ]
195- public bool has_updated_metadata ;
196-
197- public BasePackage ( ) { }
205+ public bool has_updated_metadata ;
206+
207+ public BasePackage ( ) { }
198208
199- public BasePackage ( string name , string ? version , string ? framework = "" , string ? datafile_path = "" )
209+ public BasePackage ( string name , string type , string ? version , string ? framework = "" , string ? datafile_path = "" )
200210 {
201211 this . name = name ;
212+ this . type = type ;
202213 this . version = version ;
203214 if ( ! string . IsNullOrWhiteSpace ( framework ) )
204215 this . version = version ;
@@ -210,7 +221,7 @@ public BasePackage(string name, string? version, string? framework = "", string?
210221
211222 public static BasePackage FromPackage ( BasePackage package , List < BasePackage > dependencies )
212223 {
213- return new ( name : package . name , version : package . version )
224+ return new ( name : package . name , type : package . type , version : package . version )
214225 {
215226 extra_data = package . extra_data ,
216227 dependencies = dependencies
@@ -220,13 +231,14 @@ public static BasePackage FromPackage(BasePackage package, List<BasePackage> dep
220231 ///<summary>
221232 /// Return a deep clone of this package. Optionally clone dependencies.
222233 ///</summary>
223- public BasePackage Clone ( bool with_deps = false )
234+ public BasePackage Clone ( bool with_deps = false )
224235 {
225236 List < BasePackage > deps = with_deps ? dependencies : new List < BasePackage > ( ) ;
226237
227238 return new BasePackage (
228239 name : name ,
229- version : version ,
240+ type : type ,
241+ version : version ,
230242 datafile_path : datafile_path
231243 )
232244 {
@@ -318,7 +330,8 @@ public void Update(NugetApi nugetApi, bool with_details = false)
318330
319331 try
320332 {
321- UpdateWithRemoteMetadata ( nugetApi , with_details : with_details ) ;
333+ if ( ! type . Equals ( ComponentType . Project ) )
334+ UpdateWithRemoteMetadata ( nugetApi , with_details : with_details ) ;
322335 }
323336 catch ( Exception ex )
324337 {
@@ -527,7 +540,8 @@ public static string GetApiDataUrl(PackageIdentity pid, SourcePackageDependencyI
527540 /// <summary>
528541 /// Sort recursively the dependencies of this package.
529542 /// </summary>
530- public void Sort ( ) {
543+ public void Sort ( )
544+ {
531545 dependencies . Sort ( ) ;
532546 foreach ( var dep in dependencies )
533547 dep . Sort ( ) ;
@@ -599,12 +613,13 @@ public class Party
599613
600614 public Party Clone ( )
601615 {
602- return new Party ( ) {
603- type = type ,
604- role = role ,
605- name = name ,
606- email = email ,
607- url = url
616+ return new Party ( )
617+ {
618+ type = type ,
619+ role = role ,
620+ name = name ,
621+ email = email ,
622+ url = url
608623 } ;
609624 }
610625 }
@@ -631,14 +646,15 @@ public class PackageDownload
631646 public string hash { get ; set ; } = "" ;
632647 public string hash_algorithm { get ; set ; } = "" ;
633648 public int ? size { get ; set ; } = 0 ;
634- public bool IsEnhanced ( ) {
649+ public bool IsEnhanced ( )
650+ {
635651 return ! string . IsNullOrWhiteSpace ( download_url ) && ! string . IsNullOrWhiteSpace ( hash ) ;
636652 }
637653
638654 public static PackageDownload FromSpdi ( SourcePackageDependencyInfo spdi )
639655 {
640- PackageDownload download = new ( ) { download_url = spdi . DownloadUri . ToString ( ) } ;
641- /// Note that this hash is unlikely there per https://github.com/NuGet/NuGetGallery/issues/9433
656+ PackageDownload download = new ( ) { download_url = spdi . DownloadUri . ToString ( ) } ;
657+ // Note that this hash is unlikely there per https://github.com/NuGet/NuGetGallery/issues/9433
642658 if ( ! string . IsNullOrEmpty ( spdi . PackageHash ) )
643659 {
644660 download . hash = spdi . PackageHash ;
0 commit comments