@@ -35,6 +35,7 @@ public class PackageBuilder : IPackageMetadata
3535 private readonly bool _includeEmptyDirectories ;
3636 private readonly bool _deterministic ;
3737 private readonly ILogger _logger ;
38+ private readonly string _versionOverride ;
3839
3940 /// <summary>
4041 /// Maximum Icon file size: 1 megabyte
@@ -52,7 +53,12 @@ public PackageBuilder(string path, Func<string, string> propertyProvider, bool i
5253 }
5354
5455 public PackageBuilder ( string path , Func < string , string > propertyProvider , bool includeEmptyDirectories , bool deterministic , ILogger logger )
55- : this ( path , Path . GetDirectoryName ( path ) , propertyProvider , includeEmptyDirectories , deterministic , logger )
56+ : this ( path , Path . GetDirectoryName ( path ) , propertyProvider , includeEmptyDirectories , deterministic , logger , versionOverride : "" )
57+ {
58+ }
59+
60+ public PackageBuilder ( string path , Func < string , string > propertyProvider , bool includeEmptyDirectories , bool deterministic , ILogger logger , string versionOverride )
61+ : this ( path , Path . GetDirectoryName ( path ) , propertyProvider , includeEmptyDirectories , deterministic , logger , versionOverride )
5662 {
5763 }
5864
@@ -62,12 +68,21 @@ public PackageBuilder(string path, string basePath, Func<string, string> propert
6268 }
6369
6470 public PackageBuilder ( string path , string basePath , Func < string , string > propertyProvider , bool includeEmptyDirectories , bool deterministic , ILogger logger )
65- : this ( path , basePath , propertyProvider , includeEmptyDirectories , deterministic )
71+ : this ( path , basePath , propertyProvider , includeEmptyDirectories , deterministic , logger , versionOverride : "" )
72+ {
73+ }
74+ public PackageBuilder ( string path , string basePath , Func < string , string > propertyProvider , bool includeEmptyDirectories , bool deterministic , ILogger logger , string versionOverride )
75+ : this ( path , basePath , propertyProvider , includeEmptyDirectories , deterministic , versionOverride )
6676 {
6777 _logger = logger ;
6878 }
6979
7080 public PackageBuilder ( string path , string basePath , Func < string , string > propertyProvider , bool includeEmptyDirectories , bool deterministic )
81+ : this ( path , basePath , propertyProvider , includeEmptyDirectories , deterministic , versionOverride : "" )
82+ {
83+
84+ }
85+ public PackageBuilder ( string path , string basePath , Func < string , string > propertyProvider , bool includeEmptyDirectories , bool deterministic , string versionOverride )
7186 : this ( includeEmptyDirectories , deterministic )
7287 {
7388 if ( ! File . Exists ( path ) )
@@ -77,6 +92,8 @@ public PackageBuilder(string path, string basePath, Func<string, string> propert
7792 string . Format ( CultureInfo . CurrentCulture , Strings . ErrorManifestFileNotFound , path ?? "null" ) ) ;
7893 }
7994
95+ _versionOverride = versionOverride ;
96+
8097 using ( Stream stream = File . OpenRead ( path ) )
8198 {
8299 ReadManifest ( stream , basePath , propertyProvider ) ;
@@ -89,8 +106,14 @@ public PackageBuilder(Stream stream, string basePath)
89106 }
90107
91108 public PackageBuilder ( Stream stream , string basePath , Func < string , string > propertyProvider )
109+ : this ( stream , basePath , propertyProvider , "" )
110+ {
111+ }
112+
113+ public PackageBuilder ( Stream stream , string basePath , Func < string , string > propertyProvider , string versionOverride )
92114 : this ( )
93115 {
116+ _versionOverride = versionOverride ;
94117 ReadManifest ( stream , basePath , propertyProvider ) ;
95118 }
96119
@@ -921,7 +944,11 @@ private void ValidateReadmeFile(IEnumerable<IPackageFile> files, string readmePa
921944 private void ReadManifest ( Stream stream , string basePath , Func < string , string > propertyProvider )
922945 {
923946 // Deserialize the document and extract the metadata
924- Manifest manifest = Manifest . ReadFrom ( stream , propertyProvider , validateSchema : true ) ;
947+ Manifest manifest = Manifest . ReadFrom (
948+ stream ,
949+ propertyProvider ,
950+ validateSchema : true ,
951+ overrideVersion : ! ( string . IsNullOrEmpty ( _versionOverride ) ) ? NuGetVersion . Parse ( _versionOverride ) : null ) ;
925952
926953 Populate ( manifest . Metadata ) ;
927954
0 commit comments