From be1fa5d92e763cb67704ec3b1f1c9daeca247969 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Sat, 12 Jul 2025 19:27:57 +0300 Subject: [PATCH 1/5] Update `Microsoft.CodeAnalysis.Collections` and move reference to `Microsoft.Build`. --- eng/Packages.props | 2 ++ eng/Versions.props | 2 +- src/Build/Microsoft.Build.csproj | 8 ++++++-- src/Framework/Microsoft.Build.Framework.csproj | 9 +++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/eng/Packages.props b/eng/Packages.props index 6817b951611..a5f52eecb45 100644 --- a/eng/Packages.props +++ b/eng/Packages.props @@ -10,6 +10,8 @@ + + diff --git a/eng/Versions.props b/eng/Versions.props index 2631a1cb620..2f3be59bcbe 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -79,7 +79,7 @@ $([System.Text.RegularExpressions.Regex]::Match($([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)..\global.json')), '"dotnet": "([^"]*)"').Groups.get_Item(1)) - 4.2.0-1.22102.8 + 5.0.0-1.25277.114 10.0.0-beta.25353.1 6.15.0-preview.1.86 5.0.0-1.25358.1 diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index 7adeacbb321..ea02876c472 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -38,6 +38,9 @@ + + + @@ -121,9 +124,10 @@ BackEnd\Components\RequestBuilder\IntrinsicTasks\TaskLoggingHelperExtension.cs - + + diff --git a/src/Framework/Microsoft.Build.Framework.csproj b/src/Framework/Microsoft.Build.Framework.csproj index da61a612686..1b35548cb50 100644 --- a/src/Framework/Microsoft.Build.Framework.csproj +++ b/src/Framework/Microsoft.Build.Framework.csproj @@ -1,4 +1,4 @@ - + $(LibraryTargetFrameworks) true @@ -14,10 +14,6 @@ True - - - - @@ -29,8 +25,9 @@ - + + From 50b92df297188a4102671f02705f41bba0cad4df Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Sat, 12 Jul 2025 19:28:50 +0300 Subject: [PATCH 2/5] Use unified polyfill of `IsExternalInit`. --- src/Framework/AssemblyUtilities.cs | 7 ------- src/Framework/Microsoft.Build.Framework.csproj | 5 ++++- src/Shared/IsExternalInit.cs | 13 +++++++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Framework/AssemblyUtilities.cs b/src/Framework/AssemblyUtilities.cs index 5eb6e996a6e..6b21b7d22eb 100644 --- a/src/Framework/AssemblyUtilities.cs +++ b/src/Framework/AssemblyUtilities.cs @@ -10,15 +10,8 @@ using Microsoft.Build.Framework; #endif - -// Declare this to get init properties. See https://github.com/dotnet/roslyn/issues/45510#issuecomment-694977239 #nullable disable -namespace System.Runtime.CompilerServices -{ - internal static class IsExternalInit { } -} - namespace Microsoft.Build.Shared { /// diff --git a/src/Framework/Microsoft.Build.Framework.csproj b/src/Framework/Microsoft.Build.Framework.csproj index 1b35548cb50..07d876a432c 100644 --- a/src/Framework/Microsoft.Build.Framework.csproj +++ b/src/Framework/Microsoft.Build.Framework.csproj @@ -1,4 +1,4 @@ - + $(LibraryTargetFrameworks) true @@ -40,6 +40,9 @@ Shared\Constants.cs + + Shared\IsExternalInit.cs + Shared\BinaryReaderExtensions.cs diff --git a/src/Shared/IsExternalInit.cs b/src/Shared/IsExternalInit.cs index ae2ffb321cd..f0a0588d1df 100644 --- a/src/Shared/IsExternalInit.cs +++ b/src/Shared/IsExternalInit.cs @@ -1,9 +1,22 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if NET +using System.Runtime.CompilerServices; + +// Type-forward to the inbox class where available, in order to maintain binary compatibility +// between the .NET and .NET Standard 2.0 assemblies. +[assembly: TypeForwardedTo(typeof(IsExternalInit))] + +#else + +using System.ComponentModel; + namespace System.Runtime.CompilerServices { // Needed so we can use init setters in full fw or netstandard // (details: https://developercommunity.visualstudio.com/t/error-cs0518-predefined-type-systemruntimecompiler/1244809) + [EditorBrowsable(EditorBrowsableState.Never)] internal static class IsExternalInit { } } +#endif From 67d5aeecaf1d18e80c3c240e1eefa8d35399bf63 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Sat, 12 Jul 2025 20:18:57 +0300 Subject: [PATCH 3/5] Move `Microsoft.CodeAnalysis.Contracts` dependency from `Build` to `Framework` and use it for some polyfills. Fixes duplicate type definition warnings. --- src/Build/Microsoft.Build.csproj | 1 - .../Microsoft.Build.Framework.csproj | 7 +- src/Framework/Polyfills/NullableAttributes.cs | 152 ------------------ 3 files changed, 4 insertions(+), 156 deletions(-) delete mode 100644 src/Framework/Polyfills/NullableAttributes.cs diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index ea02876c472..1ecf75cd874 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -39,7 +39,6 @@ - @@ -40,9 +44,6 @@ Shared\Constants.cs - - Shared\IsExternalInit.cs - Shared\BinaryReaderExtensions.cs diff --git a/src/Framework/Polyfills/NullableAttributes.cs b/src/Framework/Polyfills/NullableAttributes.cs deleted file mode 100644 index b6698fce618..00000000000 --- a/src/Framework/Polyfills/NullableAttributes.cs +++ /dev/null @@ -1,152 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// This was copied from https://github.com/dotnet/runtime/blob/39b9607807f29e48cae4652cd74735182b31182e/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs -// and updated to have the scope of the attributes be internal. - -#nullable disable - -namespace System.Diagnostics.CodeAnalysis -{ -#if !NETCOREAPP - - /// Specifies that null is allowed as an input even if the corresponding type disallows it. - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] - internal sealed class AllowNullAttribute : Attribute { } - - /// Specifies that null is disallowed as an input even if the corresponding type allows it. - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] - internal sealed class DisallowNullAttribute : Attribute { } - - /// Specifies that an output may be null even if the corresponding type disallows it. - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] - internal sealed class MaybeNullAttribute : Attribute { } - - /// Specifies that an output will not be null even if the corresponding type allows it. - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] - internal sealed class NotNullAttribute : Attribute { } - - /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - internal sealed class MaybeNullWhenAttribute : Attribute - { - /// Initializes the attribute with the specified return value condition. - /// - /// The return value condition. If the method returns this value, the associated parameter may be null. - /// - public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - - /// Gets the return value condition. - public bool ReturnValue { get; } - } - - /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - internal sealed class NotNullWhenAttribute : Attribute - { - /// Initializes the attribute with the specified return value condition. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - - /// Gets the return value condition. - public bool ReturnValue { get; } - } - - /// Specifies that the output will be non-null if the named parameter is non-null. - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] - internal sealed class NotNullIfNotNullAttribute : Attribute - { - /// Initializes the attribute with the associated parameter name. - /// - /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. - /// - public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; - - /// Gets the associated parameter name. - public string ParameterName { get; } - } - - /// Applied to a method that will never return under any circumstance. - [AttributeUsage(AttributeTargets.Method, Inherited = false)] - internal sealed class DoesNotReturnAttribute : Attribute { } - - /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - internal sealed class DoesNotReturnIfAttribute : Attribute - { - /// Initializes the attribute with the specified parameter value. - /// - /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to - /// the associated parameter matches this value. - /// - public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; - - /// Gets the condition parameter value. - public bool ParameterValue { get; } - } - -#endif - -#if !NETCOREAPP || NETCOREAPP3_1 - - /// Specifies that the method or property will ensure that the listed field and property members have not-null values. - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] - internal sealed class MemberNotNullAttribute : Attribute - { - /// Initializes the attribute with a field or property member. - /// - /// The field or property member that is promised to be not-null. - /// - public MemberNotNullAttribute(string member) => Members = [member]; - - /// Initializes the attribute with the list of field and property members. - /// - /// The list of field and property members that are promised to be not-null. - /// - public MemberNotNullAttribute(params string[] members) => Members = members; - - /// Gets field or property member names. - public string[] Members { get; } - } - - /// Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition. - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] - internal sealed class MemberNotNullWhenAttribute : Attribute - { - /// Initializes the attribute with the specified return value condition and a field or property member. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - /// - /// The field or property member that is promised to be not-null. - /// - public MemberNotNullWhenAttribute(bool returnValue, string member) - { - ReturnValue = returnValue; - Members = [member]; - } - - /// Initializes the attribute with the specified return value condition and list of field and property members. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - /// - /// The list of field and property members that are promised to be not-null. - /// - public MemberNotNullWhenAttribute(bool returnValue, params string[] members) - { - ReturnValue = returnValue; - Members = members; - } - - /// Gets the return value condition. - public bool ReturnValue { get; } - - /// Gets field or property member names. - public string[] Members { get; } - } - -#endif -} From c9d67e5ad9eb3edba3e2dcf81331a6e50e7e4dc1 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Sat, 12 Jul 2025 20:46:19 +0300 Subject: [PATCH 4/5] Remove commented out code. --- src/Build/Microsoft.Build.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index 1ecf75cd874..c7e881aebab 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -123,10 +123,6 @@ BackEnd\Components\RequestBuilder\IntrinsicTasks\TaskLoggingHelperExtension.cs - - From 3d847d04316903d0d93e0022258980788b2895c5 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Sat, 12 Jul 2025 21:24:30 +0300 Subject: [PATCH 5/5] Fix compile errors in `MSBuildTaskHost`. --- src/MSBuildTaskHost/MSBuildTaskHost.csproj | 2 + src/MSBuildTaskHost/NullableAttributes.cs | 154 +++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 src/MSBuildTaskHost/NullableAttributes.cs diff --git a/src/MSBuildTaskHost/MSBuildTaskHost.csproj b/src/MSBuildTaskHost/MSBuildTaskHost.csproj index 5f812c4b7a6..7bf7d85aa04 100644 --- a/src/MSBuildTaskHost/MSBuildTaskHost.csproj +++ b/src/MSBuildTaskHost/MSBuildTaskHost.csproj @@ -70,6 +70,7 @@ CopyOnWriteDictionary.cs + @@ -202,6 +203,7 @@ + diff --git a/src/MSBuildTaskHost/NullableAttributes.cs b/src/MSBuildTaskHost/NullableAttributes.cs new file mode 100644 index 00000000000..2c086ba5622 --- /dev/null +++ b/src/MSBuildTaskHost/NullableAttributes.cs @@ -0,0 +1,154 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// This was copied from https://github.com/dotnet/runtime/blob/39b9607807f29e48cae4652cd74735182b31182e/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs +// and updated to have the scope of the attributes be internal. +// This file is used only by MSBuildTaskHost; other projects should get the polyfills from the +// Microsoft.CodeAnalysis.Contracts package, through the Microsoft.Build.Framework project. + +#nullable disable + +namespace System.Diagnostics.CodeAnalysis +{ +#if !NETCOREAPP + + /// Specifies that null is allowed as an input even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] + internal sealed class AllowNullAttribute : Attribute { } + + /// Specifies that null is disallowed as an input even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] + internal sealed class DisallowNullAttribute : Attribute { } + + /// Specifies that an output may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] + internal sealed class MaybeNullAttribute : Attribute { } + + /// Specifies that an output will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] + internal sealed class NotNullAttribute : Attribute { } + + /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class MaybeNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter may be null. + /// + public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class NotNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter will not be null. + /// + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that the output will be non-null if the named parameter is non-null. + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] + internal sealed class NotNullIfNotNullAttribute : Attribute + { + /// Initializes the attribute with the associated parameter name. + /// + /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. + /// + public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; + + /// Gets the associated parameter name. + public string ParameterName { get; } + } + + /// Applied to a method that will never return under any circumstance. + [AttributeUsage(AttributeTargets.Method, Inherited = false)] + internal sealed class DoesNotReturnAttribute : Attribute { } + + /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] + internal sealed class DoesNotReturnIfAttribute : Attribute + { + /// Initializes the attribute with the specified parameter value. + /// + /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to + /// the associated parameter matches this value. + /// + public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; + + /// Gets the condition parameter value. + public bool ParameterValue { get; } + } + +#endif + +#if !NETCOREAPP || NETCOREAPP3_1 + + /// Specifies that the method or property will ensure that the listed field and property members have not-null values. + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] + internal sealed class MemberNotNullAttribute : Attribute + { + /// Initializes the attribute with a field or property member. + /// + /// The field or property member that is promised to be not-null. + /// + public MemberNotNullAttribute(string member) => Members = [member]; + + /// Initializes the attribute with the list of field and property members. + /// + /// The list of field and property members that are promised to be not-null. + /// + public MemberNotNullAttribute(params string[] members) => Members = members; + + /// Gets field or property member names. + public string[] Members { get; } + } + + /// Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition. + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] + internal sealed class MemberNotNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition and a field or property member. + /// + /// The return value condition. If the method returns this value, the associated parameter will not be null. + /// + /// + /// The field or property member that is promised to be not-null. + /// + public MemberNotNullWhenAttribute(bool returnValue, string member) + { + ReturnValue = returnValue; + Members = [member]; + } + + /// Initializes the attribute with the specified return value condition and list of field and property members. + /// + /// The return value condition. If the method returns this value, the associated parameter will not be null. + /// + /// + /// The list of field and property members that are promised to be not-null. + /// + public MemberNotNullWhenAttribute(bool returnValue, params string[] members) + { + ReturnValue = returnValue; + Members = members; + } + + /// Gets the return value condition. + public bool ReturnValue { get; } + + /// Gets field or property member names. + public string[] Members { get; } + } + +#endif +}