diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets index de52d1ea2932..157dfd75c205 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets @@ -201,6 +201,12 @@ Copyright (c) .NET Foundation. All rights reserved. %(ResolvedAssembliesToPublish.DestinationSubPath) + + + + @(FinalDocFile->'%(Filename)%(Extension)') + @@ -211,7 +217,9 @@ Copyright (c) .NET Foundation. All rights reserved. - + %(ReferenceCopyLocalPaths.DestinationSubDirectory)%(Filename)%(Extension) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets index a670e00b9c09..d5b80ee95220 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets @@ -137,6 +137,12 @@ Copyright (c) .NET Foundation. All rights reserved. + + true + true + true + + diff --git a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs index 7ab9289aa0a1..cf694165e133 100644 --- a/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs +++ b/test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAProjectWithDependencies.cs @@ -13,6 +13,8 @@ using System.Runtime.InteropServices; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using System.Collections.Generic; +using Microsoft.NET.TestFramework.ProjectConstruction; namespace Microsoft.NET.Publish.Tests { @@ -195,6 +197,98 @@ public void It_publishes_projects_with_filter_and_rid() //TODO: Enable testing the run once dotnet host has the notion of looking up shared packages } + + + [Theory] + [InlineData("GenerateDocumentationFile=true", true, true)] + [InlineData("GenerateDocumentationFile=true;PublishDocumentationFile=false", false, true)] + [InlineData("GenerateDocumentationFile=true;PublishReferencesDocumentationFiles=false", true, false)] + [InlineData("GenerateDocumentationFile=true;PublishDocumentationFiles=false", false, false)] + public void It_publishes_documentation_files(string properties, bool expectAppDocPublished, bool expectLibProjectDocPublished) + { + var kitchenSinkAsset = _testAssetsManager + .CopyTestAsset("KitchenSink", identifier: $"{expectAppDocPublished}_{expectLibProjectDocPublished}") + .WithSource(); + kitchenSinkAsset.Restore("TestApp"); + + var publishCommand = new PublishCommand(Stage0MSBuild, Path.Combine(kitchenSinkAsset.TestRoot, "TestApp")); + var publishResult = publishCommand.Execute("/p:" + properties); + + publishResult.Should().Pass(); + + var publishDirectory = publishCommand.GetOutputDirectory(); + + if (expectAppDocPublished) + { + publishDirectory.Should().HaveFile("TestApp.xml"); + } + else + { + publishDirectory.Should().NotHaveFile("TestApp.xml"); + } + + if (expectLibProjectDocPublished) + { + publishDirectory.Should().HaveFile("TestLibrary.xml"); + } + else + { + publishDirectory.Should().NotHaveFile("TestLibrary.xml"); + } + } + + [Theory] + [InlineData("PublishReferencesDocumentationFiles=false", false)] + [InlineData("PublishReferencesDocumentationFiles=true", true)] + public void It_publishes_referenced_assembly_documentation(string property, bool expectAssemblyDocumentationFilePublished) + { + var identifier = property.Replace("=", ""); + + var libProject = new TestProject + { + Name = "NetStdLib", + IsSdkProject = true, + TargetFrameworks = "netstandard1.0" + }; + + var libAsset = _testAssetsManager.CreateTestProject(libProject, identifier: identifier) + .Restore("NetStdLib"); + + var libPublishCommand = new PublishCommand(Stage0MSBuild, Path.Combine(libAsset.TestRoot, "NetStdLib")); + var libPublishResult = libPublishCommand.Execute("/t:Publish", "/p:GenerateDocumentationFile=true"); + libPublishResult.Should().Pass(); + var publishedLibPath = Path.Combine(libPublishCommand.GetOutputDirectory("netstandard1.0").FullName, "NetStdLib.dll"); + + var appProject = new TestProject + { + Name = "TestApp", + IsSdkProject = true, + IsExe = true, + TargetFrameworks = "netcoreapp2.0", + RuntimeFrameworkVersion = RepoInfo.NetCoreApp20Version, + References = { publishedLibPath } + }; + + var appAsset = _testAssetsManager.CreateTestProject(appProject, identifier: identifier); + var appSourcePath = Path.Combine(appAsset.TestRoot, "TestApp"); + + new RestoreCommand(Stage0MSBuild, appSourcePath).Execute().Should().Pass(); + var appPublishCommand = new PublishCommand(Stage0MSBuild, appSourcePath); + var appPublishResult = appPublishCommand.Execute("/p:" + property); + appPublishResult.Should().Pass(); + + var appPublishDirectory = appPublishCommand.GetOutputDirectory("netcoreapp2.0"); + + if (expectAssemblyDocumentationFilePublished) + { + appPublishDirectory.Should().HaveFile("NetStdLib.xml"); + } + else + { + appPublishDirectory.Should().NotHaveFile("NetStdLib.xml"); + } + } + private static JObject ReadJson(string path) { using (JsonTextReader jsonReader = new JsonTextReader(File.OpenText(path)))