From cc3db358d34ad4cd1ec0c67e17582d7ca2a15040 Mon Sep 17 00:00:00 2001 From: Ben Villalobos <4691428+BenVillalobos@users.noreply.github.com> Date: Mon, 19 Sep 2022 11:22:56 -0700 Subject: [PATCH] Target net7.0 (#7790) Update target framework in MSBuild and related places (consolidating MSBuild references). Add NoWarn for deprecation warnings (#7902) and API-stability analyzer problems (#7903). Fix a issues around crypto API simplifications on .NET Core spotted by new analzyers. Co-authored-by: Rainer Sigwald --- Directory.Build.props | 16 ++++++++++++- eng/BootStrapMSBuild.targets | 2 +- eng/cibuild_bootstrapped_msbuild.ps1 | 2 +- eng/cibuild_bootstrapped_msbuild.sh | 2 +- global.json | 2 +- scripts/Deploy-MSBuild.ps1 | 2 +- .../CollectionsHelpers.cs | 20 ++++++++-------- .../Microsoft.Build.Engine.UnitTests.csproj | 4 ++-- src/Build/Definition/ToolsetReader.cs | 4 ++-- src/Build/Microsoft.Build.csproj | 2 +- src/Directory.BeforeCommon.targets | 3 ++- src/Directory.Build.props | 6 ++--- src/Framework/README.md | 2 +- .../MSBuild.Bootstrap.csproj | 2 +- src/Package/Localization/Localization.csproj | 2 +- .../ProjectCachePlugin.csproj | 4 ++-- .../BootstrapperUtil/BootstrapperBuilder.cs | 6 ++++- src/Tasks/ManifestUtil/Util.cs | 12 ++++++++-- src/Tasks/ManifestUtil/mansign2.cs | 24 +++++++++++++++---- src/Utilities/README.md | 2 +- 20 files changed, 81 insertions(+), 38 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 0df28a5b8b2..21b6d6694f2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,6 +14,18 @@ net472 + + + net7.0 @@ -36,9 +48,11 @@ CS1701 and CS1702 are by default ignored by Microsoft.NET.Sdk, but if you define the NoWarn property in Directory.Build.props, you don't get those defaults. SYSLIB0011: Removing binary formatter will happen as part of a larger .NET-wide effort. + SYSLIB0037 & SYSLIB0044: The deprecated AssemblyName members could require a bigger refactor for us: https://github.com/dotnet/msbuild/issues/7902 + RS0016 & RS0017: Roslyn analyzers seem to be bugged, claiming that API's that exist don't and vise-versa: https://github.com/dotnet/msbuild/issues/7903 --> - $(NoWarn);NU1603;NU5105;1701;1702;SYSLIB0011 + $(NoWarn);NU1603;NU5105;1701;1702;SYSLIB0011;SYSLIB0037;SYSLIB0044;RS0016;RS0017; diff --git a/eng/BootStrapMSBuild.targets b/eng/BootStrapMSBuild.targets index 288c062da35..7b23330685f 100644 --- a/eng/BootStrapMSBuild.targets +++ b/eng/BootStrapMSBuild.targets @@ -210,7 +210,7 @@ Copy it from "next to MSBuild" in the pre-bootstrap SDK to our little weirdo bootstrap layout next to the SDK tasks, so it can get loaded by the SDK tasks that need it. --> + DestinationFolder="$(BootstrapDestination)Sdks\Microsoft.NET.Sdk\tools\$(LatestDotNetCoreForMSBuild)" /> diff --git a/eng/cibuild_bootstrapped_msbuild.ps1 b/eng/cibuild_bootstrapped_msbuild.ps1 index b9c1cf4fe0c..906a33dc12f 100644 --- a/eng/cibuild_bootstrapped_msbuild.ps1 +++ b/eng/cibuild_bootstrapped_msbuild.ps1 @@ -91,7 +91,7 @@ try { else { $buildToolPath = $dotnetExePath - $buildToolCommand = Join-Path $bootstrapRoot "net6.0\MSBuild\MSBuild.dll" + $buildToolCommand = Join-Path $bootstrapRoot "net7.0\MSBuild\MSBuild.dll" $buildToolFramework = "netcoreapp3.1" } diff --git a/eng/cibuild_bootstrapped_msbuild.sh b/eng/cibuild_bootstrapped_msbuild.sh index e5425507f47..b4404b7e4ad 100755 --- a/eng/cibuild_bootstrapped_msbuild.sh +++ b/eng/cibuild_bootstrapped_msbuild.sh @@ -63,7 +63,7 @@ bootstrapRoot="$Stage1Dir/bin/bootstrap" if [ $host_type = "core" ] then _InitializeBuildTool="$_InitializeDotNetCli/dotnet" - _InitializeBuildToolCommand="$bootstrapRoot/net6.0/MSBuild/MSBuild.dll" + _InitializeBuildToolCommand="$bootstrapRoot/net7.0/MSBuild/MSBuild.dll" _InitializeBuildToolFramework="netcoreapp3.1" elif [ $host_type = "mono" ] then diff --git a/global.json b/global.json index 6758761a211..2b4212cde00 100644 --- a/global.json +++ b/global.json @@ -3,7 +3,7 @@ "allowPrerelease": true }, "tools": { - "dotnet": "6.0.401", + "dotnet": "7.0.100-rc.1.22431.12", "vs": { "version": "17.2.1" }, diff --git a/scripts/Deploy-MSBuild.ps1 b/scripts/Deploy-MSBuild.ps1 index f6044dd6940..d7a084641b2 100644 --- a/scripts/Deploy-MSBuild.ps1 +++ b/scripts/Deploy-MSBuild.ps1 @@ -69,7 +69,7 @@ else { if ($runtime -eq "Desktop") { $targetFramework = "net472" } else { - $targetFramework = "net6.0" + $targetFramework = "net7.0" } $bootstrapBinDirectory = "artifacts\bin\MSBuild.Bootstrap\$configuration\$targetFramework" diff --git a/src/Build.OM.UnitTests/ObjectModelRemoting/RemoteProjectsProviderMock/CollectionsHelpers.cs b/src/Build.OM.UnitTests/ObjectModelRemoting/RemoteProjectsProviderMock/CollectionsHelpers.cs index b6d935f41a7..ea551d51ac1 100644 --- a/src/Build.OM.UnitTests/ObjectModelRemoting/RemoteProjectsProviderMock/CollectionsHelpers.cs +++ b/src/Build.OM.UnitTests/ObjectModelRemoting/RemoteProjectsProviderMock/CollectionsHelpers.cs @@ -85,32 +85,32 @@ public static IList ExportCollection(this ProjectCollectionLink } - public static IDictionary ImportDictionary(this ProjectCollectionLinker importer, IDictionary source) - where T : class - where RMock : MockLinkRemoter, new() + public static IDictionary ImportDictionary(this ProjectCollectionLinker importer, IDictionary source) + where TValue : class + where RMock : MockLinkRemoter, new() { if (source == null) return null; // Just copy ... - Dictionary result = new Dictionary(); + Dictionary result = new Dictionary(); foreach (var sRemoter in source) { - var value = importer.Import(sRemoter.Value); + var value = importer.Import(sRemoter.Value); result.Add(sRemoter.Key, value); } return result; } - public static IDictionary ExportDictionary(this ProjectCollectionLinker exporter, IDictionary source) - where T : class - where RMock : MockLinkRemoter, new() + public static IDictionary ExportDictionary(this ProjectCollectionLinker exporter, IDictionary source) + where TValue : class + where RMock : MockLinkRemoter, new() { if (source == null) return null; // Just copy ... - Dictionary result = new Dictionary(); + Dictionary result = new Dictionary(); foreach (var s in source) { - var valueRemoter = exporter.Export(s.Value); + var valueRemoter = exporter.Export(s.Value); result.Add(s.Key, valueRemoter); } diff --git a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj index 8ddca6108ac..d017ffbe1cc 100644 --- a/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj +++ b/src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj @@ -36,14 +36,14 @@ TargetFramework=$(FullFrameworkTFM) TargetFramework=$(FullFrameworkTFM) - TargetFramework=net6.0 + TargetFramework=$(LatestDotNetCoreForMSBuild) TargetFramework=$(FullFrameworkTFM) TargetFramework=$(FullFrameworkTFM) - TargetFramework=net6.0 + TargetFramework=$(LatestDotNetCoreForMSBuild) diff --git a/src/Build/Definition/ToolsetReader.cs b/src/Build/Definition/ToolsetReader.cs index 8887b9cca2b..ddb164cb778 100644 --- a/src/Build/Definition/ToolsetReader.cs +++ b/src/Build/Definition/ToolsetReader.cs @@ -12,7 +12,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Internal; using Microsoft.Build.Shared.FileSystem; -using error = Microsoft.Build.Shared.ErrorUtilities; +using ErrorUtils = Microsoft.Build.Shared.ErrorUtilities; using InvalidProjectFileException = Microsoft.Build.Exceptions.InvalidProjectFileException; using InvalidToolsetDefinitionException = Microsoft.Build.Exceptions.InvalidToolsetDefinitionException; using ReservedPropertyNames = Microsoft.Build.Internal.ReservedPropertyNames; @@ -366,7 +366,7 @@ internal string ReadToolsets out string defaultOverrideToolsVersion ) { - error.VerifyThrowArgumentNull(toolsets, "Toolsets"); + ErrorUtils.VerifyThrowArgumentNull(toolsets, "Toolsets"); ReadEachToolset(toolsets, globalProperties, initialProperties, accumulateProperties); diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index cb7786b3008..7ec2ec46738 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -4,7 +4,7 @@ - $(FullFrameworkTFM);net6.0 + $(FullFrameworkTFM);$(LatestDotNetCoreForMSBuild) $(RuntimeOutputTargetFrameworks) Microsoft.Build Microsoft.Build diff --git a/src/Directory.BeforeCommon.targets b/src/Directory.BeforeCommon.targets index 1aac46b4e69..d136a2607c9 100644 --- a/src/Directory.BeforeCommon.targets +++ b/src/Directory.BeforeCommon.targets @@ -25,6 +25,7 @@ $(DefineConstants);FEATURE_COMPILE_IN_TESTS $(DefineConstants);FEATURE_CONSTRAINED_EXECUTION $(DefineConstants);FEATURE_CODETASKFACTORY + $(DefineConstants);FEATURE_CRYPTOGRAPHIC_FACTORY_ALGORITHM_NAMES $(DefineConstants);FEATURE_CULTUREINFO_GETCULTURES $(DefineConstants);FEATURE_ENCODING_DEFAULT $(DefineConstants);FEATURE_ENVIRONMENT_SYSTEMDIRECTORY @@ -93,7 +94,7 @@ $(DefineConstants);FEATURE_SYMLINK_TARGET - + $(DefineConstants);FEATURE_PIPEOPTIONS_CURRENTUSERONLY $(DefineConstants);FEATURE_NODE_REUSE diff --git a/src/Directory.Build.props b/src/Directory.Build.props index ccffd9b5c05..ee0ec04823f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -30,13 +30,13 @@ AnyCPU;x64;arm64 - $(FullFrameworkTFM);net6.0;netstandard2.0 - net6.0;netstandard2.0 + $(FullFrameworkTFM);$(LatestDotNetCoreForMSBuild);netstandard2.0 + $(LatestDotNetCoreForMSBuild);netstandard2.0 $(FullFrameworkTFM);netstandard2.0 AnyCPU - net6.0 + net7.0 $(FullFrameworkTFM);$(RuntimeOutputTargetFrameworks) $(FullFrameworkTFM) diff --git a/src/Framework/README.md b/src/Framework/README.md index 1b72454f526..8a86bc21cc5 100644 --- a/src/Framework/README.md +++ b/src/Framework/README.md @@ -6,6 +6,6 @@ The items in this namespace are primarily base-level classes and interfaces shar [`ITask`](https://docs.microsoft.com/dotnet/api/microsoft.build.framework.itask), and [`ILogger`](https://docs.microsoft.com/dotnet/api/microsoft.build.framework.ilogger). ### netstandard2.0 target -The `netstandard2.0` target of this build is configured only to output reference assemblies; at runtime MSBuild will be `net6.0` or `net472`. Please use the `net6.0`-targeted assemblies for .NET Core 6+ scenarios. +The `netstandard2.0` target of this build is configured only to output reference assemblies; at runtime MSBuild will be `net7.0` or `net472`. Please use the `net7.0`-targeted assemblies for .NET Core 6+ scenarios. For context, see https://github.com/dotnet/msbuild/pull/6148 \ No newline at end of file diff --git a/src/MSBuild.Bootstrap/MSBuild.Bootstrap.csproj b/src/MSBuild.Bootstrap/MSBuild.Bootstrap.csproj index 9bb2da04989..bdd2f2e19c5 100644 --- a/src/MSBuild.Bootstrap/MSBuild.Bootstrap.csproj +++ b/src/MSBuild.Bootstrap/MSBuild.Bootstrap.csproj @@ -43,7 +43,7 @@ - + diff --git a/src/Package/Localization/Localization.csproj b/src/Package/Localization/Localization.csproj index e15af6ed02a..e1ecca1aab4 100644 --- a/src/Package/Localization/Localization.csproj +++ b/src/Package/Localization/Localization.csproj @@ -1,6 +1,6 @@  - net6.0 + $(LatestDotNetCoreForMSBuild) net472 Microsoft.Build.Localization.nuspec false diff --git a/src/Samples/ProjectCachePlugin/ProjectCachePlugin.csproj b/src/Samples/ProjectCachePlugin/ProjectCachePlugin.csproj index 6972b5e9ab0..3c6a05caadc 100644 --- a/src/Samples/ProjectCachePlugin/ProjectCachePlugin.csproj +++ b/src/Samples/ProjectCachePlugin/ProjectCachePlugin.csproj @@ -4,8 +4,8 @@ false false - net6.0 - $(FullFrameworkTFM);net6.0 + $(LatestDotNetCoreForMSBuild) + $(FullFrameworkTFM);$(LatestDotNetCoreForMSBuild) $(RuntimeOutputTargetFrameworks) diff --git a/src/Tasks/BootstrapperUtil/BootstrapperBuilder.cs b/src/Tasks/BootstrapperUtil/BootstrapperBuilder.cs index b8960252b8a..ce5faa9fb28 100644 --- a/src/Tasks/BootstrapperUtil/BootstrapperBuilder.cs +++ b/src/Tasks/BootstrapperUtil/BootstrapperBuilder.cs @@ -1645,7 +1645,11 @@ private static string GetFileHash(string filePath) // the .NET Framework we are targeting. In ideal situations, bootstrapper files will be // pre-signed anwyay; this is a fallback in case we ever encounter a bootstrapper that is // not signed. - System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create("System.Security.Cryptography.SHA256CryptoServiceProvider"); + System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create( +#if FEATURE_CRYPTOGRAPHIC_FACTORY_ALGORITHM_NAMES + "System.Security.Cryptography.SHA256CryptoServiceProvider" +#endif + ); using (Stream s = fi.OpenRead()) { diff --git a/src/Tasks/ManifestUtil/Util.cs b/src/Tasks/ManifestUtil/Util.cs index 56ba265c495..85434a45d44 100644 --- a/src/Tasks/ManifestUtil/Util.cs +++ b/src/Tasks/ManifestUtil/Util.cs @@ -227,11 +227,19 @@ private static void GetFileInfoImpl(string path, string targetFrameWorkVersion, if (string.IsNullOrEmpty(targetFrameWorkVersion) || CompareFrameworkVersions(targetFrameWorkVersion, Constants.TargetFrameworkVersion40) <= 0) { - hashAlg = SHA1.Create("System.Security.Cryptography.SHA1CryptoServiceProvider"); + hashAlg = SHA1.Create( +#if FEATURE_CRYPTOGRAPHIC_FACTORY_ALGORITHM_NAMES + "System.Security.Cryptography.SHA1CryptoServiceProvider" +#endif + ); } else { - hashAlg = SHA256.Create("System.Security.Cryptography.SHA256CryptoServiceProvider"); + hashAlg = SHA256.Create( +#if FEATURE_CRYPTOGRAPHIC_FACTORY_ALGORITHM_NAMES + "System.Security.Cryptography.SHA256CryptoServiceProvider" +#endif + ); } byte[] hashBytes = hashAlg.ComputeHash(s); hash = Convert.ToBase64String(hashBytes); diff --git a/src/Tasks/ManifestUtil/mansign2.cs b/src/Tasks/ManifestUtil/mansign2.cs index a5404f5b920..9c29d1cbb1d 100644 --- a/src/Tasks/ManifestUtil/mansign2.cs +++ b/src/Tasks/ManifestUtil/mansign2.cs @@ -555,7 +555,11 @@ private static byte[] ComputeHashFromManifest(XmlDocument manifestDom, bool oldF if (useSha256) { - using (SHA256 sha2 = SHA256.Create("System.Security.Cryptography.SHA256CryptoServiceProvider")) + using (SHA256 sha2 = SHA256.Create( +#if FEATURE_CRYPTOGRAPHIC_FACTORY_ALGORITHM_NAMES + "System.Security.Cryptography.SHA256CryptoServiceProvider" +#endif + )) { byte[] hash = sha2.ComputeHash(exc.GetOutput() as MemoryStream); if (hash == null) @@ -568,7 +572,11 @@ private static byte[] ComputeHashFromManifest(XmlDocument manifestDom, bool oldF } else { - using (SHA1 sha1 = SHA1.Create("System.Security.Cryptography.SHA1CryptoServiceProvider")) + using (SHA1 sha1 = SHA1.Create( +#if FEATURE_CRYPTOGRAPHIC_FACTORY_ALGORITHM_NAMES + "System.Security.Cryptography.SHA1CryptoServiceProvider" +#endif + )) { byte[] hash = sha1.ComputeHash(exc.GetOutput() as MemoryStream); if (hash == null) @@ -603,7 +611,11 @@ private static byte[] ComputeHashFromManifest(XmlDocument manifestDom, bool oldF if (useSha256) { - using (SHA256 sha2 = SHA256.Create("System.Security.Cryptography.SHA256CryptoServiceProvider")) + using (SHA256 sha2 = SHA256.Create( +#if FEATURE_CRYPTOGRAPHIC_FACTORY_ALGORITHM_NAMES + "System.Security.Cryptography.SHA256CryptoServiceProvider" +#endif + )) { byte[] hash = sha2.ComputeHash(exc.GetOutput() as MemoryStream); if (hash == null) @@ -616,7 +628,11 @@ private static byte[] ComputeHashFromManifest(XmlDocument manifestDom, bool oldF } else { - using (SHA1 sha1 = SHA1.Create("System.Security.Cryptography.SHA1CryptoServiceProvider")) + using (SHA1 sha1 = SHA1.Create( +#if FEATURE_CRYPTOGRAPHIC_FACTORY_ALGORITHM_NAMES + "System.Security.Cryptography.SHA1CryptoServiceProvider" +#endif + )) { byte[] hash = sha1.ComputeHash(exc.GetOutput() as MemoryStream); if (hash == null) diff --git a/src/Utilities/README.md b/src/Utilities/README.md index a85d56e11cc..99a1651b52c 100644 --- a/src/Utilities/README.md +++ b/src/Utilities/README.md @@ -7,6 +7,6 @@ This package contains `Microsoft.Build.Utilities.Core.dll`, which defines helper * [`Logger`](https://docs.microsoft.com/dotnet/api/microsoft.build.utilities.logger), a base class for custom logging functionality. ### netstandard2.0 target -The `netstandard2.0` target of this build is configured only to output reference assemblies; at runtime MSBuild will be `net6.0` or `net472`. Please use the `net6.0`-targeted assemblies for .NET Core 6+ scenarios. +The `netstandard2.0` target of this build is configured only to output reference assemblies; at runtime MSBuild will be `net7.0` or `net472`. Please use the `net7.0`-targeted assemblies for .NET Core 6+ scenarios. For context, see https://github.com/dotnet/msbuild/pull/6148 \ No newline at end of file