@@ -300,6 +300,95 @@ Task ("component-setup").Does (() =>
300300 }
301301} ) ;
302302
303+
304+ Task ( "nuget-setup" ) . IsDependentOn ( "buildtasks" ) . IsDependentOn ( "externals" )
305+ . Does ( ( ) =>
306+ {
307+
308+ Action < FilePath , FilePath > mergeTargetsFiles = ( FilePath fromFile , FilePath intoFile ) =>
309+ {
310+ // Load the doc to append to, and the doc to append
311+ var xOrig = System . Xml . Linq . XDocument . Load ( MakeAbsolute ( intoFile ) . FullPath ) ;
312+ System . Xml . Linq . XNamespace nsOrig = xOrig . Root . Name . Namespace ;
313+ var xMerge = System . Xml . Linq . XDocument . Load ( MakeAbsolute ( fromFile ) . FullPath ) ;
314+ System . Xml . Linq . XNamespace nsMerge = xMerge . Root . Name . Namespace ;
315+ // Add all the elements under <Project> into the existing file's <Project> node
316+ foreach ( var xItemToAdd in xMerge . Element ( nsMerge + "Project" ) . Elements ( ) )
317+ xOrig . Element ( nsOrig + "Project" ) . Add ( xItemToAdd ) ;
318+
319+ xOrig . Save ( MakeAbsolute ( intoFile ) . FullPath ) ;
320+ } ;
321+
322+ var templateText = FileReadText ( "./template.targets" ) ;
323+
324+ var nugetArtifacts = ARTIFACTS . ToList ( ) ;
325+ nugetArtifacts . Add ( new ArtifactInfo ( SUPPORT_PKG_NAME , "support-v4" , "Xamarin.Android.Support.v4" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ) ;
326+
327+ foreach ( var art in nugetArtifacts ) {
328+
329+ var proguardFile = new FilePath ( string . Format ( "./externals/{0}/proguard.txt" , art . ArtifactId ) ) ;
330+
331+ var targetsText = templateText ;
332+ var targetsFile = new FilePath ( string . Format ( "{0}/nuget/{1}.targets" , art . ArtifactId , art . NugetId ) ) ;
333+ FileWriteText ( targetsFile , targetsText ) ;
334+
335+ // Transform all .targets files
336+ var xTargets = System . Xml . Linq . XDocument . Load ( MakeAbsolute ( targetsFile ) . FullPath ) ;
337+ System . Xml . Linq . XNamespace nsTargets = xTargets . Root . Name . Namespace ;
338+
339+ if ( FileExists ( proguardFile ) ) {
340+ var projElem = xTargets . Element ( nsTargets + "Project" ) ;
341+
342+ Information ( "Adding {0} to {1}" , "proguard.txt" , targetsFile ) ;
343+
344+ projElem . Add ( new System . Xml . Linq . XElement ( nsTargets + "ItemGroup" ,
345+ new System . Xml . Linq . XElement ( nsTargets + "ProguardConfiguration" ,
346+ new System . Xml . Linq . XAttribute ( "Include" , "$(MSBuildThisFileDirectory)..\\ ..\\ proguard\\ proguard.txt" ) ) ) ) ;
347+ }
348+
349+ xTargets . Save ( MakeAbsolute ( targetsFile ) . FullPath ) ;
350+
351+ // Check for an existing .targets file in this nuget package
352+ // we need to merge the generated one with it if it exists
353+ // nuget only allows one automatic .targets file in the build/ folder
354+ // of the nuget package, which must be named {nuget-package-id}.targets
355+ // so we need to merge them all into one
356+ var mergeFile = new FilePath ( art . ArtifactId + "/nuget/merge.targets" ) ;
357+
358+ if ( FileExists ( mergeFile ) ) {
359+ Information ( "merge.targets found, merging into generated file..." ) ;
360+ mergeTargetsFiles ( mergeFile , targetsFile ) ;
361+ }
362+
363+
364+ // Transform all template.nuspec files
365+ var nuspecText = FileReadText ( art . ArtifactId + "/nuget/template.nuspec" ) ;
366+ //nuspecText = nuspecText.Replace ("$xbdversion$", XBD_VERSION);
367+ var nuspecFile = new FilePath ( art . ArtifactId + "/nuget/" + art . NugetId + ".nuspec" ) ;
368+ FileWriteText ( nuspecFile , nuspecText ) ;
369+ var xNuspec = System . Xml . Linq . XDocument . Load ( MakeAbsolute ( nuspecFile ) . FullPath ) ;
370+ System . Xml . Linq . XNamespace nsNuspec = xNuspec . Root . Name . Namespace ;
371+
372+ // Check if we have a proguard.txt file for this artifact and include it in the nuspec if so
373+ if ( FileExists ( proguardFile ) ) {
374+ Information ( "Adding {0} to {1}" , "proguard.txt" , nuspecFile ) ;
375+ var filesElems = xNuspec . Root . Descendants ( nsNuspec + "files" ) ;
376+
377+ if ( filesElems != null ) {
378+ var filesElem = filesElems . First ( ) ;
379+ filesElem . Add ( new System . Xml . Linq . XElement ( nsNuspec + "file" ,
380+ new System . Xml . Linq . XAttribute ( nsNuspec + "src" , proguardFile . ToString ( ) ) ,
381+ new System . Xml . Linq . XAttribute ( nsNuspec + "target" , "proguard/proguard.txt" ) ) ) ;
382+ }
383+ }
384+
385+ xNuspec . Save ( MakeAbsolute ( nuspecFile ) . FullPath ) ;
386+ }
387+ } ) ;
388+
389+ Task ( "nuget" ) . IsDependentOn ( "nuget-setup" ) . IsDependentOn ( "nuget-base" ) . IsDependentOn ( "libs" ) ;
390+
391+
303392Task ( "component" ) . IsDependentOn ( "component-docs" ) . IsDependentOn ( "component-setup" ) . IsDependentOn ( "component-base" ) . IsDependentOn ( "libs" ) ;
304393
305394Task ( "clean" ) . IsDependentOn ( "clean-base" ) . Does ( ( ) =>
0 commit comments