|
19 | 19 | using Xunit.Abstractions; |
20 | 20 | using System.Text.RegularExpressions; |
21 | 21 | using System.Collections.Generic; |
| 22 | +using System.Security.Cryptography; |
| 23 | +using System.Reflection.Metadata; |
22 | 24 |
|
23 | 25 | namespace Microsoft.NET.Build.Tests |
24 | 26 | { |
@@ -530,7 +532,7 @@ void Test_inbox_assembly_wins_conflict_resolution(bool useSdkProject, string htt |
530 | 532 |
|
531 | 533 | testProject.PackageReferences.Add(new TestPackageReference("System.Net.Http", httpPackageVersion)); |
532 | 534 |
|
533 | | - testProject.SourceFiles["Program.cs"] = |
| 535 | + testProject.SourceFiles["Program.cs"] = |
534 | 536 | (useAlias ? "extern alias snh;" + Environment.NewLine : "") + |
535 | 537 |
|
536 | 538 | @"using System; |
@@ -850,5 +852,153 @@ public void It_allows_TargetFrameworkVersion_to_be_capitalized() |
850 | 852 | .Should() |
851 | 853 | .Pass(); |
852 | 854 | } |
| 855 | + |
| 856 | + [WindowsOnlyTheory] |
| 857 | + [InlineData("true", "true")] |
| 858 | + [InlineData("true", "false")] |
| 859 | + [InlineData("false", "true")] |
| 860 | + [InlineData("false", "false")] |
| 861 | + public void It_places_package_pdb_and_xml_files_in_output_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages) |
| 862 | + { |
| 863 | + var testProject = new TestProject() |
| 864 | + { |
| 865 | + Name = "DesktopUsingPackageWithPdbAndXml", |
| 866 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 867 | + IsExe = true, |
| 868 | + }; |
| 869 | + |
| 870 | + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1")); |
| 871 | + |
| 872 | + testProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages); |
| 873 | + testProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages); |
| 874 | + |
| 875 | + TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name); |
| 876 | + |
| 877 | + var buildCommand = new BuildCommand(testAsset); |
| 878 | + |
| 879 | + buildCommand |
| 880 | + .Execute() |
| 881 | + .Should() |
| 882 | + .Pass(); |
| 883 | + |
| 884 | + var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks); |
| 885 | + |
| 886 | + HelperCheckPdbAndDocumentation(outputDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages); |
| 887 | + } |
| 888 | + |
| 889 | + [WindowsOnlyTheory] |
| 890 | + [InlineData("true", "true")] |
| 891 | + [InlineData("true", "false")] |
| 892 | + [InlineData("false", "true")] |
| 893 | + [InlineData("false", "false")] |
| 894 | + public void It_places_package_pdb_and_xml_files_from_project_references_in_output_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages) |
| 895 | + { |
| 896 | + var libraryProject = new TestProject() |
| 897 | + { |
| 898 | + Name = "ProjectWithPackage", |
| 899 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 900 | + IsExe = false, |
| 901 | + }; |
| 902 | + |
| 903 | + libraryProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1")); |
| 904 | + |
| 905 | + var consumerProject = new TestProject() |
| 906 | + { |
| 907 | + Name = "ConsumerProject", |
| 908 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 909 | + IsExe = true, |
| 910 | + }; |
| 911 | + |
| 912 | + consumerProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages); |
| 913 | + consumerProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages); |
| 914 | + |
| 915 | + consumerProject.ReferencedProjects.Add(libraryProject); |
| 916 | + |
| 917 | + TestAsset testAsset = _testAssetsManager.CreateTestProject(consumerProject, consumerProject.Name); |
| 918 | + |
| 919 | + var buildCommand = new BuildCommand(testAsset); |
| 920 | + |
| 921 | + buildCommand |
| 922 | + .Execute() |
| 923 | + .Should() |
| 924 | + .Pass(); |
| 925 | + |
| 926 | + var outputDirectory = buildCommand.GetOutputDirectory(libraryProject.TargetFrameworks); |
| 927 | + |
| 928 | + HelperCheckPdbAndDocumentation(outputDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages); |
| 929 | + } |
| 930 | + |
| 931 | + [WindowsOnlyTheory] |
| 932 | + [InlineData("true", "true")] |
| 933 | + [InlineData("true", "false")] |
| 934 | + [InlineData("false", "true")] |
| 935 | + [InlineData("false", "false")] |
| 936 | + public void It_places_package_pdb_and_xml_files_in_publish_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages) |
| 937 | + { |
| 938 | + var testProject = new TestProject() |
| 939 | + { |
| 940 | + Name = "DesktopPublishPackageWithPdbAndXml", |
| 941 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 942 | + IsExe = true, |
| 943 | + }; |
| 944 | + |
| 945 | + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1")); |
| 946 | + |
| 947 | + testProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages); |
| 948 | + testProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages); |
| 949 | + |
| 950 | + TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name); |
| 951 | + |
| 952 | + var buildCommand = new BuildCommand(testAsset); |
| 953 | + |
| 954 | + buildCommand |
| 955 | + .Execute() |
| 956 | + .Should() |
| 957 | + .Pass(); |
| 958 | + |
| 959 | + var publishCommand = new PublishCommand(testAsset); |
| 960 | + publishCommand |
| 961 | + .Execute() |
| 962 | + .Should() |
| 963 | + .Pass(); |
| 964 | + |
| 965 | + var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks); |
| 966 | + |
| 967 | + HelperCheckPdbAndDocumentation(publishDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages); |
| 968 | + } |
| 969 | + |
| 970 | + void HelperCheckPdbAndDocumentation( |
| 971 | + DirectoryInfo directoryInfo, |
| 972 | + string packageName, |
| 973 | + string enableCopyDebugSymbolFilesFromPackages, |
| 974 | + string enableDocumentationFilesFromPackages) |
| 975 | + { |
| 976 | + string assemblyFile = packageName + ".dll"; |
| 977 | + string pdbFile = packageName + ".pdb"; |
| 978 | + string docFile = packageName + ".xml"; |
| 979 | + |
| 980 | + ShouldHave(assemblyFile); |
| 981 | + if (enableCopyDebugSymbolFilesFromPackages == "true") |
| 982 | + { |
| 983 | + ShouldHave(pdbFile); |
| 984 | + } |
| 985 | + else |
| 986 | + { |
| 987 | + ShouldNotHave(pdbFile); |
| 988 | + } |
| 989 | + |
| 990 | + if (enableDocumentationFilesFromPackages == "true") |
| 991 | + { |
| 992 | + ShouldHave(docFile); |
| 993 | + } |
| 994 | + else |
| 995 | + { |
| 996 | + ShouldNotHave(docFile); |
| 997 | + } |
| 998 | + |
| 999 | + void ShouldHave(string file) => directoryInfo.Should().HaveFile(file); |
| 1000 | + |
| 1001 | + void ShouldNotHave(string file) => directoryInfo.Should().NotHaveFile(file); |
| 1002 | + } |
853 | 1003 | } |
854 | 1004 | } |
0 commit comments