1212using Microsoft . Build . Framework ;
1313using Microsoft . Build . Utilities ;
1414using NuGet . Common ;
15- using NuGet . Frameworks ;
1615using NuGet . ProjectModel ;
1716using NuGet . Versioning ;
1817
@@ -161,6 +160,11 @@ public sealed class ResolvePackageAssets : TaskBase
161160 /// </summary>
162161 public bool DesignTimeBuild { get ; set ; }
163162
163+ /// <summary>
164+ /// Enable publishing XML documentation
165+ /// </summary>
166+ public bool PublishReferencesDocumentationFiles { get ; set ; }
167+
164168 /// <summary>
165169 /// Full paths to assemblies from packages to pass to compiler as analyzers.
166170 /// </summary>
@@ -235,14 +239,23 @@ public sealed class ResolvePackageAssets : TaskBase
235239 public ITaskItem [ ] PackageDependencies { get ; private set ; }
236240
237241 /// <summary>
238- /// List of file symbols pdb and xml related to NuGet packages
242+ /// List of symbol files (. pdb) related to NuGet packages.
239243 /// </summary>
240244 /// <remarks>
241- /// This is the list of files to be copied to the output directory
245+ /// Pdb files to be copied to the output directory
242246 /// </remarks>
243247 [ Output ]
244248 public ITaskItem [ ] DebugSymbolsFiles { get ; private set ; }
245249
250+ /// <summary>
251+ /// List of xml files related to NuGet packages.
252+ /// </summary>
253+ /// <remarks>
254+ /// The XML files should only be included in the publish output if PublishReferencesDocumentationFiles is true
255+ /// </remarks>
256+ [ Output ]
257+ public ITaskItem [ ] DebugXmlFiles { get ; private set ; }
258+
246259 /// <summary>
247260 /// Messages from the assets file.
248261 /// These are logged directly and therefore not returned to the targets (note private here).
@@ -324,6 +337,7 @@ private void ReadItemGroups()
324337 CompileTimeAssemblies = reader . ReadItemGroup ( ) ;
325338 ContentFilesToPreprocess = reader . ReadItemGroup ( ) ;
326339 DebugSymbolsFiles = reader . ReadItemGroup ( ) ;
340+ DebugXmlFiles = reader . ReadItemGroup ( ) ;
327341 FrameworkAssemblies = reader . ReadItemGroup ( ) ;
328342 FrameworkReferences = reader . ReadItemGroup ( ) ;
329343 NativeLibraries = reader . ReadItemGroup ( ) ;
@@ -456,6 +470,7 @@ internal byte[] HashSettings()
456470 }
457471 writer . Write ( TargetFramework ) ;
458472 writer . Write ( VerifyMatchingImplicitPackageVersion ) ;
473+ writer . Write ( PublishReferencesDocumentationFiles ) ;
459474 }
460475
461476 stream . Position = 0 ;
@@ -794,6 +809,7 @@ private void WriteItemGroups()
794809 WriteItemGroup ( WriteCompileTimeAssemblies ) ;
795810 WriteItemGroup ( WriteContentFilesToPreprocess ) ;
796811 WriteItemGroup ( WriteDebugSymbolsFiles ) ;
812+ WriteItemGroup ( WriteDebugXmlFiles ) ;
797813 WriteItemGroup ( WriteFrameworkAssemblies ) ;
798814 WriteItemGroup ( WriteFrameworkReferences ) ;
799815 WriteItemGroup ( WriteNativeLibraries ) ;
@@ -1111,14 +1127,34 @@ private void WriteContentFilesToPreprocess()
11111127
11121128 private void WriteDebugSymbolsFiles ( )
11131129 {
1114- foreach ( LockFileTargetLibrary library in _runtimeTarget . Libraries )
1130+ WriteDebugItems (
1131+ p => p . RuntimeAssemblies ,
1132+ MetadataKeys . PdbExtension ) ;
1133+ }
1134+
1135+ private void WriteDebugXmlFiles ( )
1136+ {
1137+ if ( _task . PublishReferencesDocumentationFiles )
1138+ {
1139+ WriteDebugItems (
1140+ p => p . CompileTimeAssemblies ,
1141+ MetadataKeys . XmlExtension ) ;
1142+ }
1143+ }
1144+
1145+ private void WriteDebugItems < T > (
1146+ Func < LockFileTargetLibrary , IEnumerable < T > > getAssets ,
1147+ string extension )
1148+ where T : LockFileItem
1149+ {
1150+ foreach ( var library in _runtimeTarget . Libraries )
11151151 {
11161152 if ( ! library . IsPackage ( ) )
11171153 {
11181154 continue ;
11191155 }
11201156
1121- foreach ( var asset in library . RuntimeAssemblies )
1157+ foreach ( T asset in getAssets ( library ) )
11221158 {
11231159 if ( asset . IsPlaceholderFile ( ) || ! asset . Properties . ContainsKey ( MetadataKeys . RelatedProperty ) )
11241160 {
@@ -1131,14 +1167,9 @@ private void WriteDebugSymbolsFiles()
11311167
11321168 foreach ( string fileExtension in relatedExtensions . Split ( RelatedPropertySeparator ) )
11331169 {
1134- switch ( fileExtension . ToLower ( ) )
1170+ if ( fileExtension . ToLower ( ) == extension )
11351171 {
1136- case MetadataKeys . PdbExtension :
1137- WriteItem ( Path . ChangeExtension ( itemSpec , MetadataKeys . PdbExtension ) , library ) ;
1138- break ;
1139- case MetadataKeys . XmlExtension :
1140- WriteItem ( Path . ChangeExtension ( itemSpec , MetadataKeys . XmlExtension ) , library ) ;
1141- break ;
1172+ WriteItem ( Path . ChangeExtension ( itemSpec , extension ) , library ) ;
11421173 }
11431174 }
11441175 }
0 commit comments