diff --git a/Directory.Build.props b/Directory.Build.props index 32befcfc5d6..8a8cb3fae89 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,6 +10,12 @@ true Latest + + net9.0 + + net8.0 + $(NetCurrent) + diff --git a/Documentation/UnifiedBuild/TFM-Trimming-And-Targeting.md b/Documentation/UnifiedBuild/TFM-Trimming-And-Targeting.md index 59e83ec6a75..7373b8cde48 100644 --- a/Documentation/UnifiedBuild/TFM-Trimming-And-Targeting.md +++ b/Documentation/UnifiedBuild/TFM-Trimming-And-Targeting.md @@ -5,8 +5,8 @@ A Target Framework Moniker (TFM) is the name of the API surface area that a proj ## Problem .NET's product is made up of a wide variety of repositories. Each of these repositories has a number of projects that specify a desired set of target frameworks. This set is largely determined by the *union* of consumers of the component. Where does the component need to run? For instance: -- A library like `System.Text.Json` may multi-target to `netstandard2.0`, `net472`, and `net8.0` because it ships on nuget.org and is intended for consumption by .NET Framework customers in addition to .NET Core customers, as well as downstream components which may be targeting older .NET Core TFMs. -- SDK components may only target `net8.0` because they ship in-box with the .NET 8 runtime. +- A library like `System.Text.Json` may multi-target to `netstandard2.0`, `net472`, and `net9.0` because it ships on nuget.org and is intended for consumption by .NET Framework customers in addition to .NET Core customers, as well as downstream components which may be targeting older .NET Core TFMs. +- SDK components may only target `net9.0` because they ship in-box with the .NET 9 runtime. - .NET tooling components (roslyn, fsharp, etc.) may multi-target to `net7.0` and `net4*` because they will run within Visual Studio (which runs on Framework) as well as different .NET SDK bands that may cross major version boundaries of .NET (`7.0.2xx` and `8.0.1xx`). `net7` represents a common surface area that *should* work well if rolled forward onto .NET 8. While this flexiblity is useful, it does present a significant challenge for .NET distro maintainers. Targeting frameworks other the one currently being built ultimately requires the reference assemblies for that framework. Most Linux distributions disallow internet access while building, so those targeting packs cannot come from the internet. Source-build provides a mechanism for creating these references assemblies during the build, via the [source-build-reference-packages](https://github.com/dotnet/source-build-reference-packages) repository. These are assembled early in the build. There are major downsides to these reference packages: @@ -20,7 +20,7 @@ We can significantly reduce the dependence on reference packages, especially the - The set of frameworks targeted by a project is currently driven by **all** possible consumers not built within the same repository. - When building a specific product (NuGet package, SDK layout, etc.), the set of required input frameworks is usually a subset of the available input frameworks. -Because .NET uses a distributed, many-repository based development model, producing repositories lack information about any specific consumer, and so must produce assets that target any possible use case. In plainer terms, let's say that we have a single repository with 2 projects. One is a non-packable library project that targets `net462`, `net472`, and `net8.0`. The other is a console exe targeting just `net8.0`, which references the library project. When building and publishing the console exe, there is no need to build the `net462` and `net472` assets. Now, let's say we split those projects into two repositories. The library project now must become packable to be referenced in the downstream console project. It also has no way to know that the `net4*` assets are useless. It must build them all. +Because .NET uses a distributed, many-repository based development model, producing repositories lack information about any specific consumer, and so must produce assets that target any possible use case. In plainer terms, let's say that we have a single repository with 2 projects. One is a non-packable library project that targets `net462`, `net472`, and `net9.0`. The other is a console exe targeting just `net9.0`, which references the library project. When building and publishing the console exe, there is no need to build the `net462` and `net472` assets. Now, let's say we split those projects into two repositories. The library project now must become packable to be referenced in the downstream console project. It also has no way to know that the `net4*` assets are useless. It must build them all. Unified Build/source-build builds all input repositories required to produce the assets shipped by .NET distro maintainers, the consumer side of the build **is** known. RedHat ships a RedHat-targeted SDK and packages to its consumers. Microsoft ships packages to nuget.org, SDKs to VS, etc. Roslyn ships packages to nuget.org, VS, and the SDK. When building for a specific consumer in the VMR, a producer should be able to avoid building (trim away) away TFMs that are not used. Practically, this means that an organization should be able to only target TFMs that meet their end-customer's needs. @@ -46,16 +46,7 @@ Any solution must meet the following requirements: To enable latest-targeting, Arcade will introduce a new property file called `TargetFrameworkDefaults.props`. This approach takes direct inspiration from current approaches in runtime and other repositories. -``` - - - net8.0 - $(NetCurrent);net7.0;net6.0 - - -``` - -Initially, this file will contain only one property, the currrent major version of .NET. If additional properties are needed (minimum version, newest framework versions, etc.), they can be added. This file is imported in `Settings.props` within the Arcade SDK. These properties are then used as desired within repositories' project, property files, etc. For example, a project might do the following: +This file is imported in `Settings.props` within the Arcade SDK. These properties are then used as desired within repositories' project, property files, etc. For example, a project might do the following: ``` Microsoft.FileProviders.Composite.csproj diff --git a/NuGet.config b/NuGet.config index a8241532a27..1c02c9f3ffd 100644 --- a/NuGet.config +++ b/NuGet.config @@ -10,6 +10,7 @@ + diff --git a/eng/Microsoft.DotNet.XliffTasks.InTree.targets b/eng/Microsoft.DotNet.XliffTasks.InTree.targets index d466b62f862..40c87b5ef26 100644 --- a/eng/Microsoft.DotNet.XliffTasks.InTree.targets +++ b/eng/Microsoft.DotNet.XliffTasks.InTree.targets @@ -6,6 +6,10 @@ $(XliffTasksBaseOutputDirectory)$(NetCurrent)\ $(XliffTasksBaseOutputDirectory)$(NetFrameworkToolCurrent)\ + + TaskHostFactory + + ResolveProjectReferences diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/BuildReleasePackages.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/BuildReleasePackages.targets index af86865dde7..751a79c43f6 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/BuildReleasePackages.targets +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/BuildReleasePackages.targets @@ -2,7 +2,7 @@ <_NuGetRepackAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(NuGetPackageRoot)microsoft.dotnet.nugetrepack.tasks\$(MicrosoftDotnetNuGetRepackTasksVersion)\tools\net472\Microsoft.DotNet.NuGetRepack.Tasks.dll - <_NuGetRepackAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(NuGetPackageRoot)microsoft.dotnet.nugetrepack.tasks\$(MicrosoftDotnetNuGetRepackTasksVersion)\tools\net8.0\Microsoft.DotNet.NuGetRepack.Tasks.dll + <_NuGetRepackAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(NuGetPackageRoot)microsoft.dotnet.nugetrepack.tasks\$(MicrosoftDotnetNuGetRepackTasksVersion)\tools\net9.0\Microsoft.DotNet.NuGetRepack.Tasks.dll diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props b/src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props index 39214fefaaa..74755a0979a 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props @@ -2,6 +2,6 @@ $(MSBuildThisFileDirectory)net472\Microsoft.DotNet.Arcade.Sdk.dll - $(MSBuildThisFileDirectory)net8.0\Microsoft.DotNet.Arcade.Sdk.dll + $(MSBuildThisFileDirectory)net9.0\Microsoft.DotNet.Arcade.Sdk.dll diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/PublishArtifactsInManifest.proj b/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/PublishArtifactsInManifest.proj index 22061848239..1fb02a6b859 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/PublishArtifactsInManifest.proj +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/PublishArtifactsInManifest.proj @@ -73,7 +73,7 @@ --> - net8.0 + net9.0 Publish diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/PublishSignedAssets.proj b/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/PublishSignedAssets.proj index f94d45c14a8..7dee9bde931 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/PublishSignedAssets.proj +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/PublishSignedAssets.proj @@ -3,7 +3,7 @@ Publish - net8.0 + net9.0 - net8.0 + net9.0 Publish diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/SigningValidation.proj b/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/SigningValidation.proj index ac5f7d4e1aa..8d98eaaf676 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/SigningValidation.proj +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/SigningValidation.proj @@ -18,7 +18,7 @@ - net8.0 + net9.0 Build $(NuGetPackageRoot)Microsoft.DotNet.SignCheck\$(MicrosoftDotNetSignCheckVersion)\tools\Microsoft.DotNet.SignCheck.exe diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/Sign.proj b/src/Microsoft.DotNet.Arcade.Sdk/tools/Sign.proj index d0bade8e0f4..cb58effbb95 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/Sign.proj +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/Sign.proj @@ -72,7 +72,7 @@ SNBinaryPath="$(NuGetPackageRoot)sn\$(SNVersion)\sn.exe" MicroBuildCorePath="$(NuGetPackageRoot)microbuild.core\$(MicroBuildCoreVersion)" WixToolsPath="$(WixInstallPath)" - TarToolPath="$(NuGetPackageRoot)microsoft.dotnet.tar\$(MicrosoftDotNetSignToolVersion)\tools\net8.0\any\Microsoft.Dotnet.Tar.dll" + TarToolPath="$(NuGetPackageRoot)microsoft.dotnet.tar\$(MicrosoftDotNetSignToolVersion)\tools\net9.0\any\Microsoft.Dotnet.Tar.dll" RepackParallelism="$(SignToolRepackParallelism)" MaximumParallelFileSize="$(SignToolRepackMaximumParallelFileSize)" /> diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/TargetFrameworkDefaults.props b/src/Microsoft.DotNet.Arcade.Sdk/tools/TargetFrameworkDefaults.props index b7071a3099a..b0e95dacbf2 100644 --- a/src/Microsoft.DotNet.Arcade.Sdk/tools/TargetFrameworkDefaults.props +++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/TargetFrameworkDefaults.props @@ -10,21 +10,21 @@ - net8.0 + net9.0 - net7.0 + - net6.0 + E.g. net8.0 when NetCurrent is net9.0. --> + net8.0 net481 + E.g. if NetCurrent is net9.0, then NetFrameworkMinimum is net462. --> net462 @@ -32,7 +32,7 @@ - net8.0 + net9.0 $(NetCurrent) - true Open true diff --git a/src/Microsoft.DotNet.Build.Tasks.Feed/build/Microsoft.DotNet.Build.Tasks.Feed.targets b/src/Microsoft.DotNet.Build.Tasks.Feed/build/Microsoft.DotNet.Build.Tasks.Feed.targets index 67ee76f3c2c..d337959ccbd 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Feed/build/Microsoft.DotNet.Build.Tasks.Feed.targets +++ b/src/Microsoft.DotNet.Build.Tasks.Feed/build/Microsoft.DotNet.Build.Tasks.Feed.targets @@ -43,7 +43,7 @@ <_MicrosoftDotNetBuildTasksFeedTaskDir>$(MSBuildThisFileDirectory)../tools/net472/ - <_MicrosoftDotNetBuildTasksFeedTaskDir Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)../tools/net8.0/ + <_MicrosoftDotNetBuildTasksFeedTaskDir Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)../tools/net9.0/ diff --git a/src/Microsoft.DotNet.Build.Tasks.Installers/build/Microsoft.DotNet.Build.Tasks.Installers.props b/src/Microsoft.DotNet.Build.Tasks.Installers/build/Microsoft.DotNet.Build.Tasks.Installers.props index a79104884c9..6a8895b5717 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Installers/build/Microsoft.DotNet.Build.Tasks.Installers.props +++ b/src/Microsoft.DotNet.Build.Tasks.Installers/build/Microsoft.DotNet.Build.Tasks.Installers.props @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)..\tools\net8.0\Microsoft.DotNet.Build.Tasks.Installers.dll + $(MSBuildThisFileDirectory)..\tools\net9.0\Microsoft.DotNet.Build.Tasks.Installers.dll $(MSBuildThisFileDirectory)..\tools\net472\Microsoft.DotNet.Build.Tasks.Installers.dll $(MSBuildThisFileDirectory) diff --git a/src/Microsoft.DotNet.Build.Tasks.Packaging/src/build/Packaging.common.targets b/src/Microsoft.DotNet.Build.Tasks.Packaging/src/build/Packaging.common.targets index 99b1d490a18..4ae4de45955 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Packaging/src/build/Packaging.common.targets +++ b/src/Microsoft.DotNet.Build.Tasks.Packaging/src/build/Packaging.common.targets @@ -4,7 +4,7 @@ - $(MSBuildThisFileDirectory)../tools/net8.0/ + $(MSBuildThisFileDirectory)../tools/net9.0/ $(MSBuildThisFileDirectory)../tools/net472/ $(MSBuildThisFileDirectory)runtime.json diff --git a/src/Microsoft.DotNet.Build.Tasks.Packaging/src/build/Packaging.targets b/src/Microsoft.DotNet.Build.Tasks.Packaging/src/build/Packaging.targets index 8c13d2db732..b90075fb82b 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Packaging/src/build/Packaging.targets +++ b/src/Microsoft.DotNet.Build.Tasks.Packaging/src/build/Packaging.targets @@ -948,6 +948,10 @@ @(NETCoreApp80RIDs) + + + @(NETCoreApp90RIDs) + diff --git a/src/Microsoft.DotNet.Build.Tasks.TargetFramework/src/build/Microsoft.DotNet.Build.Tasks.TargetFramework.props b/src/Microsoft.DotNet.Build.Tasks.TargetFramework/src/build/Microsoft.DotNet.Build.Tasks.TargetFramework.props index 9712b0ad7a1..801ec5cd1d6 100644 --- a/src/Microsoft.DotNet.Build.Tasks.TargetFramework/src/build/Microsoft.DotNet.Build.Tasks.TargetFramework.props +++ b/src/Microsoft.DotNet.Build.Tasks.TargetFramework/src/build/Microsoft.DotNet.Build.Tasks.TargetFramework.props @@ -1,7 +1,7 @@ - ..\tools\net8.0\Microsoft.DotNet.Build.Tasks.TargetFramework.dll + ..\tools\net9.0\Microsoft.DotNet.Build.Tasks.TargetFramework.dll ..\tools\net472\Microsoft.DotNet.Build.Tasks.TargetFramework.dll diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/Misc/msi.csproj b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/Misc/msi.csproj index 40a8c636e93..b2062af0a9a 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/Misc/msi.csproj +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/Misc/msi.csproj @@ -20,7 +20,7 @@ DotnetPlatform __PACKAGE_VERSION__ true - net8.0 + net9.0 diff --git a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/build/Microsoft.DotNet.Build.Tasks.Workloads.props b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/build/Microsoft.DotNet.Build.Tasks.Workloads.props index b7e95130b91..900fdb471a4 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Workloads/src/build/Microsoft.DotNet.Build.Tasks.Workloads.props +++ b/src/Microsoft.DotNet.Build.Tasks.Workloads/src/build/Microsoft.DotNet.Build.Tasks.Workloads.props @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)..\tools\net8.0\Microsoft.DotNet.Build.Tasks.Workloads.dll + $(MSBuildThisFileDirectory)..\tools\net9.0\Microsoft.DotNet.Build.Tasks.Workloads.dll $(MSBuildThisFileDirectory)..\tools\net472\Microsoft.DotNet.Build.Tasks.Workloads.dll diff --git a/src/Microsoft.DotNet.Deployment.Tasks.Links/build/Microsoft.DotNet.Deployment.Tasks.Links.props b/src/Microsoft.DotNet.Deployment.Tasks.Links/build/Microsoft.DotNet.Deployment.Tasks.Links.props index 3ff65b8ca02..dcc239864d6 100644 --- a/src/Microsoft.DotNet.Deployment.Tasks.Links/build/Microsoft.DotNet.Deployment.Tasks.Links.props +++ b/src/Microsoft.DotNet.Deployment.Tasks.Links/build/Microsoft.DotNet.Deployment.Tasks.Links.props @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)net8.0\Microsoft.DotNet.Deployment.Tasks.Links.dll + $(MSBuildThisFileDirectory)net9.0\Microsoft.DotNet.Deployment.Tasks.Links.dll $(MSBuildThisFileDirectory)net472\Microsoft.DotNet.Deployment.Tasks.Links.dll diff --git a/src/Microsoft.DotNet.GenAPI/build/Microsoft.DotNet.GenAPI.targets b/src/Microsoft.DotNet.GenAPI/build/Microsoft.DotNet.GenAPI.targets index 622b5247686..7f8b80acf8b 100644 --- a/src/Microsoft.DotNet.GenAPI/build/Microsoft.DotNet.GenAPI.targets +++ b/src/Microsoft.DotNet.GenAPI/build/Microsoft.DotNet.GenAPI.targets @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)\..\tools\net8.0\Microsoft.DotNet.GenAPI.dll + $(MSBuildThisFileDirectory)\..\tools\net9.0\Microsoft.DotNet.GenAPI.dll $(MSBuildThisFileDirectory)\..\tools\net472\Microsoft.DotNet.GenAPI.dll diff --git a/src/Microsoft.DotNet.GenFacades/build/Microsoft.DotNet.GenFacades.targets b/src/Microsoft.DotNet.GenFacades/build/Microsoft.DotNet.GenFacades.targets index 65045a3ae14..98f22ef3e33 100644 --- a/src/Microsoft.DotNet.GenFacades/build/Microsoft.DotNet.GenFacades.targets +++ b/src/Microsoft.DotNet.GenFacades/build/Microsoft.DotNet.GenFacades.targets @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)..\tools\net8.0\Microsoft.DotNet.GenFacades.dll + $(MSBuildThisFileDirectory)..\tools\net9.0\Microsoft.DotNet.GenFacades.dll $(MSBuildThisFileDirectory)..\tools\net472\Microsoft.DotNet.GenFacades.dll diff --git a/src/Microsoft.DotNet.Helix/Sdk/Readme.md b/src/Microsoft.DotNet.Helix/Sdk/Readme.md index e906c37d63b..58f873d7a20 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/Readme.md +++ b/src/Microsoft.DotNet.Helix/Sdk/Readme.md @@ -54,8 +54,8 @@ In order to run them, one has to publish the SDK locally so that the unit tests ``` 3. Publish Arcade SDK and Helix SDK ```sh - dotnet publish -f net8.0 src/Microsoft.DotNet.Arcade.Sdk/Microsoft.DotNet.Arcade.Sdk.csproj - dotnet publish -f net8.0 src/Microsoft.DotNet.Helix/Sdk/Microsoft.DotNet.Helix.Sdk.csproj + dotnet publish -f net9.0 src/Microsoft.DotNet.Arcade.Sdk/Microsoft.DotNet.Arcade.Sdk.csproj + dotnet publish -f net9.0 src/Microsoft.DotNet.Helix/Sdk/Microsoft.DotNet.Helix.Sdk.csproj ``` 4. Pick one of the test `.proj` files, set some env variables and build it Bash diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/Microsoft.DotNet.Helix.Sdk.props b/src/Microsoft.DotNet.Helix/Sdk/tools/Microsoft.DotNet.Helix.Sdk.props index 1c51c1822e8..ec91afae3d6 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/Microsoft.DotNet.Helix.Sdk.props +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/Microsoft.DotNet.Helix.Sdk.props @@ -4,7 +4,7 @@ - $(MSBuildThisFileDirectory)net8.0/Microsoft.DotNet.Helix.Sdk.dll + $(MSBuildThisFileDirectory)net9.0/Microsoft.DotNet.Helix.Sdk.dll $(MSBuildThisFileDirectory)net472/Microsoft.DotNet.Helix.Sdk.dll diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/dotnet-cli/DotNetCli.props b/src/Microsoft.DotNet.Helix/Sdk/tools/dotnet-cli/DotNetCli.props index 6d5a8077143..90d0f74a2a7 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/dotnet-cli/DotNetCli.props +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/dotnet-cli/DotNetCli.props @@ -2,7 +2,7 @@ false - 8.0.0 + 9.0.0-alpha.1.23612.4 runtime $(BundledNETCoreAppPackageVersion) diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/xunit-runner/XUnitRunner.targets b/src/Microsoft.DotNet.Helix/Sdk/tools/xunit-runner/XUnitRunner.targets index dc5988bb1fd..b6c898c59f3 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/xunit-runner/XUnitRunner.targets +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/xunit-runner/XUnitRunner.targets @@ -1,6 +1,6 @@ - net8.0 + net9.0 netcoreapp2.0 2.6.1 diff --git a/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props b/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props index 82850655678..394ed5cc66c 100644 --- a/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props +++ b/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props @@ -3,7 +3,7 @@ $(MSBuildThisFileDirectory)..\tools\net472\Microsoft.DotNet.PackageTesting.dll - $(MSBuildThisFileDirectory)..\tools\net8.0\Microsoft.DotNet.PackageTesting.dll + $(MSBuildThisFileDirectory)..\tools\net9.0\Microsoft.DotNet.PackageTesting.dll diff --git a/src/Microsoft.DotNet.SharedFramework.Sdk/sdk/Sdk.props b/src/Microsoft.DotNet.SharedFramework.Sdk/sdk/Sdk.props index 44951b96d49..77176b15280 100644 --- a/src/Microsoft.DotNet.SharedFramework.Sdk/sdk/Sdk.props +++ b/src/Microsoft.DotNet.SharedFramework.Sdk/sdk/Sdk.props @@ -9,7 +9,7 @@ --> - $(MSBuildThisFileDirectory)../tools/net8.0/ + $(MSBuildThisFileDirectory)../tools/net9.0/ $(MSBuildThisFileDirectory)../tools/net472/ diff --git a/src/Microsoft.DotNet.SignTool/build/Microsoft.DotNet.SignTool.props b/src/Microsoft.DotNet.SignTool/build/Microsoft.DotNet.SignTool.props index 369cb60a25e..3522d8c5faf 100644 --- a/src/Microsoft.DotNet.SignTool/build/Microsoft.DotNet.SignTool.props +++ b/src/Microsoft.DotNet.SignTool/build/Microsoft.DotNet.SignTool.props @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)..\lib\net8.0\Microsoft.DotNet.SignTool.dll + $(MSBuildThisFileDirectory)..\lib\net9.0\Microsoft.DotNet.SignTool.dll $(MSBuildThisFileDirectory)..\lib\net472\Microsoft.DotNet.SignTool.dll diff --git a/src/Microsoft.DotNet.SourceBuild/tasks/build/Microsoft.DotNet.SourceBuild.Tasks.props b/src/Microsoft.DotNet.SourceBuild/tasks/build/Microsoft.DotNet.SourceBuild.Tasks.props index 9dc4c6ccc2a..a49ee2b651a 100644 --- a/src/Microsoft.DotNet.SourceBuild/tasks/build/Microsoft.DotNet.SourceBuild.Tasks.props +++ b/src/Microsoft.DotNet.SourceBuild/tasks/build/Microsoft.DotNet.SourceBuild.Tasks.props @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)..\tools\net8.0\$(MSBuildThisFileName).dll + $(MSBuildThisFileDirectory)..\tools\net9.0\$(MSBuildThisFileName).dll $(MSBuildThisFileDirectory)..\tools\net472\$(MSBuildThisFileName).dll diff --git a/src/Microsoft.DotNet.SwaggerGenerator/Microsoft.DotNet.SwaggerGenerator.MSBuild/build/Microsoft.DotNet.SwaggerGenerator.MSBuild.props b/src/Microsoft.DotNet.SwaggerGenerator/Microsoft.DotNet.SwaggerGenerator.MSBuild/build/Microsoft.DotNet.SwaggerGenerator.MSBuild.props index 5362d800fc7..1ae4e21caed 100644 --- a/src/Microsoft.DotNet.SwaggerGenerator/Microsoft.DotNet.SwaggerGenerator.MSBuild/build/Microsoft.DotNet.SwaggerGenerator.MSBuild.props +++ b/src/Microsoft.DotNet.SwaggerGenerator/Microsoft.DotNet.SwaggerGenerator.MSBuild/build/Microsoft.DotNet.SwaggerGenerator.MSBuild.props @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)../tools/net8.0/Microsoft.DotNet.SwaggerGenerator.MSBuild.dll + $(MSBuildThisFileDirectory)../tools/net9.0/Microsoft.DotNet.SwaggerGenerator.MSBuild.dll $(MSBuildThisFileDirectory)../tools/net472/Microsoft.DotNet.SwaggerGenerator.MSBuild.dll diff --git a/src/Microsoft.DotNet.VersionTools/tasks/build/Microsoft.DotNet.VersionTools.Tasks.props b/src/Microsoft.DotNet.VersionTools/tasks/build/Microsoft.DotNet.VersionTools.Tasks.props index 39e19a9ab9e..ae3c813ac77 100644 --- a/src/Microsoft.DotNet.VersionTools/tasks/build/Microsoft.DotNet.VersionTools.Tasks.props +++ b/src/Microsoft.DotNet.VersionTools/tasks/build/Microsoft.DotNet.VersionTools.Tasks.props @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)..\tools\net8.0\$(MSBuildThisFileName).dll + $(MSBuildThisFileDirectory)..\tools\net9.0\$(MSBuildThisFileName).dll $(MSBuildThisFileDirectory)..\tools\net472\$(MSBuildThisFileName).dll diff --git a/src/Microsoft.DotNet.XUnitAssert/src/Assert.cs b/src/Microsoft.DotNet.XUnitAssert/src/Assert.cs index 2dd358049d5..313fbb338bf 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/Assert.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/Assert.cs @@ -7,6 +7,7 @@ using System; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace Xunit { @@ -52,10 +53,12 @@ protected Assert() { } /// /// The potentially generic type /// The generic type definition, when is generic; null, otherwise. + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] + [UnconditionalSuppressMessage("Trimmability", "IL2073", Justification = "The interfaces on a generic type definition won't be trimmed if they're preserved for an instantation.")] #if XUNIT_NULLABLE - static Type? SafeGetGenericTypeDefinition(Type? type) + static Type? SafeGetGenericTypeDefinition([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type? type) #else - static Type SafeGetGenericTypeDefinition(Type type) + static Type SafeGetGenericTypeDefinition([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type) #endif { if (type == null) diff --git a/src/Microsoft.DotNet.XUnitAssert/src/CollectionAsserts.cs b/src/Microsoft.DotNet.XUnitAssert/src/CollectionAsserts.cs index eb9145dc2d7..12a90ce9416 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/CollectionAsserts.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/CollectionAsserts.cs @@ -32,7 +32,12 @@ partial class Assert /// The collection /// The action to test each item against /// Thrown when the collection contains at least one non-matching element - public static void All( + public static void All<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, Action action) { @@ -50,7 +55,12 @@ public static void All( /// The collection /// The action to test each item against /// Thrown when the collection contains at least one non-matching element - public static void All( + public static void All<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, Action action) { @@ -86,7 +96,7 @@ public static void All( /// The collection /// The action to test each item against /// Thrown when the collection contains at least one non-matching element - public static async Task AllAsync( + public static async Task AllAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, Func action) { @@ -104,7 +114,7 @@ public static async Task AllAsync( /// The collection /// The action to test each item against /// Thrown when the collection contains at least one non-matching element - public static async Task AllAsync( + public static async Task AllAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, Func action) { @@ -140,7 +150,7 @@ public static async Task AllAsync( /// The collection to be inspected /// The element inspectors, which inspect each element in turn. The /// total number of element inspectors must exactly match the number of elements in the collection. - public static void Collection( + public static void Collection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, params Action[] elementInspectors) { @@ -181,7 +191,7 @@ public static void Collection( /// The collection to be inspected /// The element inspectors, which inspect each element in turn. The /// total number of element inspectors must exactly match the number of elements in the collection. - public static async Task CollectionAsync( + public static async Task CollectionAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, params Func[] elementInspectors) { @@ -221,7 +231,12 @@ public static async Task CollectionAsync( /// The object expected to be in the collection /// The collection to be inspected /// Thrown when the object is not present in the collection - public static void Contains<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void Contains<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, IEnumerable collection) { @@ -244,7 +259,7 @@ public static async Task CollectionAsync( /// The collection to be inspected /// The comparer used to equate objects in the collection with the expected object /// Thrown when the object is not present in the collection - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, IEnumerable collection, IEqualityComparer comparer) @@ -264,7 +279,7 @@ public static void Contains( /// The collection to be inspected /// The filter used to find the item you're ensuring the collection contains /// Thrown when the object is not present in the collection - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, Predicate filter) { @@ -287,7 +302,7 @@ public static void Contains( /// The type of the object to be compared /// The collection to be inspected /// Thrown when an object is present inside the collection more than once - public static void Distinct(IEnumerable collection) => + public static void Distinct<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>(IEnumerable collection) => Distinct(collection, EqualityComparer.Default); /// @@ -297,7 +312,7 @@ public static void Distinct(IEnumerable collection) => /// The collection to be inspected /// The comparer used to equate objects in the collection with the expected object /// Thrown when an object is present inside the collection more than once - public static void Distinct( + public static void Distinct<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, IEqualityComparer comparer) { @@ -321,7 +336,12 @@ public static void Distinct( /// The object that is expected not to be in the collection /// The collection to be inspected /// Thrown when the object is present inside the container - public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, IEnumerable collection) { @@ -344,7 +364,7 @@ public static void Distinct( /// The collection to be inspected /// The comparer used to equate objects in the collection with the expected object /// Thrown when the object is present inside the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, IEnumerable collection, IEqualityComparer comparer) @@ -383,7 +403,7 @@ public static void DoesNotContain( /// The collection to be inspected /// The filter used to find the item you're ensuring the collection does not contain /// Thrown when the object is present inside the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, Predicate filter) { @@ -438,7 +458,7 @@ public static void Empty(IEnumerable collection) /// The expected value /// The value to be compared against /// Thrown when the objects are not equal - public static void Equal( + public static void Equal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE IEnumerable? expected, IEnumerable? actual) => @@ -456,7 +476,7 @@ public static void Equal( /// The value to be compared against /// The comparer used to compare the two objects /// Thrown when the objects are not equal - public static void Equal( + public static void Equal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE IEnumerable? expected, IEnumerable? actual, @@ -475,7 +495,12 @@ public static void Equal( /// The expected value /// The value to be compared against /// The function to compare two items for equality - public static void Equal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void Equal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE IEnumerable? expected, IEnumerable? actual, @@ -515,7 +540,7 @@ public static void NotEmpty(IEnumerable collection) /// The expected object /// The actual object /// Thrown when the objects are equal - public static void NotEqual( + public static void NotEqual<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE IEnumerable? expected, IEnumerable? actual) => @@ -533,7 +558,7 @@ public static void NotEqual( /// The actual object /// The comparer used to compare the two objects /// Thrown when the objects are equal - public static void NotEqual( + public static void NotEqual<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE IEnumerable? expected, IEnumerable? actual, @@ -552,7 +577,12 @@ public static void NotEqual( /// The expected value /// The value to be compared against /// The function to compare two items for equality - public static void NotEqual<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void NotEqual<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE IEnumerable? expected, IEnumerable? actual, @@ -614,7 +644,7 @@ public static void Single( /// The single item in the collection. /// Thrown when the collection does not contain /// exactly one element. - public static T Single(IEnumerable collection) + public static T Single<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>(IEnumerable collection) { GuardArgumentNotNull(nameof(collection), collection); @@ -633,7 +663,7 @@ public static T Single(IEnumerable collection) /// The single item in the filtered collection. /// Thrown when the filtered collection does /// not contain exactly one element. - public static T Single( + public static T Single<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, Predicate predicate) { @@ -643,7 +673,7 @@ public static T Single( return GetSingleResult(collection, predicate, "(predicate expression)"); } - static T GetSingleResult( + static T GetSingleResult<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( IEnumerable collection, #if XUNIT_NULLABLE Predicate? predicate, diff --git a/src/Microsoft.DotNet.XUnitAssert/src/Comparers.cs b/src/Microsoft.DotNet.XUnitAssert/src/Comparers.cs index a8148c36033..d15a1122479 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/Comparers.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/Comparers.cs @@ -25,10 +25,20 @@ static IComparer GetComparer() new AssertComparer(); #if XUNIT_NULLABLE - static IEqualityComparer GetEqualityComparer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>(IEqualityComparer? innerComparer = null) => + static IEqualityComparer GetEqualityComparer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>(IEqualityComparer? innerComparer = null) => new AssertEqualityComparer(innerComparer); #else - static IEqualityComparer GetEqualityComparer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>(IEqualityComparer innerComparer = null) => + static IEqualityComparer GetEqualityComparer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>(IEqualityComparer innerComparer = null) => new AssertEqualityComparer(innerComparer); #endif } diff --git a/src/Microsoft.DotNet.XUnitAssert/src/DictionaryAsserts.cs b/src/Microsoft.DotNet.XUnitAssert/src/DictionaryAsserts.cs index 19f8cfb6405..5dda27ba063 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/DictionaryAsserts.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/DictionaryAsserts.cs @@ -9,6 +9,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using Xunit.Sdk; #if XUNIT_IMMUTABLE_COLLECTIONS @@ -33,7 +34,12 @@ partial class Assert /// The collection to be inspected. /// The value associated with . /// Thrown when the object is not present in the collection - public static TValue Contains( + public static TValue Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, IDictionary collection) #if XUNIT_NULLABLE @@ -62,7 +68,12 @@ public static TValue Contains( /// The collection to be inspected. /// The value associated with . /// Thrown when the object is not present in the collection - public static TValue Contains( + public static TValue Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, IReadOnlyDictionary collection) #if XUNIT_NULLABLE @@ -91,7 +102,12 @@ public static TValue Contains( /// The collection to be inspected. /// The value associated with . /// Thrown when the object is not present in the collection - public static TValue Contains( + public static TValue Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, ConcurrentDictionary collection) #if XUNIT_NULLABLE @@ -110,7 +126,12 @@ public static TValue Contains( /// The collection to be inspected. /// The value associated with . /// Thrown when the object is not present in the collection - public static TValue Contains( + public static TValue Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, Dictionary collection) #if XUNIT_NULLABLE @@ -129,7 +150,12 @@ public static TValue Contains( /// The collection to be inspected. /// The value associated with . /// Thrown when the object is not present in the collection - public static TValue Contains( + public static TValue Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, ReadOnlyDictionary collection) #if XUNIT_NULLABLE @@ -149,7 +175,12 @@ public static TValue Contains( /// The collection to be inspected. /// The value associated with . /// Thrown when the object is not present in the collection - public static TValue Contains( + public static TValue Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)]TKey, TValue>( TKey expected, ImmutableDictionary collection) #if XUNIT_NULLABLE @@ -168,7 +199,12 @@ public static TValue Contains( /// The object expected to be in the collection. /// The collection to be inspected. /// Thrown when the object is present in the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, IDictionary collection) #if XUNIT_NULLABLE @@ -194,7 +230,7 @@ public static void DoesNotContain( /// The object expected to be in the collection. /// The collection to be inspected. /// Thrown when the object is present in the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, IReadOnlyDictionary collection) #if XUNIT_NULLABLE @@ -220,7 +256,7 @@ public static void DoesNotContain( /// The object expected to be in the collection. /// The collection to be inspected. /// Thrown when the object is present in the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, ConcurrentDictionary collection) #if XUNIT_NULLABLE @@ -238,7 +274,7 @@ public static void DoesNotContain( /// The object expected to be in the collection. /// The collection to be inspected. /// Thrown when the object is present in the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, Dictionary collection) #if XUNIT_NULLABLE @@ -256,7 +292,7 @@ public static void DoesNotContain( /// The object expected to be in the collection. /// The collection to be inspected. /// Thrown when the object is present in the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] TKey, TValue>( TKey expected, ReadOnlyDictionary collection) #if XUNIT_NULLABLE @@ -275,7 +311,12 @@ public static void DoesNotContain( /// The object expected to be in the collection. /// The collection to be inspected. /// Thrown when the object is present in the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)]TKey, TValue>( TKey expected, ImmutableDictionary collection) #if XUNIT_NULLABLE diff --git a/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs b/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs index f16eeb0e181..35731be80bd 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/EqualityAsserts.cs @@ -72,7 +72,13 @@ public static void Equal( /// The expected value /// The value to be compared against /// Thrown when the objects are not equal - public static void Equal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void Equal<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.Interfaces + | DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE [AllowNull] T expected, [AllowNull] T actual) => @@ -89,7 +95,13 @@ public static void Equal( /// The expected value /// The value to be compared against /// The comparer used to compare the two objects - public static void Equal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void Equal<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.Interfaces + | DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE [AllowNull] T expected, [AllowNull] T actual, @@ -108,7 +120,13 @@ public static void Equal( /// The value to be compared against /// The comparer used to compare the two objects /// Thrown when the objects are not equal - public static void Equal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void Equal<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.Interfaces + | DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE [AllowNull] T expected, [AllowNull] T actual, @@ -231,25 +249,13 @@ public static void Equal( } #if XUNIT_NULLABLE - string? collectionDisplay = null; + string? collectionDisplay = GetCollectionDisplay(expected, actual); #else - string collectionDisplay = null; + string collectionDisplay = GetCollectionDisplay(expected, actual); #endif var expectedType = expected?.GetType(); - var expectedTypeDefinition = SafeGetGenericTypeDefinition(expectedType); - var expectedInterfaceTypeDefinitions = expectedType?.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType).Select(i => i.GetGenericTypeDefinition()); - var actualType = actual?.GetType(); - var actualTypeDefinition = SafeGetGenericTypeDefinition(actualType); - var actualInterfaceTypeDefinitions = actualType?.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType).Select(i => i.GetGenericTypeDefinition()); - - if (expectedTypeDefinition == typeofDictionary && actualTypeDefinition == typeofDictionary) - collectionDisplay = "Dictionaries"; - else if (expectedTypeDefinition == typeofHashSet && actualTypeDefinition == typeofHashSet) - collectionDisplay = "HashSets"; - else if (expectedInterfaceTypeDefinitions != null && actualInterfaceTypeDefinitions != null && expectedInterfaceTypeDefinitions.Contains(typeofSet) && actualInterfaceTypeDefinitions.Contains(typeofSet)) - collectionDisplay = "Sets"; if (expectedType != actualType) { @@ -277,6 +283,39 @@ public static void Equal( } } + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ISet<>))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Dictionary<,>))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(HashSet<>))] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072", Justification = "We only check for the types listed above.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075", Justification = "We only check for the types listed above.")] +#if XUNIT_NULLABLE + private static string? GetCollectionDisplay(object? expected, object? actual) +#else + private static string GetCollectionDisplay(object expected, object actual) +#endif + { +#if XUNIT_NULLABLE + string? collectionDisplay = null; +#else + string collectionDisplay = null; +#endif + var expectedType = expected?.GetType(); + var actualType = actual?.GetType(); + var expectedTypeDefinition = SafeGetGenericTypeDefinition(expectedType); + var expectedInterfaceTypeDefinitions = expectedType?.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType).Select(i => i.GetGenericTypeDefinition()); + + var actualTypeDefinition = SafeGetGenericTypeDefinition(actualType); + var actualInterfaceTypeDefinitions = actualType?.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType).Select(i => i.GetGenericTypeDefinition()); + + if (expectedTypeDefinition == typeofDictionary && actualTypeDefinition == typeofDictionary) + collectionDisplay = "Dictionaries"; + else if (expectedTypeDefinition == typeofHashSet && actualTypeDefinition == typeofHashSet) + collectionDisplay = "HashSets"; + else if (expectedInterfaceTypeDefinitions != null && actualInterfaceTypeDefinitions != null && expectedInterfaceTypeDefinitions.Contains(typeofSet) && actualInterfaceTypeDefinitions.Contains(typeofSet)) + collectionDisplay = "Sets"; + return collectionDisplay; + } + /// /// Verifies that two values are equal, within the number of decimal /// places given by . The values are rounded before comparison. @@ -546,7 +585,12 @@ public static void NotEqual( /// The expected object /// The actual object /// Thrown when the objects are equal - public static void NotEqual<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void NotEqual<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE [AllowNull] T expected, [AllowNull] T actual) => @@ -563,7 +607,12 @@ public static void NotEqual( /// The expected object /// The actual object /// The comparer used to examine the objects - public static void NotEqual<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + public static void NotEqual<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE [AllowNull] T expected, [AllowNull] T actual, @@ -582,7 +631,12 @@ public static void NotEqual( /// The actual object /// The comparer used to examine the objects public static void NotEqual< - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE [AllowNull] T expected, [AllowNull] T actual, @@ -701,25 +755,13 @@ public static void NotEqual< } #if XUNIT_NULLABLE - string? collectionDisplay = null; + string? collectionDisplay = GetCollectionDisplay(expected, actual); #else - string collectionDisplay = null; + string collectionDisplay = GetCollectionDisplay(expected, actual); #endif var expectedType = expected?.GetType(); - var expectedTypeDefinition = SafeGetGenericTypeDefinition(expectedType); - var expectedInterfaceTypeDefinitions = expectedType?.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType).Select(i => i.GetGenericTypeDefinition()); - var actualType = actual?.GetType(); - var actualTypeDefinition = SafeGetGenericTypeDefinition(actualType); - var actualInterfaceTypeDefinitions = actualType?.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType).Select(i => i.GetGenericTypeDefinition()); - - if (expectedTypeDefinition == typeofDictionary && actualTypeDefinition == typeofDictionary) - collectionDisplay = "Dictionaries"; - else if (expectedTypeDefinition == typeofHashSet && actualTypeDefinition == typeofHashSet) - collectionDisplay = "HashSets"; - else if (expectedInterfaceTypeDefinitions != null && actualInterfaceTypeDefinitions != null && expectedInterfaceTypeDefinitions.Contains(typeofSet) && actualInterfaceTypeDefinitions.Contains(typeofSet)) - collectionDisplay = "Sets"; if (expectedType != actualType) { @@ -919,7 +961,12 @@ public static void NotEqual( /// The type of the objects to be compared /// The expected object /// The actual object - public static void NotStrictEqual( + public static void NotStrictEqual<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE [AllowNull] T expected, [AllowNull] T actual) @@ -943,7 +990,12 @@ public static void NotStrictEqual( /// The type of the objects to be compared /// The expected value /// The value to be compared against - public static void StrictEqual( + public static void StrictEqual<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( #if XUNIT_NULLABLE [AllowNull] T expected, [AllowNull] T actual) diff --git a/src/Microsoft.DotNet.XUnitAssert/src/MemoryAsserts.cs b/src/Microsoft.DotNet.XUnitAssert/src/MemoryAsserts.cs index fe1f8714261..f62bdc33927 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/MemoryAsserts.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/MemoryAsserts.cs @@ -5,6 +5,7 @@ #endif using System; +using System.Diagnostics.CodeAnalysis; using Xunit.Sdk; namespace Xunit @@ -129,7 +130,12 @@ public static void Contains( /// The sub-Memory expected to be in the Memory /// The Memory to be inspected /// Thrown when the sub-Memory is not present inside the Memory - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Memory expectedSubMemory, Memory actualMemory) where T : IEquatable => @@ -141,7 +147,12 @@ public static void Contains( /// The sub-Memory expected to be in the Memory /// The Memory to be inspected /// Thrown when the sub-Memory is not present inside the Memory - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Memory expectedSubMemory, ReadOnlyMemory actualMemory) where T : IEquatable => @@ -153,7 +164,12 @@ public static void Contains( /// The sub-Memory expected to be in the Memory /// The Memory to be inspected /// Thrown when the sub-Memory is not present inside the Memory - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ReadOnlyMemory expectedSubMemory, Memory actualMemory) where T : IEquatable => @@ -165,7 +181,12 @@ public static void Contains( /// The sub-Memory expected to be in the Memory /// The Memory to be inspected /// Thrown when the sub-Memory is not present inside the Memory - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ReadOnlyMemory expectedSubMemory, ReadOnlyMemory actualMemory) where T : IEquatable @@ -285,7 +306,12 @@ public static void DoesNotContain( /// The sub-Memory expected not to be in the Memory /// The Memory to be inspected /// Thrown when the sub-Memory is present inside the Memory - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Memory expectedSubMemory, Memory actualMemory) where T : IEquatable => @@ -297,7 +323,12 @@ public static void DoesNotContain( /// The sub-Memory expected not to be in the Memory /// The Memory to be inspected /// Thrown when the sub-Memory is present inside the Memory - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Memory expectedSubMemory, ReadOnlyMemory actualMemory) where T : IEquatable => @@ -309,7 +340,12 @@ public static void DoesNotContain( /// The sub-Memory expected not to be in the Memory /// The Memory to be inspected /// Thrown when the sub-Memory is present inside the Memory - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ReadOnlyMemory expectedSubMemory, Memory actualMemory) where T : IEquatable => @@ -321,7 +357,12 @@ public static void DoesNotContain( /// The sub-Memory expected not to be in the Memory /// The Memory to be inspected /// Thrown when the sub-Memory is present inside the Memory - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ReadOnlyMemory expectedSubMemory, ReadOnlyMemory actualMemory) where T : IEquatable diff --git a/src/Microsoft.DotNet.XUnitAssert/src/NullAsserts.cs b/src/Microsoft.DotNet.XUnitAssert/src/NullAsserts.cs index 1121468f3b3..540d4a30051 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/NullAsserts.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/NullAsserts.cs @@ -72,7 +72,12 @@ public static void Null(object @object) /// /// The value to be inspected /// Thrown when the value is not null - public static void Null(T? value) + public static void Null<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>(T? value) where T : struct { if (value.HasValue) diff --git a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/ArgumentFormatter.cs b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/ArgumentFormatter.cs index 25e8221eaef..98c747417aa 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/ArgumentFormatter.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/ArgumentFormatter.cs @@ -133,12 +133,32 @@ public static string EscapeString(string s) return builder.ToString(); } +#if XUNIT_NULLABLE + public static string Format(Type? value) +#else + public static string Format(Type value) +#endif + { + if (value is null) + return "null"; + + return string.Format(CultureInfo.CurrentCulture, "typeof({0})", FormatTypeName(value, fullTypeName: true)); + } + /// /// Formats a value for display. /// /// The value to be formatted /// The optional printing depth (1 indicates a top-level value) - public static string Format(T value, int depth = 1) + [DynamicDependency("ToString", typeof(object))] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072", Justification = "We can't easily annotate callers of this type to require them to preserve the ToString method as we need to use the runtime type. We also can't preserve all of the properties and fields for the complex type printing, but any members that are trimmed aren't used and thus don't contribute to the asserts.")] + public static string Format< + [DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T>(T value, int depth = 1) { if (value == null) return "null"; @@ -436,9 +456,12 @@ public static string FormatTypeName( return result + arraySuffix; } + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(KeyValuePair<,>))] + [DynamicDependency("ToString", typeof(object))] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070", Justification = "We can't easily annotate callers of this type to require them to preserve properties for the one type we need or the ToString method as we need to use the runtime type")] static string FormatValueTypeValue( object value, - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] TypeInfo typeInfo) + TypeInfo typeInfo) { if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(KeyValuePair<,>)) { @@ -451,6 +474,8 @@ static string FormatValueTypeValue( return Convert.ToString(value, CultureInfo.CurrentCulture) ?? "null"; } + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ISet<>))] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075", Justification = "We can't easily annotate callers of this type to require them to preserve interfaces, so just preserve the one interface that's checked for.")] #if XUNIT_NULLABLE internal static Type? GetSetElementType(object? obj) #else diff --git a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/AssertEqualityComparer.cs b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/AssertEqualityComparer.cs index 03612c023b5..3cd4a490f17 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/AssertEqualityComparer.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/AssertEqualityComparer.cs @@ -27,7 +27,13 @@ namespace Xunit.Sdk /// Default implementation of used by the xUnit.net equality assertions. /// /// The type that is being compared. - sealed class AssertEqualityComparer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T> : IEqualityComparer + sealed class AssertEqualityComparer< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields | + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + DynamicallyAccessedMemberTypes.PublicMethods)] T> : IEqualityComparer { internal static readonly IEqualityComparer DefaultInnerComparer = new AssertEqualityComparerAdapter(new AssertEqualityComparer()); @@ -86,10 +92,9 @@ public bool Equals( if (equatable != null) return equatable.Equals(y); +#if !XUNIT_AOT var xType = x.GetType(); var yType = y.GetType(); - -#if !XUNIT_AOT var xTypeInfo = xType.GetTypeInfo(); // Implements IEquatable? @@ -180,14 +185,12 @@ public bool Equals( } // Special case KeyValuePair - if (xType.IsConstructedGenericType && - xType.GetGenericTypeDefinition() == typeKeyValuePair && - yType.IsConstructedGenericType && - yType.GetGenericTypeDefinition() == typeKeyValuePair) + if (typeof(T).IsConstructedGenericType && + typeof(T).GetGenericTypeDefinition() == typeKeyValuePair) { return - innerComparer.Value.Equals(xType.GetRuntimeProperty("Key")?.GetValue(x), yType.GetRuntimeProperty("Key")?.GetValue(y)) && - innerComparer.Value.Equals(xType.GetRuntimeProperty("Value")?.GetValue(x), yType.GetRuntimeProperty("Value")?.GetValue(y)); + innerComparer.Value.Equals(typeof(T).GetRuntimeProperty("Key")?.GetValue(x), typeof(T).GetRuntimeProperty("Key")?.GetValue(y)) && + innerComparer.Value.Equals(typeof(T).GetRuntimeProperty("Value")?.GetValue(x), typeof(T).GetRuntimeProperty("Value")?.GetValue(y)); } // Last case, rely on object.Equals @@ -306,7 +309,13 @@ public TypeErasedEqualityComparer(IEqualityComparer innerComparer) #endif // XUNIT_AOT } - bool EqualsGeneric<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] U>( + bool EqualsGeneric<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.Interfaces + | DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] U>( U x, U y) => new AssertEqualityComparer(innerComparer: innerComparer).Equals(x, y); diff --git a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/AssertHelper.cs b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/AssertHelper.cs index 13035cc3dac..46a1c9b0e35 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/AssertHelper.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/AssertHelper.cs @@ -49,7 +49,7 @@ internal static class AssertHelper const string fileSystemInfoFqn = "System.IO.FileSystemInfo, System.Runtime"; #if XUNIT_NULLABLE static readonly Lazy fileSystemInfoTypeInfo = new Lazy(() => Type.GetType(fileSystemInfoFqn)?.GetTypeInfo()); - static readonly Lazy fileSystemInfoFullNameProperty = new Lazy(() => fileSystemInfoTypeInfo.Value?.GetDeclaredProperty("FullName")); + static readonly Lazy fileSystemInfoFullNameProperty = new Lazy(() => Type.GetType(fileSystemInfoFqn)?.GetTypeInfo().GetDeclaredProperty("FullName")); #else static readonly Lazy fileSystemInfoTypeInfo = new Lazy(() => GetTypeInfo(fileSystemInfoFqn)?.GetTypeInfo()); static readonly Lazy fileSystemInfoFullNameProperty = new Lazy(() => fileSystemInfoTypeInfo.Value?.GetDeclaredProperty("FullName")); @@ -85,10 +85,19 @@ internal static class AssertHelper #endif }); + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111: Method 'lambda expression' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.", Justification = "The lambda will only be called by the value in the type parameter, which has the same requirements.")] #if XUNIT_NULLABLE - static Dictionary> GetGettersForType(Type type) => + static Dictionary> GetGettersForType([DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties)] Type type) => #else - static Dictionary> GetGettersForType(Type type) => + static Dictionary> GetGettersForType([DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties)] Type type) => #endif gettersByType.GetOrAdd(type, ([DynamicallyAccessedMembers( @@ -234,13 +243,31 @@ public static EquivalentException VerifyEquivalence( } #if XUNIT_NULLABLE - static EquivalentException? VerifyEquivalence( - object? expected, - object? actual, + static EquivalentException? VerifyEquivalence<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties)] T, + [DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties)] U>( + T? expected, + U? actual, #else - static EquivalentException VerifyEquivalence( - object expected, - object actual, + static EquivalentException VerifyEquivalence<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties)] T, + [DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties)] U>( + T expected, + U actual, #endif bool strict, string prefix, @@ -449,6 +476,7 @@ static EquivalentException VerifyEquivalenceIntrinsics( return result ? null : EquivalentException.ForMemberValueMismatch(expected, actual, prefix); } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072", Justification = "We need to use the runtime type for getting the getters as we can't recursively preserve them. Any members that are trimmed were not touched by the test and likely are not important for equivalence.")] #if XUNIT_NULLABLE static EquivalentException? VerifyEquivalenceReference( #else diff --git a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/CollectionTracker.cs b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/CollectionTracker.cs index 4112eb195f9..09db897bc8b 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/CollectionTracker.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/CollectionTracker.cs @@ -410,7 +410,12 @@ public static CollectionTracker Wrap(IEnumerable enumerable) => #else public #endif - sealed class CollectionTracker : CollectionTracker, IEnumerable + sealed class CollectionTracker<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T> : CollectionTracker, IEnumerable { const int MAX_ENUMERABLE_LENGTH_HALF = ArgumentFormatter.MAX_ENUMERABLE_LENGTH / 2; diff --git a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/CollectionTrackerExtensions.cs b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/CollectionTrackerExtensions.cs index 8390f59a8ae..f37d77b49c6 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/CollectionTrackerExtensions.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/CollectionTrackerExtensions.cs @@ -96,7 +96,12 @@ public static CollectionTracker AsTracker(this IEnumerable enumerable) /// The enumerable to be wrapped #if XUNIT_NULLABLE [return: NotNullIfNotNull("enumerable")] - public static CollectionTracker? AsTracker(this IEnumerable? enumerable) => + public static CollectionTracker? AsTracker<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>(this IEnumerable? enumerable) => #else public static CollectionTracker AsTracker(this IEnumerable enumerable) => #endif diff --git a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/Exceptions/NullException.cs b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/Exceptions/NullException.cs index f28bfd00d4a..cc41c508dd0 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/Sdk/Exceptions/NullException.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/Sdk/Exceptions/NullException.cs @@ -6,6 +6,7 @@ #endif using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace Xunit.Sdk @@ -30,7 +31,12 @@ partial class NullException : XunitException /// /// The inner type of the value /// The actual non-null value - public static Exception ForNonNullStruct( + public static Exception ForNonNullStruct<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Type type, T? actual) where T : struct => @@ -50,7 +56,14 @@ public static Exception ForNonNullStruct( /// when the given value was unexpectedly not null. /// /// The actual non-null value - public static NullException ForNonNullValue(object actual) => + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2019:Mismatched constraints", + Justification = "Assert.GuardArgumentNotNull returns the same type passed in, so the annotations on the T type parameter will work")] + public static NullException ForNonNullValue<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>(T actual) => new NullException( string.Format( CultureInfo.CurrentCulture, diff --git a/src/Microsoft.DotNet.XUnitAssert/src/SetAsserts.cs b/src/Microsoft.DotNet.XUnitAssert/src/SetAsserts.cs index 663a59e8d95..7508279ad0d 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/SetAsserts.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/SetAsserts.cs @@ -6,6 +6,7 @@ #endif using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Xunit.Sdk; #if XUNIT_IMMUTABLE_COLLECTIONS @@ -28,7 +29,7 @@ partial class Assert /// The object expected to be in the set /// The set to be inspected /// Thrown when the object is not present in the set - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, ISet set) { @@ -50,7 +51,12 @@ public static void Contains( /// The object expected to be in the set /// The set to be inspected /// Thrown when the object is not present in the set - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, IReadOnlySet set) { @@ -72,7 +78,7 @@ public static void Contains( /// The object expected to be in the set /// The set to be inspected /// Thrown when the object is not present in the set - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, HashSet set) => Contains(expected, (ISet)set); @@ -98,7 +104,7 @@ public static void Contains( /// The object that is expected not to be in the set /// The set to be inspected /// Thrown when the object is present inside the set - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, ISet set) { @@ -119,7 +125,12 @@ public static void DoesNotContain( /// The object that is expected not to be in the set /// The set to be inspected /// Thrown when the object is present inside the collection - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, IReadOnlySet set) { @@ -140,7 +151,12 @@ public static void DoesNotContain( /// The object expected to be in the set /// The set to be inspected /// Thrown when the object is not present in the set - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( T expected, HashSet set) => DoesNotContain(expected, (ISet)set); @@ -153,7 +169,12 @@ public static void DoesNotContain( /// The object expected to be in the set /// The set to be inspected /// Thrown when the object is not present in the set - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)]T>( T expected, ImmutableHashSet set) => DoesNotContain(expected, (ISet)set); @@ -166,7 +187,12 @@ public static void DoesNotContain( /// The expected subset /// The set expected to be a proper subset /// Thrown when the actual set is not a proper subset of the expected set - public static void ProperSubset( + public static void ProperSubset<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ISet expectedSubset, #if XUNIT_NULLABLE ISet? actual) @@ -190,7 +216,12 @@ public static void ProperSubset( /// The expected superset /// The set expected to be a proper superset /// Thrown when the actual set is not a proper superset of the expected set - public static void ProperSuperset( + public static void ProperSuperset<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ISet expectedSuperset, #if XUNIT_NULLABLE ISet? actual) @@ -214,7 +245,7 @@ public static void ProperSuperset( /// The expected subset /// The set expected to be a subset /// Thrown when the actual set is not a subset of the expected set - public static void Subset( + public static void Subset<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ISet expectedSubset, #if XUNIT_NULLABLE ISet? actual) @@ -238,7 +269,7 @@ public static void Subset( /// The expected superset /// The set expected to be a superset /// Thrown when the actual set is not a superset of the expected set - public static void Superset( + public static void Superset<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ISet expectedSuperset, #if XUNIT_NULLABLE ISet? actual) diff --git a/src/Microsoft.DotNet.XUnitAssert/src/SpanAsserts.cs b/src/Microsoft.DotNet.XUnitAssert/src/SpanAsserts.cs index c299d186d9c..70b776a5d76 100644 --- a/src/Microsoft.DotNet.XUnitAssert/src/SpanAsserts.cs +++ b/src/Microsoft.DotNet.XUnitAssert/src/SpanAsserts.cs @@ -5,6 +5,7 @@ #endif using System; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using Xunit.Sdk; @@ -132,7 +133,12 @@ public static void Contains( /// The sub-span expected to be in the span /// The span to be inspected /// Thrown when the sub-span is not present inside the span - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Span expectedSubSpan, Span actualSpan) where T : IEquatable => @@ -144,7 +150,12 @@ public static void Contains( /// The sub-span expected to be in the span /// The span to be inspected /// Thrown when the sub-span is not present inside the span - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Span expectedSubSpan, ReadOnlySpan actualSpan) where T : IEquatable => @@ -156,7 +167,12 @@ public static void Contains( /// The sub-span expected to be in the span /// The span to be inspected /// Thrown when the sub-span is not present inside the span - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ReadOnlySpan expectedSubSpan, Span actualSpan) where T : IEquatable => @@ -168,7 +184,12 @@ public static void Contains( /// The sub-span expected to be in the span /// The span to be inspected /// Thrown when the sub-span is not present inside the span - public static void Contains( + public static void Contains<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ReadOnlySpan expectedSubSpan, ReadOnlySpan actualSpan) where T : IEquatable @@ -286,7 +307,12 @@ public static void DoesNotContain( /// The sub-span expected not to be in the span /// The span to be inspected /// Thrown when the sub-span is present inside the span - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Span expectedSubSpan, Span actualSpan) where T : IEquatable => @@ -298,7 +324,12 @@ public static void DoesNotContain( /// The sub-span expected not to be in the span /// The span to be inspected /// Thrown when the sub-span is present inside the span - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( Span expectedSubSpan, ReadOnlySpan actualSpan) where T : IEquatable => @@ -310,7 +341,12 @@ public static void DoesNotContain( /// The sub-span expected not to be in the span /// The span to be inspected /// Thrown when the sub-span is present inside the span - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ReadOnlySpan expectedSubSpan, Span actualSpan) where T : IEquatable => @@ -322,7 +358,12 @@ public static void DoesNotContain( /// The sub-span expected not to be in the span /// The span to be inspected /// Thrown when the sub-span is present inside the span - public static void DoesNotContain( + public static void DoesNotContain<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields + | DynamicallyAccessedMemberTypes.NonPublicFields + | DynamicallyAccessedMemberTypes.PublicProperties + | DynamicallyAccessedMemberTypes.NonPublicProperties + | DynamicallyAccessedMemberTypes.PublicMethods)] T>( ReadOnlySpan expectedSubSpan, ReadOnlySpan actualSpan) where T : IEquatable diff --git a/src/Microsoft.DotNet.XUnitConsoleRunner/src/build/Microsoft.DotNet.XUnitConsoleRunner.props b/src/Microsoft.DotNet.XUnitConsoleRunner/src/build/Microsoft.DotNet.XUnitConsoleRunner.props index 09142a05336..0af5cf872d7 100644 --- a/src/Microsoft.DotNet.XUnitConsoleRunner/src/build/Microsoft.DotNet.XUnitConsoleRunner.props +++ b/src/Microsoft.DotNet.XUnitConsoleRunner/src/build/Microsoft.DotNet.XUnitConsoleRunner.props @@ -2,7 +2,7 @@ - $(MSBuildThisFileDirectory)..\tools\net8.0\xunit.console.dll + $(MSBuildThisFileDirectory)..\tools\net9.0\xunit.console.dll diff --git a/src/Microsoft.DotNet.XliffTasks/build/Microsoft.DotNet.XliffTasks.targets b/src/Microsoft.DotNet.XliffTasks/build/Microsoft.DotNet.XliffTasks.targets index 2bce08cd562..6513a424b34 100644 --- a/src/Microsoft.DotNet.XliffTasks/build/Microsoft.DotNet.XliffTasks.targets +++ b/src/Microsoft.DotNet.XliffTasks/build/Microsoft.DotNet.XliffTasks.targets @@ -2,18 +2,19 @@ - $(MSBuildThisFileDirectory)..\tools\net8.0\ + $(MSBuildThisFileDirectory)..\tools\net9.0\ $(MSBuildThisFileDirectory)..\tools\net472\ $(XliffTasksDirectory)Microsoft.DotNet.XliffTasks.dll + AssemblyTaskFactory - - - - - - - + + + + + + + - $(MSBuildThisFileDirectory)../artifacts/bin/Microsoft.DotNet.Helix.Sdk/$(Configuration)/net8.0/publish/Microsoft.DotNet.Helix.Sdk.dll + $(MSBuildThisFileDirectory)../artifacts/bin/Microsoft.DotNet.Helix.Sdk/$(Configuration)/net9.0/publish/Microsoft.DotNet.Helix.Sdk.dll $(MSBuildThisFileDirectory)../artifacts/bin/Microsoft.DotNet.Helix.Sdk/$(Configuration)/net472/publish/Microsoft.DotNet.Helix.Sdk.dll diff --git a/tests/XHarness.Tests.Common.props b/tests/XHarness.Tests.Common.props index 0cb67083c9a..581a8d7fa71 100644 --- a/tests/XHarness.Tests.Common.props +++ b/tests/XHarness.Tests.Common.props @@ -7,7 +7,7 @@ --> - $(MSBuildThisFileDirectory)../artifacts/bin/Microsoft.DotNet.Helix.Sdk/$(Configuration)/net8.0/publish/Microsoft.DotNet.Helix.Sdk.dll + $(MSBuildThisFileDirectory)../artifacts/bin/Microsoft.DotNet.Helix.Sdk/$(Configuration)/net9.0/publish/Microsoft.DotNet.Helix.Sdk.dll $(MSBuildThisFileDirectory)../artifacts/bin/Microsoft.DotNet.Helix.Sdk/$(Configuration)/net472/publish/Microsoft.DotNet.Helix.Sdk.dll