Skip to content

Commit 3e7c5cc

Browse files
author
Livar
authored
Merge pull request #1062 from dasMulli/feature/publish-documentation
Enable publishing XML documentation
2 parents 16f318c + 56d9419 commit 3e7c5cc

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ Copyright (c) .NET Foundation. All rights reserved.
210210
<ResolvedFileToPublish Include="@(ResolvedAssembliesToPublish)">
211211
<RelativePath>%(ResolvedAssembliesToPublish.DestinationSubPath)</RelativePath>
212212
</ResolvedFileToPublish>
213+
214+
<!-- Copy the xml documentation (if enabled) -->
215+
<ResolvedFileToPublish Include="@(FinalDocFile)"
216+
Condition="'$(PublishDocumentationFile)' == 'true'">
217+
<RelativePath>@(FinalDocFile->'%(Filename)%(Extension)')</RelativePath>
218+
</ResolvedFileToPublish>
213219
</ItemGroup>
214220

215221
</Target>
@@ -220,7 +226,9 @@ Copyright (c) .NET Foundation. All rights reserved.
220226
<!-- TODO perform any preprocess transforms on the files -->
221227

222228
<ItemGroup>
223-
<ResolvedAssembliesToPublish Include="@(ReferenceCopyLocalPaths)" Exclude="@(ResolvedAssembliesToPublish)">
229+
<ResolvedAssembliesToPublish Include="@(ReferenceCopyLocalPaths)"
230+
Exclude="@(ResolvedAssembliesToPublish)"
231+
Condition="'$(PublishReferencesDocumentationFiles)' == 'true' or '%(Extension)' != '.xml'">
224232
<DestinationSubPath>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(Filename)%(Extension)</DestinationSubPath>
225233
</ResolvedAssembliesToPublish>
226234
</ItemGroup>

src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ Copyright (c) .NET Foundation. All rights reserved.
137137
<DocumentationFile />
138138
</PropertyGroup>
139139

140+
<PropertyGroup>
141+
<PublishDocumentationFiles Condition="'$(PublishDocumentationFiles)' == ''">true</PublishDocumentationFiles>
142+
<PublishDocumentationFile Condition="'$(PublishDocumentationFile)' == '' and '$(PublishDocumentationFiles)' == 'true'">true</PublishDocumentationFile>
143+
<PublishReferencesDocumentationFiles Condition="'$(PublishReferencesDocumentationFiles)' == '' and '$(PublishDocumentationFiles)' == 'true'">true</PublishReferencesDocumentationFiles>
144+
</PropertyGroup>
145+
140146
<!-- Add a project capability so that the project properties in the IDE can show the option to generate an XML documentation file without specifying the filename -->
141147
<ItemGroup>
142148
<ProjectCapability Include="GenerateDocumentationFile" />

test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using System.Runtime.InteropServices;
1414
using Newtonsoft.Json;
1515
using Newtonsoft.Json.Linq;
16+
using System.Collections.Generic;
17+
using Microsoft.NET.TestFramework.ProjectConstruction;
1618

