@@ -85,6 +85,12 @@ class RegisterPSResourceRepository : PSCmdlet
85
85
[ ValidateRange ( 0 , 100 ) ]
86
86
public int Priority { get ; set ; } = DefaultPriority ;
87
87
88
+ /// <summary>
89
+ /// Specifies the Api version of the repository to be set.
90
+ /// </sumamry>
91
+ [ Parameter ( ParameterSetName = NameParameterSet ) ]
92
+ public PSRepositoryInfo . APIVersion ApiVersion { get ; set ; }
93
+
88
94
/// <summary>
89
95
/// Specifies vault and secret names as PSCredentialInfo for the repository.
90
96
/// </summary>
@@ -115,6 +121,12 @@ protected override void ProcessRecord()
115
121
{
116
122
List < PSRepositoryInfo > items = new List < PSRepositoryInfo > ( ) ;
117
123
124
+ PSRepositoryInfo . APIVersion ? repoApiVersion = null ;
125
+ if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( ApiVersion ) ) )
126
+ {
127
+ repoApiVersion = ApiVersion ;
128
+ }
129
+
118
130
switch ( ParameterSetName )
119
131
{
120
132
case NameParameterSet :
@@ -128,7 +140,7 @@ protected override void ProcessRecord()
128
140
129
141
try
130
142
{
131
- items . Add ( RepositorySettings . AddRepository ( Name , _uri , Priority , Trusted , null , CredentialInfo , Force , this , out string errorMsg ) ) ;
143
+ items . Add ( RepositorySettings . AddRepository ( Name , _uri , Priority , Trusted , repoApiVersion , CredentialInfo , Force , this , out string errorMsg ) ) ;
132
144
133
145
if ( ! string . IsNullOrEmpty ( errorMsg ) )
134
146
{
@@ -325,14 +337,28 @@ private PSRepositoryInfo RepoValidationHelper(Hashtable repo)
325
337
return null ;
326
338
}
327
339
340
+ if ( repo . ContainsKey ( "ApiVersion" ) &&
341
+ ( repo [ "ApiVersion" ] == null || String . IsNullOrEmpty ( repo [ "ApiVersion" ] . ToString ( ) ) ||
342
+ ! ( repo [ "ApiVersion" ] . ToString ( ) . Equals ( "local" ) || repo [ "ApiVersion" ] . ToString ( ) . Equals ( "v2" ) ||
343
+ repo [ "ApiVersion" ] . ToString ( ) . Equals ( "v3" ) || repo [ "ApiVersion" ] . ToString ( ) . Equals ( "nugetServer" ) || repo [ "ApiVersion" ] . ToString ( ) . Equals ( "unknown" ) ) ) )
344
+ {
345
+ WriteError ( new ErrorRecord (
346
+ new PSInvalidOperationException ( "Repository ApiVersion must be either 'local', 'v2', 'v3', 'nugetServer' or 'unknown'" ) ,
347
+ "IncorrectApiVersionForRepositoriesParameterSetRegistration" ,
348
+ ErrorCategory . InvalidArgument ,
349
+ this ) ) ;
350
+
351
+ return null ;
352
+ }
353
+
328
354
try
329
355
{
330
356
WriteDebug ( $ "Registering repository '{ repo [ "Name" ] } ' with uri '{ repoUri } '") ;
331
357
var addedRepo = RepositorySettings . AddRepository ( repo [ "Name" ] . ToString ( ) ,
332
358
repoUri ,
333
359
repo . ContainsKey ( "Priority" ) ? Convert . ToInt32 ( repo [ "Priority" ] . ToString ( ) ) : DefaultPriority ,
334
360
repo . ContainsKey ( "Trusted" ) ? Convert . ToBoolean ( repo [ "Trusted" ] . ToString ( ) ) : DefaultTrusted ,
335
- apiVersion : null ,
361
+ apiVersion : repo . ContainsKey ( "Trusted" ) ? ( PSRepositoryInfo . APIVersion ? ) repo [ "ApiVersion" ] : null ,
336
362
repoCredentialInfo ,
337
363
Force ,
338
364
this ,
0 commit comments