diff --git a/TestPlatform.sln b/TestPlatform.sln index 26a8b21bb6..4150d781ae 100644 --- a/TestPlatform.sln +++ b/TestPlatform.sln @@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "datacollector", "src\dataco EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.Build", "src\Microsoft.TestPlatform.Build\Microsoft.TestPlatform.Build.csproj", "{6F5EC38C-4A11-40D3-827C-F607B90BEFF0}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Logger", "Logger", "{5E7F18A8-F843-4C8A-AB02-4C7D9205C6CF}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Loggers", "Loggers", "{5E7F18A8-F843-4C8A-AB02-4C7D9205C6CF}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.Client", "src\Microsoft.TestPlatform.Client\Microsoft.TestPlatform.Client.csproj", "{E19B5128-3469-492E-82E1-725631C4A68C}" EndProject @@ -41,10 +41,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vstest.console", "src\vstes EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration", "Integration", "{46250E12-4CF1-4051-B4A7-80C8C06E0068}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Logger", "Logger", "{020E15EA-731F-4667-95AF-226671E0C3AE}" - ProjectSection(SolutionItems) = preProject - test\Microsoft.TestPlatform.AcceptanceTests\TestResults.html = test\Microsoft.TestPlatform.AcceptanceTests\TestResults.html - EndProjectSection +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Loggers", "Loggers", "{020E15EA-731F-4667-95AF-226671E0C3AE}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Performance", "Performance", "{595BE9C1-E10F-4E50-938A-E6C248D3F950}" EndProject @@ -800,17 +797,17 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {50C00046-0DA3-4B5C-9F6F-7BE1145E156A} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} - {01409D95-A5F1-4EBE-94B1-909D5D2D0DC3} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} + {50C00046-0DA3-4B5C-9F6F-7BE1145E156A} = {7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3} + {01409D95-A5F1-4EBE-94B1-909D5D2D0DC3} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999} {2C7CE1F8-E73E-4987-8023-B5A0EBAC86E8} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} {6F5EC38C-4A11-40D3-827C-F607B90BEFF0} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} {5E7F18A8-F843-4C8A-AB02-4C7D9205C6CF} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} {E19B5128-3469-492E-82E1-725631C4A68C} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} - {68ADC720-316E-4895-9F8E-C3CCADD262BE} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} - {1621415E-7723-4F46-A589-4C4620C0751A} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} - {987898D9-724E-4324-BF91-77B1A6DBE8F1} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} - {FD63F778-3938-45D2-900B-51EC770F70E5} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} - {61F7F446-9EF3-4768-B33A-4D75F60E1059} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} + {68ADC720-316E-4895-9F8E-C3CCADD262BE} = {7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3} + {1621415E-7723-4F46-A589-4C4620C0751A} = {7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3} + {987898D9-724E-4324-BF91-77B1A6DBE8F1} = {7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3} + {FD63F778-3938-45D2-900B-51EC770F70E5} = {7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3} + {61F7F446-9EF3-4768-B33A-4D75F60E1059} = {7D4082EA-7AC9-4DFB-98E8-C5E08BDC0EC3} {D5296435-3A3F-4B1A-81D1-434EC9E97DEF} = {5E7F18A8-F843-4C8A-AB02-4C7D9205C6CF} {790B8030-00C2-4121-B125-EDC4CE329BA3} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} {27DFBD04-64B2-4F1B-82B2-006620CCA6F8} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} @@ -820,12 +817,12 @@ Global {020E15EA-731F-4667-95AF-226671E0C3AE} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {595BE9C1-E10F-4E50-938A-E6C248D3F950} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {0D59BA81-6279-4650-AEBB-4EA735C28A1A} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} - {DE730F17-7D5C-4D9D-B479-025024BF4F1D} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} - {E062FFD6-DEB1-4DB4-8B6E-ADBF04129545} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} - {F582949D-8B92-47BD-9DD7-9F2BFCCC290C} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} - {376A7588-50DF-46CD-955B-0309F491D830} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} + {DE730F17-7D5C-4D9D-B479-025024BF4F1D} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999} + {E062FFD6-DEB1-4DB4-8B6E-ADBF04129545} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999} + {F582949D-8B92-47BD-9DD7-9F2BFCCC290C} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999} + {376A7588-50DF-46CD-955B-0309F491D830} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999} {5DF3CF65-3E11-4639-964D-7BEB4109DCF9} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} - {D3E8A13B-92EE-45A8-BB24-40EC3CC9DB34} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} + {D3E8A13B-92EE-45A8-BB24-40EC3CC9DB34} = {376C19DE-31E2-4FF6-88FC-0D0D6233C999} {9EFCEFB5-253E-4DE2-8A70-821D7B8189DF} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {3A8080FB-9C93-45B9-8EB5-828DDC31FDF0} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {BFF7714C-E5A3-4EEB-B04B-5FA47F29AD03} = {020E15EA-731F-4667-95AF-226671E0C3AE} @@ -847,7 +844,7 @@ Global {7B48115A-B766-4B55-93A8-C08A42C37710} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {FBF74C8F-695C-4967-84AC-358EEFB1376D} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {11ECCB8B-6958-42A7-BD58-88C09CB149B2} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} - {76D4BB7E-D981-42D5-BE96-6FAD8DEF9A4A} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} + {76D4BB7E-D981-42D5-BE96-6FAD8DEF9A4A} = {B705537C-B82C-4A30-AFA5-6244D9A7DAEB} {488675EC-C8BB-40E0-AD4F-91F623D548B3} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {B705537C-B82C-4A30-AFA5-6244D9A7DAEB} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} {65A25D6E-C9CC-4F45-8925-04087AC82634} = {B705537C-B82C-4A30-AFA5-6244D9A7DAEB} @@ -862,7 +859,7 @@ Global {E7D4921C-F12D-4E1C-85AC-8B7F91C59B0E} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {236A71E3-01DA-4679-9DFF-16A8E079ACFF} = {5E7F18A8-F843-4C8A-AB02-4C7D9205C6CF} {41248B96-6E15-4E5E-A78F-859897676814} = {020E15EA-731F-4667-95AF-226671E0C3AE} - {074F5BD6-DC05-460B-B78F-044D125FD787} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} + {074F5BD6-DC05-460B-B78F-044D125FD787} = {D9A30E32-D466-4EC5-B4F2-62E17562279B} {DCD0C39E-C78C-4A44-B0BD-7325254A2E97} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Microsoft.TestPlatform.Extensions.EventLogCollector.csproj b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Microsoft.TestPlatform.Extensions.EventLogCollector.csproj index a86a2ef4b3..61c74ab8c2 100644 --- a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Microsoft.TestPlatform.Extensions.EventLogCollector.csproj +++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Microsoft.TestPlatform.Extensions.EventLogCollector.csproj @@ -29,9 +29,6 @@ - - - True diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Properties/AssemblyInfo.cs b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Properties/AssemblyInfo.cs index dd4512dc14..e0e2c84b82 100644 --- a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Properties/AssemblyInfo.cs +++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Properties/AssemblyInfo.cs @@ -14,7 +14,6 @@ [assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] [assembly: AssemblyProduct("Microsoft.TestPlatform.Extensions.EventLogCollector")] [assembly: AssemblyTrademark("")] -[assembly: TypesToLoad(typeof(EventLogDataCollector))] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Properties/TypesToLoadAttribute.cs b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Properties/TypesToLoadAttribute.cs new file mode 100644 index 0000000000..0869251ec9 --- /dev/null +++ b/src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/Properties/TypesToLoadAttribute.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.TestPlatform.Extensions.EventLogCollector; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + +[assembly: TypesToLoad(typeof(EventLogDataCollector))] + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities +{ + /// + /// Custom Attribute to specify the exact types which should be loaded from assembly + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + internal sealed class TypesToLoadAttribute : Attribute + { + public TypesToLoadAttribute(params Type[] types) + { + this.Types = types; + } + + public Type[] Types { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/TypesToLoadAttribute.cs b/src/DataCollectors/TraceDataCollector/Properties/TypesToLoadAttribute.cs similarity index 68% rename from src/Microsoft.TestPlatform.ObjectModel/Utilities/TypesToLoadAttribute.cs rename to src/DataCollectors/TraceDataCollector/Properties/TypesToLoadAttribute.cs index 5f8824b510..48cad540f0 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/TypesToLoadAttribute.cs +++ b/src/DataCollectors/TraceDataCollector/Properties/TypesToLoadAttribute.cs @@ -1,22 +1,25 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using Microsoft.VisualStudio.Coverage; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + +[assembly: TypesToLoad(typeof(DynamicCoverageDataCollector))] + namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities { - using System; - /// /// Custom Attribute to specify the exact types which should be loaded from assembly /// [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] - [CLSCompliant(false)] - public sealed class TypesToLoadAttribute : Attribute + internal sealed class TypesToLoadAttribute : Attribute { public TypesToLoadAttribute(params Type[] types) { - Types = types; + this.Types = types; } public Type[] Types { get; } } -} +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs index 3d845df33a..f08f565394 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs @@ -18,6 +18,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using CommonResources = Resources.Resources; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; /// /// Discovers test extensions in a directory. @@ -108,8 +109,6 @@ private void AddKnownExtensions(ref IEnumerable extensionPaths) /// /// Test plugins collection to add to. /// - [SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.Assembly.LoadFrom")] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We would like to continue discovering all plugins even if some dll in Extensions folder is not able to be load properly")] private void GetTestExtensionsFromFiles( string[] files, Dictionary pluginInfos) where TPluginInfo : TestPluginInformation @@ -167,13 +166,10 @@ private void GetTestExtensionsFromAssembly(Assembly ass Type extension = typeof(TExtension); try - { - var customAttribute = CustomAttributeExtensions.GetCustomAttribute(assembly, typeof(TypesToLoadAttribute)) as TypesToLoadAttribute; - if (customAttribute != null) - { - types = customAttribute.Types; - } - else + { + types = TypesToLoadUtilities.GetTypesToLoad(assembly); + + if (!types.Any()) { types = assembly.GetTypes().Where(type => type.GetTypeInfo().IsClass && !type.GetTypeInfo().IsAbstract); } diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs index ae780aa7a3..b322d75fd7 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginManager.cs @@ -5,7 +5,6 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework { using System; using System.Collections.Generic; - using System.Diagnostics; using System.Reflection; using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities; diff --git a/src/Microsoft.TestPlatform.Common/Friends.cs b/src/Microsoft.TestPlatform.Common/Friends.cs index e767fb98ad..fb645969e2 100644 --- a/src/Microsoft.TestPlatform.Common/Friends.cs +++ b/src/Microsoft.TestPlatform.Common/Friends.cs @@ -24,5 +24,5 @@ [assembly: InternalsVisibleTo("Microsoft.TestPlatform.Client.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("Microsoft.TestPlatform.TestUtilities, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] - +[assembly: InternalsVisibleTo("Microsoft.TestPlatform.AcceptanceTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] #endregion \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Utilities/TypesToLoadUtilities.cs b/src/Microsoft.TestPlatform.Common/Utilities/TypesToLoadUtilities.cs new file mode 100644 index 0000000000..fb25c588ff --- /dev/null +++ b/src/Microsoft.TestPlatform.Common/Utilities/TypesToLoadUtilities.cs @@ -0,0 +1,42 @@ +// Copyright(c) Microsoft Corporation.All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.Common.Utilities +{ + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + + using System; + using System.Collections.Generic; + using System.Reflection; + using System.Linq; + + internal static class TypesToLoadUtilities + { + public const string TypesToLoadAttributeFullName = "Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities.TypesToLoadAttribute"; + + internal static IEnumerable GetTypesToLoad(Assembly assembly) + { + ValidateArg.NotNull(assembly, nameof(assembly)); + + var typesToLoad = assembly + .GetCustomAttributes(TypesToLoadAttributeFullName) + .SelectMany(i => GetTypesToLoad(i)); + + return typesToLoad; + } + + private static IEnumerable GetTypesToLoad(Attribute attribute) + { + if (attribute == null) + return Enumerable.Empty(); + + var type = attribute.GetType(); + var typesProperty = type.GetProperty("Types"); + if(typesProperty == null) + return Enumerable.Empty(); + + return typesProperty.GetValue(attribute) as Type[]; + } + } +} diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Properties/AssemblyInfo.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Properties/AssemblyInfo.cs index 68809aec87..33717a5453 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Properties/AssemblyInfo.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Properties/AssemblyInfo.cs @@ -3,8 +3,6 @@ using System.Reflection; using System.Runtime.InteropServices; -using Microsoft.TestPlatform.Extensions.BlameDataCollector; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -14,7 +12,6 @@ [assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] [assembly: AssemblyProduct("Microsoft.TestPlatform.Extensions.BlameDataCollector")] [assembly: AssemblyTrademark("")] -[assembly: TypesToLoad(typeof(BlameLogger), typeof(BlameCollector))] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Properties/TypesToLoadAttribute.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Properties/TypesToLoadAttribute.cs new file mode 100644 index 0000000000..850d091188 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Properties/TypesToLoadAttribute.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +using Microsoft.TestPlatform.Extensions.BlameDataCollector; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + +[assembly: TypesToLoad(typeof(BlameLogger), typeof(BlameCollector))] + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities +{ + /// + /// Custom Attribute to specify the exact types which should be loaded from assembly + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + internal sealed class TypesToLoadAttribute : Attribute + { + public TypesToLoadAttribute(params Type[] types) + { + this.Types = types; + } + + public Type[] Types { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Properties/AssemblyInfo.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Properties/AssemblyInfo.cs index bc64c4ba85..4010518fda 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Properties/AssemblyInfo.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Properties/AssemblyInfo.cs @@ -3,8 +3,6 @@ using System.Reflection; using System.Runtime.InteropServices; -using Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -14,7 +12,6 @@ [assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] [assembly: AssemblyProduct("Microsoft.TestPlatform.Extensions.HtmlLogger")] [assembly: AssemblyTrademark("")] -[assembly: TypesToLoad(typeof(HtmlLogger))] // Setting ComVisible to false makes the types in this assembly not visible @@ -23,5 +20,4 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM. - [assembly: Guid("1f26e9c7-5018-4091-a22a-89280f2f98a9")] diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Properties/TypesToLoadAttribute.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Properties/TypesToLoadAttribute.cs new file mode 100644 index 0000000000..a80f7cc16d --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Properties/TypesToLoadAttribute.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + +[assembly: TypesToLoad(typeof(HtmlLogger))] + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities +{ + /// + /// Custom Attribute to specify the exact types which should be loaded from assembly + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + internal sealed class TypesToLoadAttribute : Attribute + { + public TypesToLoadAttribute(params Type[] types) + { + this.Types = types; + } + + public Type[] Types { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Properties/AssemblyInfo.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Properties/AssemblyInfo.cs index 57f3f4ab80..816dbd6b88 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Properties/AssemblyInfo.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Properties/AssemblyInfo.cs @@ -14,7 +14,6 @@ [assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] [assembly: AssemblyProduct("Microsoft.TestPlatform.Extensions.TrxLogger")] [assembly: AssemblyTrademark("")] -[assembly: TypesToLoad(typeof(TrxLogger))] // Setting ComVisible to false makes the types in this assembly not visible @@ -23,4 +22,4 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("60d876ee-f278-4bf8-bc8a-15b356895c6f")] +[assembly: Guid("60d876ee-f278-4bf8-bc8a-15b356895c6f")] \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Properties/TypesToLoadAttribute.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Properties/TypesToLoadAttribute.cs new file mode 100644 index 0000000000..e92219c4a8 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Properties/TypesToLoadAttribute.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + +[assembly: TypesToLoad(typeof(TrxLogger))] + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities +{ + /// + /// Custom Attribute to specify the exact types which should be loaded from assembly + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + internal sealed class TypesToLoadAttribute : Attribute + { + public TypesToLoadAttribute(params Type[] types) + { + this.Types = types; + } + + public Type[] Types { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyHelper.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyHelper.cs index 3c1616c217..48994399c1 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyHelper.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyHelper.cs @@ -3,20 +3,21 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities { -#if NETFRAMEWORK + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; + using System.Linq; using System.Reflection; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; - /// /// Implementation of finding assembly references using "managed route", i.e. Assembly.Load. /// public static class AssemblyHelper { +#if NETFRAMEWORK private static Version defaultVersion = new Version(); private static Version version45 = new Version("4.5"); @@ -25,7 +26,6 @@ public static class AssemblyHelper /// Only assembly name and public key token are match. Version is ignored for matching. /// Returns null if not able to check if source references assembly. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] public static bool? DoesReferencesAssembly(string source, AssemblyName referenceAssembly) { try @@ -160,7 +160,6 @@ public static KeyValuePair GetFrameworkVersionAn } } - /// /// Returns the full name (AssemblyName.FullName) of the referenced assemblies by the assembly on the specified path. /// @@ -340,6 +339,18 @@ internal static void SetNETFrameworkCompatiblityMode(AppDomainSetup setup, IRunC } } } - } #endif + + public static IEnumerable GetCustomAttributes(this Assembly assembly, string fullyQualifiedName) + { + ValidateArg.NotNull(assembly, nameof(assembly)); + ValidateArg.NotNullOrWhiteSpace(fullyQualifiedName, nameof(fullyQualifiedName)); + + var attributes = assembly + .GetCustomAttributes() + .Where(i => i.GetType().FullName == fullyQualifiedName); + + return attributes; + } + } } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Properties/AssemblyInfo.cs b/src/Microsoft.TestPlatform.TestHostProvider/Properties/AssemblyInfo.cs index cfcaf11468..892e0ae7e4 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Properties/AssemblyInfo.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Properties/AssemblyInfo.cs @@ -3,8 +3,6 @@ using System.Reflection; using System.Runtime.InteropServices; -using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -14,7 +12,6 @@ [assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] [assembly: AssemblyProduct("Microsoft.TestPlatform.TestHostRuntimeProvider")] [assembly: AssemblyTrademark("")] -[assembly: TypesToLoad(typeof(DefaultTestHostManager), typeof(DotnetTestHostManager))] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Properties/TypesToLoadAttribute.cs b/src/Microsoft.TestPlatform.TestHostProvider/Properties/TypesToLoadAttribute.cs new file mode 100644 index 0000000000..33805104af --- /dev/null +++ b/src/Microsoft.TestPlatform.TestHostProvider/Properties/TypesToLoadAttribute.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + +[assembly: TypesToLoad(typeof(DefaultTestHostManager), typeof(DotnetTestHostManager))] + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities +{ + /// + /// Custom Attribute to specify the exact types which should be loaded from assembly + /// + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] + internal sealed class TypesToLoadAttribute : Attribute + { + public TypesToLoadAttribute(params Type[] types) + { + this.Types = types; + } + + public Type[] Types { get; } + } +} \ No newline at end of file diff --git a/src/testhost.x86/testhost.x86.csproj b/src/testhost.x86/testhost.x86.csproj index 1527b52d70..b0a9d8eea3 100644 --- a/src/testhost.x86/testhost.x86.csproj +++ b/src/testhost.x86/testhost.x86.csproj @@ -3,6 +3,7 @@ ..\..\ false + true diff --git a/src/testhost/testhost.csproj b/src/testhost/testhost.csproj index a55ef48bb7..f8991d48a3 100644 --- a/src/testhost/testhost.csproj +++ b/src/testhost/testhost.csproj @@ -3,6 +3,7 @@ ..\..\ false + true diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs index d671d4d94c..155772fbd5 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs @@ -4,7 +4,13 @@ namespace Microsoft.TestPlatform.AcceptanceTests { using System; + using System.Collections.Generic; using System.IO; + using System.Linq; + using System.Reflection; + + using Microsoft.TestPlatform.TestUtilities; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] @@ -91,5 +97,31 @@ public void DiscoverTestsShouldShowProperWarningIfNoTestsOnTestCaseFilter(Runner this.ExitCodeEquals(0); } + + [TestMethod] + public void TypesToLoadAttributeTests() + { + var environment = new IntegrationTestEnvironment(); + var extensionsDirectory = environment.ExtensionsDirectory; + var extensionsToVerify = new Dictionary + { + {"Microsoft.TestPlatform.Extensions.EventLogCollector.dll", new[] { "Microsoft.TestPlatform.Extensions.EventLogCollector.EventLogDataCollector"} }, + {"Microsoft.TestPlatform.Extensions.BlameDataCollector.dll", new[] { "Microsoft.TestPlatform.Extensions.BlameDataCollector.BlameLogger", "Microsoft.TestPlatform.Extensions.BlameDataCollector.BlameCollector" } }, + {"Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger.dll", new[] { "Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger" } }, + {"Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.dll", new[] { "Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.TrxLogger" } }, + {"Microsoft.TestPlatform.TestHostRuntimeProvider.dll", new[] { "Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DefaultTestHostManager", "Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager" } } + }; + + foreach (var extension in extensionsToVerify.Keys) + { + var assemblyFile = Path.Combine(extensionsDirectory, extension); + var assembly = Assembly.LoadFrom(assemblyFile); + + var expected = extensionsToVerify[extension]; + var actual = TypesToLoadUtilities.GetTypesToLoad(assembly).Select(i => i.FullName).ToArray(); + + CollectionAssert.AreEquivalent(expected, actual, $"Specified types using TypesToLoadAttribute in \"{extension}\" assembly doesn't match the expected."); + } + } } } diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs index cff43c4ca2..947ad4b53d 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs @@ -97,7 +97,6 @@ public string PublishDirectory { get { - // this used to switch to src\package\package\bin\based on whether // this is running in cli, but that's a bad idea, the console there does not have // a runtime config and will fail to start with error testhostpolicy.dll not found @@ -117,6 +116,11 @@ public string PublishDirectory } } + /// + /// Gets the extensions directory for vstest.console package. + /// + public string ExtensionsDirectory => Path.Combine(PublishDirectory, "Extensions"); + /// /// Gets the target framework. /// Supported values = net451, netcoreapp1.0.