1719
namespace Microsoft.NET.Publish.Tests
1820
{
@@ -189,6 +191,98 @@ public void It_publishes_projects_with_filter_and_rid()
189191

190192
//TODO: Enable testing the run once dotnet host has the notion of looking up shared packages
191193
}
194+
195+
196+
[Theory]
197+
[InlineData("GenerateDocumentationFile=true", true, true)]
198+
[InlineData("GenerateDocumentationFile=true;PublishDocumentationFile=false", false, true)]
199+
[InlineData("GenerateDocumentationFile=true;PublishReferencesDocumentationFiles=false", true, false)]
200+
[InlineData("GenerateDocumentationFile=true;PublishDocumentationFiles=false", false, false)]
201+
public void It_publishes_documentation_files(string properties, bool expectAppDocPublished, bool expectLibProjectDocPublished)
202+
{
203+
var kitchenSinkAsset = _testAssetsManager
204+
.CopyTestAsset("KitchenSink", identifier: $"{expectAppDocPublished}_{expectLibProjectDocPublished}")
205+
.WithSource();
206+
kitchenSinkAsset.Restore("TestApp");
207+
208+
var publishCommand = new PublishCommand(Stage0MSBuild, Path.Combine(kitchenSinkAsset.TestRoot, "TestApp"));
209+
var publishResult = publishCommand.Execute("/p:" + properties);
210+
211+
publishResult.Should().Pass();
212+
213+
var publishDirectory = publishCommand.GetOutputDirectory();
214+
215+
if (expectAppDocPublished)
216+
{
217+
publishDirectory.Should().HaveFile("TestApp.xml");
218+
}
219+
else
220+
{
221+
publishDirectory.Should().NotHaveFile("TestApp.xml");
222+
}
223+
224+
if (expectLibProjectDocPublished)
225+
{
226+
publishDirectory.Should().HaveFile("TestLibrary.xml");
227+
}
228+
else
229+
{
230+
publishDirectory.Should().NotHaveFile("TestLibrary.xml");
231+
}
232+
}
233+
234+
[Theory]
235+
[InlineData("PublishReferencesDocumentationFiles=false", false)]
236+
[InlineData("PublishReferencesDocumentationFiles=true", true)]
237+
public void It_publishes_referenced_assembly_documentation(string property, bool expectAssemblyDocumentationFilePublished)
238+
{
239+
var identifier = property.Replace("=", "");
240+
241+
var libProject = new TestProject
242+
{
243+
Name = "NetStdLib",
244+
IsSdkProject = true,
245+
TargetFrameworks = "netstandard1.0"
246+
};
247+
248+
var libAsset = _testAssetsManager.CreateTestProject(libProject, identifier: identifier)
249+
.Restore("NetStdLib");
250+
251+
var libPublishCommand = new PublishCommand(Stage0MSBuild, Path.Combine(libAsset.TestRoot, "NetStdLib"));
252+
var libPublishResult = libPublishCommand.Execute("/t:Publish", "/p:GenerateDocumentationFile=true");
253+
libPublishResult.Should().Pass();
254+
var publishedLibPath = Path.Combine(libPublishCommand.GetOutputDirectory("netstandard1.0").FullName, "NetStdLib.dll");
255+
256+
var appProject = new TestProject
257+
{
258+
Name = "TestApp",
259+
IsSdkProject = true,
260+
IsExe = true,
261+
TargetFrameworks = "netcoreapp2.0",
262+
RuntimeFrameworkVersion = RepoInfo.NetCoreApp20Version,
263+
References = { publishedLibPath }
264+
};
265+
266+
var appAsset = _testAssetsManager.CreateTestProject(appProject, identifier: identifier);
267+
var appSourcePath = Path.Combine(appAsset.TestRoot, "TestApp");
268+
269+
new RestoreCommand(Stage0MSBuild, appSourcePath).Execute().Should().Pass();
270+
var appPublishCommand = new PublishCommand(Stage0MSBuild, appSourcePath);
271+
var appPublishResult = appPublishCommand.Execute("/p:" + property);
272+
appPublishResult.Should().Pass();
273+
274+
var appPublishDirectory = appPublishCommand.GetOutputDirectory("netcoreapp2.0");
275+
276+
if (expectAssemblyDocumentationFilePublished)
277+
{
278+
appPublishDirectory.Should().HaveFile("NetStdLib.xml");
279+
}
280+
else
281+
{
282+
appPublishDirectory.Should().NotHaveFile("NetStdLib.xml");
283+
}
284+
}
285+
192286
private static JObject ReadJson(string path)
193287
{
194288
using (JsonTextReader jsonReader = new JsonTextReader(File.OpenText(path)))

0 commit comments

Comments
 (0)