@@ -41,7 +41,8 @@ public static void WriteNuspec(
4141 RepositoryMetadata repositoryMetadata = null ,
4242 Func < string > getCustomNodes = null ,
4343 string licenseExpression = null ,
44- string licenseFilename = null )
44+ string licenseFilename = null ,
45+ string iconFilename = null )
4546 {
4647 var fullNuspec = ( @"<?xml version=""1.0""?>
4748 <package xmlns=""http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"">
@@ -60,6 +61,7 @@ public static void WriteNuspec(
6061 <releaseNotes>" + ( releaseNotes ?? string . Empty ) + @"</releaseNotes>
6162 <licenseUrl>" + ( licenseUrl ? . AbsoluteUri ?? string . Empty ) + @"</licenseUrl>
6263 " + WriteLicense ( licenseExpression , licenseFilename ) + @"
64+ " + WriteIcon ( iconFilename ) + @"
6365 <projectUrl>" + ( projectUrl ? . ToString ( ) ?? string . Empty ) + @"</projectUrl>
6466 <iconUrl>" + ( iconUrl ? . ToString ( ) ?? string . Empty ) + @"</iconUrl>
6567 <packageTypes>" + WritePackageTypes ( packageTypes ) + @"</packageTypes>
@@ -102,6 +104,16 @@ private static string WriteLicense(string licenseExpression, string licenseFilen
102104 return stringBuilder . ToString ( ) ;
103105 }
104106
107+ private static string WriteIcon ( string iconFilename )
108+ {
109+ if ( iconFilename != null )
110+ {
111+ return $ "<icon>{ iconFilename } </icon>";
112+ }
113+
114+ return string . Empty ;
115+ }
116+
105117 private static string WriteRepositoryMetadata ( RepositoryMetadata repositoryMetadata )
106118 {
107119 return repositoryMetadata == null
@@ -198,7 +210,9 @@ public static MemoryStream CreateTestPackageStream(
198210 Func < string > getCustomNuspecNodes = null ,
199211 string licenseExpression = null ,
200212 string licenseFilename = null ,
201- byte [ ] licenseFileContents = null )
213+ byte [ ] licenseFileContents = null ,
214+ string iconFilename = null ,
215+ byte [ ] iconFileContents = null )
202216 {
203217 return CreateTestPackageStream ( packageArchive =>
204218 {
@@ -208,19 +222,11 @@ public static MemoryStream CreateTestPackageStream(
208222 WriteNuspec ( stream , true , id , version , title , summary , authors , owners , description , tags , language ,
209223 copyright , releaseNotes , minClientVersion , licenseUrl , projectUrl , iconUrl ,
210224 requireLicenseAcceptance , packageDependencyGroups , packageTypes , isSymbolPackage , repositoryMetadata ,
211- getCustomNuspecNodes , licenseExpression , licenseFilename ) ;
225+ getCustomNuspecNodes , licenseExpression , licenseFilename , iconFilename ) ;
212226 }
213227
214- if ( licenseFileContents != null && licenseFilename != null )
215- {
216- // enforce directory separators the same way as the client (see PackageArchiveReader.GetStream)
217- licenseFilename = PathUtility . StripLeadingDirectorySeparators ( licenseFilename ) ;
218- var licenseEntry = packageArchive . CreateEntry ( licenseFilename , CompressionLevel . Fastest ) ;
219- using ( var licenseStream = licenseEntry . Open ( ) )
220- {
221- licenseStream . Write ( licenseFileContents , 0 , licenseFileContents . Length ) ;
222- }
223- }
228+ licenseFilename = AddBinaryFile ( packageArchive , licenseFilename , licenseFileContents ) ;
229+ iconFilename = AddBinaryFile ( packageArchive , iconFilename , iconFileContents ) ;
224230
225231 if ( populatePackage != null )
226232 {
@@ -229,6 +235,22 @@ public static MemoryStream CreateTestPackageStream(
229235 } , desiredTotalEntryCount ) ;
230236 }
231237
238+ private static string AddBinaryFile ( ZipArchive archive , string filename , byte [ ] fileContents )
239+ {
240+ if ( fileContents != null && filename != null )
241+ {
242+ // enforce directory separators the same way as the client (see PackageArchiveReader.GetStream)
243+ filename = PathUtility . StripLeadingDirectorySeparators ( filename ) ;
244+ var fileEntry = archive . CreateEntry ( filename , CompressionLevel . Fastest ) ;
245+ using ( var fileStream = fileEntry . Open ( ) )
246+ {
247+ fileStream . Write ( fileContents , 0 , fileContents . Length ) ;
248+ }
249+ }
250+
251+ return filename ;
252+ }
253+
232254 public static MemoryStream CreateTestSymbolPackageStream ( string id = "theId" , string version = "1.0.42" , Action < ZipArchive > populatePackage = null )
233255 {
234256 var packageTypes = new List < ClientPackageType > ( ) ;
0 commit comments