|
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,227 @@ public void It_allows_TargetFrameworkVersion_to_be_capitalized() |
850 | 852 | .Should() |
851 | 853 | .Pass(); |
852 | 854 | } |
| 855 | + |
| 856 | + [WindowsOnlyFact] |
| 857 | + public void It_places_package_xml_in_ref_folder_in_output_directory() |
| 858 | + { |
| 859 | + var testProject = new TestProject() |
| 860 | + { |
| 861 | + Name = "DesktopUsingPackageWithdXmlInRefFolder", |
| 862 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 863 | + IsExe = true, |
| 864 | + }; |
| 865 | + |
| 866 | + // This package contains an xml in ref, but not in lib. |
| 867 | + testProject.PackageReferences.Add(new TestPackageReference("system.diagnostics.debug", "4.3.0")); |
| 868 | + |
| 869 | + testProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", "true"); |
| 870 | + testProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", "true"); |
| 871 | + |
| 872 | + TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name); |
| 873 | + |
| 874 | + var buildCommand = new BuildCommand(testAsset); |
| 875 | + |
| 876 | + buildCommand |
| 877 | + .Execute() |
| 878 | + .Should() |
| 879 | + .Pass(); |
| 880 | + |
| 881 | + var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks); |
| 882 | + |
| 883 | + // this xml is coming from ref folder |
| 884 | + outputDirectory.Should().HaveFile("System.Diagnostics.Debug.xml"); |
| 885 | + } |
| 886 | + |
| 887 | + [WindowsOnlyTheory] |
| 888 | + [InlineData("true", "true")] |
| 889 | + [InlineData("true", "false")] |
| 890 | + [InlineData("false", "true")] |
| 891 | + [InlineData("false", "false")] |
| 892 | + public void It_places_package_pdb_and_xml_files_in_output_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages) |
| 893 | + { |
| 894 | + var testProject = new TestProject() |
| 895 | + { |
| 896 | + Name = "DesktopUsingPackageWithPdbAndXml", |
| 897 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 898 | + IsExe = true, |
| 899 | + }; |
| 900 | + |
| 901 | + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1")); |
| 902 | + |
| 903 | + testProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages); |
| 904 | + testProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages); |
| 905 | + |
| 906 | + string testPath = enableCopyDebugSymbolFilesFromPackages + enableDocumentationFilesFromPackages; |
| 907 | + TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name, identifier: testPath); |
| 908 | + |
| 909 | + var buildCommand = new BuildCommand(testAsset); |
| 910 | + |
| 911 | + buildCommand |
| 912 | + .Execute() |
| 913 | + .Should() |
| 914 | + .Pass(); |
| 915 | + |
| 916 | + var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks); |
| 917 | + |
| 918 | + HelperCheckPdbAndDocumentation(outputDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages); |
| 919 | + } |
| 920 | + |
| 921 | + [WindowsOnlyTheory] |
| 922 | + [InlineData("true", "true")] |
| 923 | + [InlineData("true", "false")] |
| 924 | + [InlineData("false", "true")] |
| 925 | + [InlineData("false", "false")] |
| 926 | + public void It_places_package_pdb_and_xml_files_from_project_references_in_output_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages) |
| 927 | + { |
| 928 | + var libraryProject = new TestProject() |
| 929 | + { |
| 930 | + Name = "ProjectWithPackage", |
| 931 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 932 | + IsExe = false, |
| 933 | + }; |
| 934 | + |
| 935 | + libraryProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1")); |
| 936 | + |
| 937 | + var consumerProject = new TestProject() |
| 938 | + { |
| 939 | + Name = "ConsumerProject", |
| 940 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 941 | + IsExe = true, |
| 942 | + }; |
| 943 | + |
| 944 | + consumerProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages); |
| 945 | + consumerProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages); |
| 946 | + |
| 947 | + consumerProject.ReferencedProjects.Add(libraryProject); |
| 948 | + |
| 949 | + string testPath = enableCopyDebugSymbolFilesFromPackages + enableDocumentationFilesFromPackages; |
| 950 | + TestAsset testAsset = _testAssetsManager.CreateTestProject(consumerProject, consumerProject.Name, identifier: testPath); |
| 951 | + |
| 952 | + var buildCommand = new BuildCommand(testAsset); |
| 953 | + |
| 954 | + buildCommand |
| 955 | + .Execute() |
| 956 | + .Should() |
| 957 | + .Pass(); |
| 958 | + |
| 959 | + var outputDirectory = buildCommand.GetOutputDirectory(libraryProject.TargetFrameworks); |
| 960 | + |
| 961 | + HelperCheckPdbAndDocumentation(outputDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages); |
| 962 | + } |
| 963 | + |
| 964 | + [WindowsOnlyTheory] |
| 965 | + [InlineData("true", "true")] |
| 966 | + [InlineData("true", "false")] |
| 967 | + [InlineData("false", "true")] |
| 968 | + [InlineData("false", "false")] |
| 969 | + public void It_places_package_pdb_and_xml_files_in_publish_directory(string enableCopyDebugSymbolFilesFromPackages, string enableDocumentationFilesFromPackages) |
| 970 | + { |
| 971 | + var testProject = new TestProject() |
| 972 | + { |
| 973 | + Name = "DesktopPublishPackageWithPdbAndXml", |
| 974 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 975 | + IsExe = true, |
| 976 | + }; |
| 977 | + |
| 978 | + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1")); |
| 979 | + |
| 980 | + testProject.AdditionalProperties.Add("CopyDebugSymbolFilesFromPackages", enableCopyDebugSymbolFilesFromPackages); |
| 981 | + testProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", enableDocumentationFilesFromPackages); |
| 982 | + |
| 983 | + string testPath = enableCopyDebugSymbolFilesFromPackages + enableDocumentationFilesFromPackages; |
| 984 | + TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name, identifier: testPath); |
| 985 | + |
| 986 | + var buildCommand = new BuildCommand(testAsset); |
| 987 | + |
| 988 | + buildCommand |
| 989 | + .Execute() |
| 990 | + .Should() |
| 991 | + .Pass(); |
| 992 | + |
| 993 | + var publishCommand = new PublishCommand(testAsset); |
| 994 | + |
| 995 | + publishCommand |
| 996 | + .Execute() |
| 997 | + .Should() |
| 998 | + .Pass(); |
| 999 | + |
| 1000 | + var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks); |
| 1001 | + |
| 1002 | + HelperCheckPdbAndDocumentation(publishDirectory, "Microsoft.Build", enableCopyDebugSymbolFilesFromPackages, enableDocumentationFilesFromPackages); |
| 1003 | + } |
| 1004 | + |
| 1005 | + [WindowsOnlyFact] |
| 1006 | + public void It_places_package_xml_files_in_output_directory_but_not_in_publish() |
| 1007 | + { |
| 1008 | + var testProject = new TestProject() |
| 1009 | + { |
| 1010 | + Name = "DesktopPackageWithXmlNotPublished", |
| 1011 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 1012 | + IsExe = true, |
| 1013 | + }; |
| 1014 | + |
| 1015 | + testProject.PackageReferences.Add(new TestPackageReference("Microsoft.Build", "17.3.1")); |
| 1016 | + |
| 1017 | + testProject.AdditionalProperties.Add("PublishReferencesDocumentationFiles", "false"); |
| 1018 | + testProject.AdditionalProperties.Add("CopyDocumentationFilesFromPackages", "true"); |
| 1019 | + |
| 1020 | + TestAsset testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name); |
| 1021 | + |
| 1022 | + var buildCommand = new BuildCommand(testAsset); |
| 1023 | + |
| 1024 | + buildCommand |
| 1025 | + .Execute() |
| 1026 | + .Should() |
| 1027 | + .Pass(); |
| 1028 | + |
| 1029 | + var publishCommand = new PublishCommand(testAsset); |
| 1030 | + |
| 1031 | + publishCommand |
| 1032 | + .Execute() |
| 1033 | + .Should() |
| 1034 | + .Pass(); |
| 1035 | + |
| 1036 | + var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks); |
| 1037 | + |
| 1038 | + var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks); |
| 1039 | + |
| 1040 | + outputDirectory.Should().HaveFile("Microsoft.Build.xml"); |
| 1041 | + publishDirectory.Should().NotHaveFile("Microsoft.Build.xml"); |
| 1042 | + } |
| 1043 | + |
| 1044 | + void HelperCheckPdbAndDocumentation( |
| 1045 | + DirectoryInfo directoryInfo, |
| 1046 | + string packageName, |
| 1047 | + string enableCopyDebugSymbolFilesFromPackages, |
| 1048 | + string enableDocumentationFilesFromPackages) |
| 1049 | + { |
| 1050 | + string assemblyFile = packageName + ".dll"; |
| 1051 | + string pdbFile = packageName + ".pdb"; |
| 1052 | + string docFile = packageName + ".xml"; |
| 1053 | + |
| 1054 | + ShouldHave(assemblyFile); |
| 1055 | + if (enableCopyDebugSymbolFilesFromPackages == "true") |
| 1056 | + { |
| 1057 | + ShouldHave(pdbFile); |
| 1058 | + } |
| 1059 | + else |
| 1060 | + { |
| 1061 | + ShouldNotHave(pdbFile); |
| 1062 | + } |
| 1063 | + |
| 1064 | + if (enableDocumentationFilesFromPackages == "true") |
| 1065 | + { |
| 1066 | + ShouldHave(docFile); |
| 1067 | + } |
| 1068 | + else |
| 1069 | + { |
| 1070 | + ShouldNotHave(docFile); |
| 1071 | + } |
| 1072 | + |
| 1073 | + void ShouldHave(string file) => directoryInfo.Should().HaveFile(file); |
| 1074 | + |
| 1075 | + void ShouldNotHave(string file) => directoryInfo.Should().NotHaveFile(file); |
| 1076 | + } |
853 | 1077 | } |
854 | 1078 | } |
0 commit comments