From e0a377b5ebcd6b7509355ae0b72de4f1a71007cd Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Tue, 22 Aug 2023 15:51:11 -0400 Subject: [PATCH 1/7] stub tasks not supported on .NET Core to provide a clear error message --- src/Tasks/Al.cs | 134 +++++++++++++++++- src/Tasks/AspNetCompiler.cs | 72 +++++++++- src/Tasks/GenerateBootstrapper.cs | 86 ++++++++++- src/Tasks/GenerateTrustInfo.cs | 54 ++++++- src/Tasks/GetFrameworkSDKPath.cs | 67 ++++++++- src/Tasks/Microsoft.Build.Tasks.csproj | 62 ++++---- src/Tasks/Microsoft.Common.tasks | 2 + src/Tasks/RegisterAssembly.cs | 50 ++++++- src/Tasks/ResolveComReference.cs | 21 +-- src/Tasks/ResolveNativeReference.cs | 68 ++++++++- src/Tasks/TaskRequiresFramework.cs | 30 ++++ src/Tasks/UnregisterAssembly.cs | 44 +++++- src/Tasks/UpdateManifest.cs | 51 ++++++- src/Tasks/WinMDExp.cs | 77 +++++++++- .../Microsoft.Build.Utilities.csproj | 6 +- 15 files changed, 755 insertions(+), 69 deletions(-) create mode 100644 src/Tasks/TaskRequiresFramework.cs diff --git a/src/Tasks/Al.cs b/src/Tasks/Al.cs index 7d9ad8fa1a8..2ccbe827456 100644 --- a/src/Tasks/Al.cs +++ b/src/Tasks/Al.cs @@ -1,21 +1,26 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if NETFRAMEWORK using System; -using Microsoft.Build.Framework; using Microsoft.Build.Shared.FileSystem; using Microsoft.Build.Utilities; +#endif + +using Microsoft.Build.Framework; #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + /// /// This class defines the "AL" XMake task, which enables using al.exe to link /// modules and resource files into assemblies. /// - public class AL : ToolTaskExtension + public class AL : ToolTaskExtension, IALTaskContract { #region Properties /* @@ -387,6 +392,131 @@ public override bool Execute() return base.Execute(); } + #endregion + } + +#else + + /// + /// Stub AL task for .NET Core + /// + public class AL : TaskRequiresFramework, IALTaskContract + { + public AL() + : base(nameof(AL)) + { + } + + #region Properties + + public string AlgorithmId { get; set; } + + public string BaseAddress { get; set; } + + public string CompanyName { get; set; } + + public string Configuration { get; set; } + + public string Copyright { get; set; } + + public string Culture { get; set; } + + public bool DelaySign { get; set; } + + public string Description { get; set; } + + public string EvidenceFile { get; set; } + + public string FileVersion { get; set; } + + public string Flags { get; set; } + + public bool GenerateFullPaths { get; set; } + + public string KeyFile { get; set; } + + public string KeyContainer { get; set; } + + public string MainEntryPoint { get; set; } + + [Output] + [Required] + public ITaskItem OutputAssembly { get; set; } + + public string Platform { get; set; } + + public bool Prefer32Bit { get; set; } + + public string ProductName { get; set; } + + public string ProductVersion { get; set; } + + public string[] ResponseFiles { get; set; } + + public string TargetType { get; set; } + + public string TemplateFile { get; set; } + + public string Title { get; set; } + + public string Trademark { get; set; } + + public string Version { get; set; } + + public string Win32Icon { get; set; } + + public string Win32Resource { get; set; } + + public ITaskItem[] SourceModules { get; set; } + + public ITaskItem[] EmbedResources { get; set; } + + public ITaskItem[] LinkResources { get; set; } + + public string SdkToolsPath { get; set; } + + #endregion + } + +#endif + + internal interface IALTaskContract + { + #region Properties + + string AlgorithmId { get; set; } + string BaseAddress { get; set; } + string CompanyName { get; set; } + string Configuration { get; set; } + string Copyright { get; set; } + string Culture { get; set; } + bool DelaySign { get; set; } + string Description { get; set; } + string EvidenceFile { get; set; } + string FileVersion { get; set; } + string Flags { get; set; } + bool GenerateFullPaths { get; set; } + string KeyFile { get; set; } + string KeyContainer { get; set; } + string MainEntryPoint { get; set; } + ITaskItem OutputAssembly { get; set; } + string Platform { get; set; } + bool Prefer32Bit { get; set; } + string ProductName { get; set; } + string ProductVersion { get; set; } + string[] ResponseFiles { get; set; } + string TargetType { get; set; } + string TemplateFile { get; set; } + string Title { get; set; } + string Trademark { get; set; } + string Version { get; set; } + string Win32Icon { get; set; } + string Win32Resource { get; set; } + ITaskItem[] SourceModules { get; set; } + ITaskItem[] EmbedResources { get; set; } + ITaskItem[] LinkResources { get; set; } + string SdkToolsPath { get; set; } + #endregion } } diff --git a/src/Tasks/AspNetCompiler.cs b/src/Tasks/AspNetCompiler.cs index 1e1d3b4b2be..7c313f09dcb 100644 --- a/src/Tasks/AspNetCompiler.cs +++ b/src/Tasks/AspNetCompiler.cs @@ -1,16 +1,20 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if NETFRAMEWORK using Microsoft.Build.Utilities; +#endif #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + /// /// The AspNetCompiler task, which is a wrapper around aspnet_compiler.exe /// - public class AspNetCompiler : ToolTaskExtension + public class AspNetCompiler : ToolTaskExtension, IAspNetCompilerTaskContract { /* C:\WINDOWS\Microsoft.NET\Framework\v2.0.x86dbg>aspnet_compiler /? @@ -338,4 +342,70 @@ protected override bool ValidateParameters() return true; } } + +#else + + public class AspNetCompiler : TaskRequiresFramework, IAspNetCompilerTaskContract + { + public AspNetCompiler() + : base(nameof(AspNetCompiler)) + { + } + + #region Properties + + public bool AllowPartiallyTrustedCallers { get; set; } + + public bool DelaySign { get; set; } + + public bool FixedNames { get; set; } + + public string KeyContainer { get; set; } + + public string KeyFile { get; set; } + + public string MetabasePath { get; set; } + + public string PhysicalPath { get; set; } + + public string TargetPath { get; set; } + + public string VirtualPath { get; set; } + + public bool Updateable { get; set; } + + public bool Force { get; set; } + + public bool Debug { get; set; } + + public bool Clean { get; set; } + + public string TargetFrameworkMoniker { get; set; } + + #endregion + } + +#endif + + internal interface IAspNetCompilerTaskContract + { + #region Properties + + bool AllowPartiallyTrustedCallers { get; set; } + bool DelaySign { get; set; } + bool FixedNames { get; set; } + string KeyContainer { get; set; } + string KeyFile { get; set; } + string MetabasePath { get; set; } + string PhysicalPath { get; set; } + string TargetPath { get; set; } + string VirtualPath { get; set; } + bool Updateable { get; set; } + bool Force { get; set; } + bool Debug { get; set; } + bool Clean { get; set; } + string TargetFrameworkMoniker { get; set; } + + #endregion + } } diff --git a/src/Tasks/GenerateBootstrapper.cs b/src/Tasks/GenerateBootstrapper.cs index 7eb63e1e8e0..241ca0a4610 100644 --- a/src/Tasks/GenerateBootstrapper.cs +++ b/src/Tasks/GenerateBootstrapper.cs @@ -1,20 +1,25 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if NETFRAMEWORK using System; using System.Collections.Generic; using System.IO; -using Microsoft.Build.Framework; using Microsoft.Build.Tasks.Deployment.Bootstrapper; +#endif + +using Microsoft.Build.Framework; #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + /// /// Generates a bootstrapper for ClickOnce deployment projects. /// - public sealed class GenerateBootstrapper : TaskExtension + public sealed class GenerateBootstrapper : TaskExtension, IGenerateBootstrapperTaskContract { public string ApplicationName { get; set; } @@ -174,4 +179,81 @@ private ComponentsLocation ConvertStringToComponentsLocation(string parameterVal } } } + +#else + + public sealed class GenerateBootstrapper : TaskRequiresFramework, IGenerateBootstrapperTaskContract + { + public GenerateBootstrapper() + : base(nameof(GenerateBootstrapper)) + { + } + + #region Properties + + public string ApplicationName { get; set; } + + public string ApplicationFile { get; set; } + + public bool ApplicationRequiresElevation { get; set; } + + public string ApplicationUrl { get; set; } + + public ITaskItem[] BootstrapperItems { get; set; } + + public string ComponentsLocation { get; set; } + + public string ComponentsUrl { get; set; } + + public bool CopyComponents { get; set; } + + public string Culture { get; set; } + + public string FallbackCulture { get; set; } + + public string OutputPath { get; set; } + + public string Path { get; set; } + + public string SupportUrl { get; set; } + + public string VisualStudioVersion { get; set; } + + public bool Validate { get; set; } + + [Output] + public string BootstrapperKeyFile { get; set; } + + [Output] + public string[] BootstrapperComponentFiles { get; set; } + + #endregion + } + +#endif + + internal interface IGenerateBootstrapperTaskContract + { + #region Properties + + string ApplicationName { get; set; } + string ApplicationFile { get; set; } + bool ApplicationRequiresElevation { get; set; } + string ApplicationUrl { get; set; } + ITaskItem[] BootstrapperItems { get; set; } + string ComponentsLocation { get; set; } + string ComponentsUrl { get; set; } + bool CopyComponents { get; set; } + string Culture { get; set; } + string FallbackCulture { get; set; } + string OutputPath { get; set; } + string Path { get; set; } + string SupportUrl { get; set; } + string VisualStudioVersion { get; set; } + bool Validate { get; set; } + string BootstrapperKeyFile { get; set; } + string[] BootstrapperComponentFiles { get; set; } + + #endregion + } } diff --git a/src/Tasks/GenerateTrustInfo.cs b/src/Tasks/GenerateTrustInfo.cs index e6a6a1d43cc..fa369fd26b7 100644 --- a/src/Tasks/GenerateTrustInfo.cs +++ b/src/Tasks/GenerateTrustInfo.cs @@ -1,21 +1,27 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if NETFRAMEWORK using System; -using Microsoft.Build.Framework; + using Microsoft.Build.Shared.FileSystem; using Microsoft.Build.Tasks.Deployment.ManifestUtilities; using FrameworkNameVersioning = System.Runtime.Versioning.FrameworkName; +#endif + +using Microsoft.Build.Framework; #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + /// /// This task generates the application trust from the base manifest /// and the TargetZone and ExcludedPermissions properties. /// - public sealed class GenerateTrustInfo : TaskExtension + public sealed class GenerateTrustInfo : TaskExtension, IGenerateTrustInfoTaskContract { private const string Custom = "Custom"; @@ -98,4 +104,48 @@ public override bool Execute() return true; } } + +#else + + public sealed class GenerateTrustInfo : TaskRequiresFramework, IGenerateTrustInfoTaskContract + { + public GenerateTrustInfo() + : base(nameof(GenerateTrustInfo)) + { + } + + #region Properties + + public ITaskItem BaseManifest { get; set; } + + public string ExcludedPermissions { get; set; } + + public string TargetFrameworkMoniker { get; set; } + + public string TargetZone { get; set; } + + public ITaskItem[] ApplicationDependencies { get; set; } + + [Output] + [Required] + public ITaskItem TrustInfoFile { get; set; } + + #endregion + } + +#endif + + internal interface IGenerateTrustInfoTaskContract + { + #region Properties + + ITaskItem BaseManifest { get; set; } + string ExcludedPermissions { get; set; } + string TargetFrameworkMoniker { get; set; } + string TargetZone { get; set; } + ITaskItem[] ApplicationDependencies { get; set; } + ITaskItem TrustInfoFile { get; set; } + + #endregion + } } diff --git a/src/Tasks/GetFrameworkSDKPath.cs b/src/Tasks/GetFrameworkSDKPath.cs index 5d10aaf2817..55bdc88ee34 100644 --- a/src/Tasks/GetFrameworkSDKPath.cs +++ b/src/Tasks/GetFrameworkSDKPath.cs @@ -1,19 +1,25 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if NETFRAMEWORK using System; -using Microsoft.Build.Framework; + using Microsoft.Build.Shared; using Microsoft.Build.Utilities; +#endif + +using Microsoft.Build.Framework; #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + /// /// Returns paths to the frameworks SDK. /// - public class GetFrameworkSdkPath : TaskExtension + public class GetFrameworkSdkPath : TaskExtension, IGetFrameworkSdkPathTaskContract { #region Properties @@ -311,4 +317,61 @@ public override bool Execute() #endregion } +#else + + public class GetFrameworkSdkPath : TaskRequiresFramework, IGetFrameworkSdkPathTaskContract + { + public GetFrameworkSdkPath() + : base(nameof(GetFrameworkSdkPath)) + { + } + + #region Properties + + [Output] + public string Path { get; set; } + + [Output] + public string FrameworkSdkVersion20Path { get; } + + [Output] + public string FrameworkSdkVersion35Path { get; } + + [Output] + public string FrameworkSdkVersion40Path { get; } + + [Output] + public string FrameworkSdkVersion45Path { get; } + + [Output] + public string FrameworkSdkVersion451Path { get; } + + [Output] + public string FrameworkSdkVersion46Path { get; } + + [Output] + public string FrameworkSdkVersion461Path { get; } + + #endregion + } + +#endif + +#pragma warning disable SA1201 // Elements should appear in the correct order + internal interface IGetFrameworkSdkPathTaskContract + { + #region Properties + + string Path { get; set; } + string FrameworkSdkVersion20Path { get; } + string FrameworkSdkVersion35Path { get; } + string FrameworkSdkVersion40Path { get; } + string FrameworkSdkVersion45Path { get; } + string FrameworkSdkVersion451Path { get; } + string FrameworkSdkVersion46Path { get; } + string FrameworkSdkVersion461Path { get; } + + #endregion + } +#pragma warning restore SA1201 // Elements should appear in the correct order } diff --git a/src/Tasks/Microsoft.Build.Tasks.csproj b/src/Tasks/Microsoft.Build.Tasks.csproj index 72ea1091d20..d0ee92e7092 100644 --- a/src/Tasks/Microsoft.Build.Tasks.csproj +++ b/src/Tasks/Microsoft.Build.Tasks.csproj @@ -328,7 +328,6 @@ - @@ -550,14 +549,41 @@ - + + + true - + true - + + true + + + true + + + true + + + true + + + + true + + + true + + + true + + + + + true @@ -598,15 +624,6 @@ true - - true - - - true - - - true - true @@ -617,16 +634,10 @@ true - - true - true - - true - true @@ -637,13 +648,6 @@ true - - true - - - true - - @@ -974,11 +978,9 @@ - + - + diff --git a/src/Tasks/Microsoft.Common.tasks b/src/Tasks/Microsoft.Common.tasks index beab1878e60..46d2eff9f2a 100644 --- a/src/Tasks/Microsoft.Common.tasks +++ b/src/Tasks/Microsoft.Common.tasks @@ -65,6 +65,7 @@ + @@ -86,6 +87,7 @@ + diff --git a/src/Tasks/RegisterAssembly.cs b/src/Tasks/RegisterAssembly.cs index 0fb8e616bb3..d47d6fa1a6e 100644 --- a/src/Tasks/RegisterAssembly.cs +++ b/src/Tasks/RegisterAssembly.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#if FEATURE_APPDOMAIN +#if NETFRAMEWORK && FEATURE_APPDOMAIN using System; using System.Diagnostics; @@ -11,20 +11,25 @@ using System.Runtime.InteropServices.ComTypes; using System.Security; -using Microsoft.Build.Framework; using Microsoft.Build.Shared; using Microsoft.Build.Shared.FileSystem; using Microsoft.Build.Utilities; +#endif + +using Microsoft.Build.Framework; + #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK && FEATURE_APPDOMAIN + /// /// Registers a managed assembly for COM interop (equivalent of regasm.exe functionality, but this code doesn't actually call the exe). /// /// ITypeLibExporterNotifySink is necessary for the ITypeLibConverter.ConvertAssemblyToTypeLib call. - public class RegisterAssembly : AppDomainIsolatedTaskExtension, ITypeLibExporterNotifySink + public class RegisterAssembly : AppDomainIsolatedTaskExtension, ITypeLibExporterNotifySink, IRegisterAssemblyTaskContract { #region Properties @@ -360,5 +365,42 @@ private bool ExportTypeLib(Assembly asm, string typeLibFileName) #endregion } -} + +#elif !NETFRAMEWORK + + public class RegisterAssembly : TaskRequiresFramework, IRegisterAssemblyTaskContract + { + public RegisterAssembly() + : base(nameof(RegisterAssembly)) + { + } + + #region Properties + + [Required] + public ITaskItem[] Assemblies { get; set; } + + [Output] + public ITaskItem[] TypeLibFiles { get; set; } + + public bool CreateCodeBase { get; set; } + + public ITaskItem AssemblyListFile { get; set; } + + #endregion + } + #endif + + internal interface IRegisterAssemblyTaskContract + { + #region Properties + + ITaskItem[] Assemblies { get; set; } + ITaskItem[] TypeLibFiles { get; set; } + bool CreateCodeBase { get; set; } + ITaskItem AssemblyListFile { get; set; } + + #endregion + } +} diff --git a/src/Tasks/ResolveComReference.cs b/src/Tasks/ResolveComReference.cs index 0a3eb949eef..a9fcee543f6 100644 --- a/src/Tasks/ResolveComReference.cs +++ b/src/Tasks/ResolveComReference.cs @@ -139,8 +139,13 @@ internal interface IResolveComReferenceTaskContract /// /// Main class for the COM reference resolution task for .NET Core /// - public sealed partial class ResolveComReference : Microsoft.Build.Tasks.TaskExtension, IResolveComReferenceTaskContract + public sealed partial class ResolveComReference : TaskRequiresFramework, IResolveComReferenceTaskContract { + public ResolveComReference() + : base(nameof(ResolveComReference)) + { + } + #pragma warning disable format // region formatting is different in net7.0 and net472, and cannot be fixed for both #region Properties @@ -183,20 +188,6 @@ public sealed partial class ResolveComReference : Microsoft.Build.Tasks.TaskExte public string TargetFrameworkVersion { get; set; } = String.Empty; #endregion - - #region ITask members - - /// - /// Task entry point. - /// - /// - public override bool Execute() - { - Log.LogErrorWithCodeFromResources("TaskRequiresFrameworkFailure", nameof(ResolveComReference)); - return false; - } - - #endregion #pragma warning restore format } diff --git a/src/Tasks/ResolveNativeReference.cs b/src/Tasks/ResolveNativeReference.cs index 66a5ac3c70b..a2e45a6441e 100644 --- a/src/Tasks/ResolveNativeReference.cs +++ b/src/Tasks/ResolveNativeReference.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if NETFRAMEWORK using System; using System.IO; using System.Collections; @@ -9,20 +10,25 @@ using System.Diagnostics; #endif using System.Linq; -using Microsoft.Build.Framework; + using Microsoft.Build.Shared; using Microsoft.Build.Shared.FileSystem; using Microsoft.Build.Tasks.Deployment.ManifestUtilities; using Microsoft.Build.Utilities; +#endif + +using Microsoft.Build.Framework; #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + /// /// Main class for the native reference resolution task. /// - public class ResolveNativeReference : TaskExtension + public class ResolveNativeReference : TaskExtension, IResolveNativeReferenceTaskConract { #region Constructors @@ -340,4 +346,62 @@ internal bool ExtractFromManifest( } #endregion } + +#else + + public class ResolveNativeReference : TaskRequiresFramework, IResolveNativeReferenceTaskConract + { + public ResolveNativeReference() + : base(nameof(ResolveNativeReference)) + { + } + + #region Properties + + [Required] + public ITaskItem[] NativeReferences { get; set; } + + [Required] + public string[] AdditionalSearchPaths { get; set; } + + [Output] + public ITaskItem[] ContainingReferenceFiles { get; set; } + + [Output] + public ITaskItem[] ContainedPrerequisiteAssemblies { get; set; } + + [Output] + public ITaskItem[] ContainedComComponents { get; set; } + + [Output] + public ITaskItem[] ContainedTypeLibraries { get; set; } + + [Output] + public ITaskItem[] ContainedLooseTlbFiles { get; set; } + + [Output] + public ITaskItem[] ContainedLooseEtcFiles { get; set; } + + #endregion + } + +#endif + +#pragma warning disable SA1201 // Elements should appear in the correct order + internal interface IResolveNativeReferenceTaskConract + { + #region Properties + + ITaskItem[] NativeReferences { get; set; } + string[] AdditionalSearchPaths { get; set; } + ITaskItem[] ContainingReferenceFiles { get; set; } + ITaskItem[] ContainedPrerequisiteAssemblies { get; set; } + ITaskItem[] ContainedComComponents { get; set; } + ITaskItem[] ContainedTypeLibraries { get; set; } + ITaskItem[] ContainedLooseTlbFiles { get; set; } + ITaskItem[] ContainedLooseEtcFiles { get; set; } + + #endregion + } +#pragma warning restore SA1201 // Elements should appear in the correct order } diff --git a/src/Tasks/TaskRequiresFramework.cs b/src/Tasks/TaskRequiresFramework.cs new file mode 100644 index 00000000000..3bd28f850c8 --- /dev/null +++ b/src/Tasks/TaskRequiresFramework.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#if !NETFRAMEWORK + +using System; + +#nullable disable + +namespace Microsoft.Build.Tasks +{ + public abstract class TaskRequiresFramework : TaskExtension + { + internal TaskRequiresFramework(string taskName) => TaskName = taskName; + + private string TaskName { get; set; } + + /// + /// Task entry point. + /// + /// + public override bool Execute() + { + Log.LogErrorWithCodeFromResources("TaskRequiresFrameworkFailure", TaskName); + return false; + } + } +} + +#endif diff --git a/src/Tasks/UnregisterAssembly.cs b/src/Tasks/UnregisterAssembly.cs index 4c297df27fd..d28897ec8bb 100644 --- a/src/Tasks/UnregisterAssembly.cs +++ b/src/Tasks/UnregisterAssembly.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#if FEATURE_APPDOMAIN +#if NETFRAMEWORK && FEATURE_APPDOMAIN using System; #if DEBUG @@ -14,19 +14,23 @@ using System.Threading; using System.Runtime.InteropServices.ComTypes; -using Microsoft.Build.Framework; using Microsoft.Build.Shared; using Microsoft.Build.Shared.FileSystem; +#endif + +using Microsoft.Build.Framework; #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK && FEATURE_APPDOMAIN + /// /// Registers a managed assembly for COM interop (equivalent of regasm.exe functionality, but this code /// doesn't actually call the exe). /// - public class UnregisterAssembly : AppDomainIsolatedTaskExtension + public class UnregisterAssembly : AppDomainIsolatedTaskExtension, IUnregisterAssemblyTaskContract { #region Properties @@ -289,5 +293,37 @@ private bool Unregister(string assemblyPath, string typeLibPath) private const string unregisteringLockName = "MSBUILD_V_3_5_UNREGISTER_LOCK"; #endregion } -} + +#elif !NETFRAMEWORK + + public class UnregisterAssembly : TaskRequiresFramework, IUnregisterAssemblyTaskContract + { + public UnregisterAssembly() + : base(nameof(UnregisterAssembly)) + { + } + + #region Properties + + public ITaskItem[] Assemblies { get; set; } + + public ITaskItem[] TypeLibFiles { get; set; } + + public ITaskItem AssemblyListFile { get; set; } + + #endregion + } + #endif + + public interface IUnregisterAssemblyTaskContract + { + #region Properties + + ITaskItem[] Assemblies { get; set; } + ITaskItem[] TypeLibFiles { get; set; } + ITaskItem AssemblyListFile { get; set; } + + #endregion + } +} diff --git a/src/Tasks/UpdateManifest.cs b/src/Tasks/UpdateManifest.cs index 0e9e78bef9c..48c32f28b69 100644 --- a/src/Tasks/UpdateManifest.cs +++ b/src/Tasks/UpdateManifest.cs @@ -2,17 +2,22 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Build.Framework; + +#if NETFRAMEWORK using Microsoft.Build.Tasks.Deployment.ManifestUtilities; using Microsoft.Build.Utilities; +#endif #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + /// /// Updates selected properties in a manifest and resigns. /// - public class UpdateManifest : Task + public class UpdateManifest : Task, IUpdateManifestTaskContract { [Required] public string ApplicationPath { get; set; } @@ -35,4 +40,48 @@ public override bool Execute() return true; } } + +#else + + public class UpdateManifest : TaskRequiresFramework, IUpdateManifestTaskContract + { + public UpdateManifest() + : base(nameof(UpdateManifest)) + { + } + + #region Properties + + [Required] + public string ApplicationPath { get; set; } + + [Required] + public string TargetFrameworkVersion { get; set; } + + [Required] + public ITaskItem ApplicationManifest { get; set; } + + [Required] + public ITaskItem InputManifest { get; set; } + + [Output] + public ITaskItem OutputManifest { get; set; } + + #endregion + } + +#endif + + internal interface IUpdateManifestTaskContract + { + #region Properties + + string ApplicationPath { get; set; } + string TargetFrameworkVersion { get; set; } + ITaskItem ApplicationManifest { get; set; } + ITaskItem InputManifest { get; set; } + ITaskItem OutputManifest { get; set; } + + #endregion + } } diff --git a/src/Tasks/WinMDExp.cs b/src/Tasks/WinMDExp.cs index 28e2662c997..989945aecf0 100644 --- a/src/Tasks/WinMDExp.cs +++ b/src/Tasks/WinMDExp.cs @@ -1,21 +1,28 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#if NETFRAMEWORK using System; -using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text; -using Microsoft.Build.Framework; + using Microsoft.Build.Shared; +#endif + +using System.Diagnostics.CodeAnalysis; + +using Microsoft.Build.Framework; #nullable disable namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + /// /// Exports a managed assembly to a windows runtime metadata. /// - public class WinMDExp : ToolTaskExtension + public class WinMDExp : ToolTaskExtension, IWinMDExpTaskContract { #region Properties @@ -274,4 +281,68 @@ protected override bool SkipTaskExecution() } #endregion } + +#else + + public class WinMDExp : TaskRequiresFramework, IWinMDExpTaskContract + { + public WinMDExp() + : base(nameof(WinMDExp)) + { + } + + #region Properties + + [Required] + public ITaskItem[] References { get; set; } + + public string DisabledWarnings { get; set; } + + public string InputDocumentationFile { get; set; } + + public string OutputDocumentationFile { get; set; } + + public string InputPDBFile { get; set; } + + public string OutputPDBFile { get; set; } + + [Required] + public string WinMDModule { get; set; } + + [Output] + public string OutputWindowsMetadataFile { get; set; } + + public string SdkToolsPath { get; set; } + + [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "UTF", Justification = "Not worth breaking customers because of case correction")] + public bool UTF8Output { get; set; } + + public bool TreatWarningsAsErrors { get; set; } + + public string AssemblyUnificationPolicy { get; set; } + + #endregion + } + +#endif + + internal interface IWinMDExpTaskContract + { + #region Properties + + ITaskItem[] References { get; set; } + string DisabledWarnings { get; set; } + string InputDocumentationFile { get; set; } + string OutputDocumentationFile { get; set; } + string InputPDBFile { get; set; } + string OutputPDBFile { get; set; } + string WinMDModule { get; set; } + string OutputWindowsMetadataFile { get; set; } + string SdkToolsPath { get; set; } + bool UTF8Output { get; set; } + bool TreatWarningsAsErrors { get; set; } + string AssemblyUnificationPolicy { get; set; } + + #endregion + } } diff --git a/src/Utilities/Microsoft.Build.Utilities.csproj b/src/Utilities/Microsoft.Build.Utilities.csproj index b9296ffc4e4..bed52dfddbf 100644 --- a/src/Utilities/Microsoft.Build.Utilities.csproj +++ b/src/Utilities/Microsoft.Build.Utilities.csproj @@ -35,7 +35,11 @@ - + + + + + Shared\AssemblyFolders\AssemblyFoldersEx.cs From 0d0c7837f4a6c497bad9707aabc8e4f5f7e814e2 Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Mon, 28 Aug 2023 17:08:56 -0400 Subject: [PATCH 2/7] Revert change to Microsoft.Build.Utilities.csproj --- src/Utilities/Microsoft.Build.Utilities.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Utilities/Microsoft.Build.Utilities.csproj b/src/Utilities/Microsoft.Build.Utilities.csproj index bed52dfddbf..b9296ffc4e4 100644 --- a/src/Utilities/Microsoft.Build.Utilities.csproj +++ b/src/Utilities/Microsoft.Build.Utilities.csproj @@ -35,11 +35,7 @@ - - - - - + Shared\AssemblyFolders\AssemblyFoldersEx.cs From 1d5ed8d2341a4ac9452ceb2189fcfea1c8578114 Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Mon, 28 Aug 2023 19:54:04 -0400 Subject: [PATCH 3/7] make stubs sealed; remove #nullable disable; remove suppression of SA1201 --- src/Tasks/Al.cs | 4 ++-- src/Tasks/AspNetCompiler.cs | 2 +- src/Tasks/GetFrameworkSDKPath.cs | 2 +- src/Tasks/RegisterAssembly.cs | 2 +- src/Tasks/ResolveNativeReference.cs | 4 +--- src/Tasks/TaskRequiresFramework.cs | 2 -- src/Tasks/UnregisterAssembly.cs | 2 +- src/Tasks/UpdateManifest.cs | 2 +- src/Tasks/WinMDExp.cs | 2 +- 9 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Tasks/Al.cs b/src/Tasks/Al.cs index 2ccbe827456..1cac38f4ffb 100644 --- a/src/Tasks/Al.cs +++ b/src/Tasks/Al.cs @@ -398,9 +398,9 @@ public override bool Execute() #else /// - /// Stub AL task for .NET Core + /// Stub AL task for .NET Core. /// - public class AL : TaskRequiresFramework, IALTaskContract + public sealed class AL : TaskRequiresFramework, IALTaskContract { public AL() : base(nameof(AL)) diff --git a/src/Tasks/AspNetCompiler.cs b/src/Tasks/AspNetCompiler.cs index 7c313f09dcb..3570cc44010 100644 --- a/src/Tasks/AspNetCompiler.cs +++ b/src/Tasks/AspNetCompiler.cs @@ -345,7 +345,7 @@ protected override bool ValidateParameters() #else - public class AspNetCompiler : TaskRequiresFramework, IAspNetCompilerTaskContract + public sealed class AspNetCompiler : TaskRequiresFramework, IAspNetCompilerTaskContract { public AspNetCompiler() : base(nameof(AspNetCompiler)) diff --git a/src/Tasks/GetFrameworkSDKPath.cs b/src/Tasks/GetFrameworkSDKPath.cs index 55bdc88ee34..fb90e032392 100644 --- a/src/Tasks/GetFrameworkSDKPath.cs +++ b/src/Tasks/GetFrameworkSDKPath.cs @@ -319,7 +319,7 @@ public override bool Execute() } #else - public class GetFrameworkSdkPath : TaskRequiresFramework, IGetFrameworkSdkPathTaskContract + public sealed class GetFrameworkSdkPath : TaskRequiresFramework, IGetFrameworkSdkPathTaskContract { public GetFrameworkSdkPath() : base(nameof(GetFrameworkSdkPath)) diff --git a/src/Tasks/RegisterAssembly.cs b/src/Tasks/RegisterAssembly.cs index d47d6fa1a6e..829e1ee31cf 100644 --- a/src/Tasks/RegisterAssembly.cs +++ b/src/Tasks/RegisterAssembly.cs @@ -368,7 +368,7 @@ private bool ExportTypeLib(Assembly asm, string typeLibFileName) #elif !NETFRAMEWORK - public class RegisterAssembly : TaskRequiresFramework, IRegisterAssemblyTaskContract + public sealed class RegisterAssembly : TaskRequiresFramework, IRegisterAssemblyTaskContract { public RegisterAssembly() : base(nameof(RegisterAssembly)) diff --git a/src/Tasks/ResolveNativeReference.cs b/src/Tasks/ResolveNativeReference.cs index a2e45a6441e..b5a50926dcc 100644 --- a/src/Tasks/ResolveNativeReference.cs +++ b/src/Tasks/ResolveNativeReference.cs @@ -349,7 +349,7 @@ internal bool ExtractFromManifest( #else - public class ResolveNativeReference : TaskRequiresFramework, IResolveNativeReferenceTaskConract + public sealed class ResolveNativeReference : TaskRequiresFramework, IResolveNativeReferenceTaskConract { public ResolveNativeReference() : base(nameof(ResolveNativeReference)) @@ -387,7 +387,6 @@ public ResolveNativeReference() #endif -#pragma warning disable SA1201 // Elements should appear in the correct order internal interface IResolveNativeReferenceTaskConract { #region Properties @@ -403,5 +402,4 @@ internal interface IResolveNativeReferenceTaskConract #endregion } -#pragma warning restore SA1201 // Elements should appear in the correct order } diff --git a/src/Tasks/TaskRequiresFramework.cs b/src/Tasks/TaskRequiresFramework.cs index 3bd28f850c8..a2a128d21d2 100644 --- a/src/Tasks/TaskRequiresFramework.cs +++ b/src/Tasks/TaskRequiresFramework.cs @@ -5,8 +5,6 @@ using System; -#nullable disable - namespace Microsoft.Build.Tasks { public abstract class TaskRequiresFramework : TaskExtension diff --git a/src/Tasks/UnregisterAssembly.cs b/src/Tasks/UnregisterAssembly.cs index d28897ec8bb..6721625deb5 100644 --- a/src/Tasks/UnregisterAssembly.cs +++ b/src/Tasks/UnregisterAssembly.cs @@ -296,7 +296,7 @@ private bool Unregister(string assemblyPath, string typeLibPath) #elif !NETFRAMEWORK - public class UnregisterAssembly : TaskRequiresFramework, IUnregisterAssemblyTaskContract + public sealed class UnregisterAssembly : TaskRequiresFramework, IUnregisterAssemblyTaskContract { public UnregisterAssembly() : base(nameof(UnregisterAssembly)) diff --git a/src/Tasks/UpdateManifest.cs b/src/Tasks/UpdateManifest.cs index 48c32f28b69..6ea412fdb70 100644 --- a/src/Tasks/UpdateManifest.cs +++ b/src/Tasks/UpdateManifest.cs @@ -43,7 +43,7 @@ public override bool Execute() #else - public class UpdateManifest : TaskRequiresFramework, IUpdateManifestTaskContract + public sealed class UpdateManifest : TaskRequiresFramework, IUpdateManifestTaskContract { public UpdateManifest() : base(nameof(UpdateManifest)) diff --git a/src/Tasks/WinMDExp.cs b/src/Tasks/WinMDExp.cs index 989945aecf0..037c9f1ab09 100644 --- a/src/Tasks/WinMDExp.cs +++ b/src/Tasks/WinMDExp.cs @@ -284,7 +284,7 @@ protected override bool SkipTaskExecution() #else - public class WinMDExp : TaskRequiresFramework, IWinMDExpTaskContract + public sealed class WinMDExp : TaskRequiresFramework, IWinMDExpTaskContract { public WinMDExp() : base(nameof(WinMDExp)) From 53829303d75fa915c3f9b11b82586c7b21524ac5 Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Tue, 29 Aug 2023 10:59:01 -0500 Subject: [PATCH 4/7] Add CP0007 suppressions for tasks that are stubs on Core --- src/Tasks/CompatibilitySuppressions.xml | 68 +++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/src/Tasks/CompatibilitySuppressions.xml b/src/Tasks/CompatibilitySuppressions.xml index 498513b70bc..f5a247793a2 100644 --- a/src/Tasks/CompatibilitySuppressions.xml +++ b/src/Tasks/CompatibilitySuppressions.xml @@ -1,18 +1,78 @@  - - + + CP0007 + T:Microsoft.Build.Tasks.AL + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + + CP0007 + T:Microsoft.Build.Tasks.AspNetCompiler + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + + CP0007 + T:Microsoft.Build.Tasks.GenerateBootstrapper + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + + CP0007 + T:Microsoft.Build.Tasks.GenerateTrustInfo + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + + CP0007 + T:Microsoft.Build.Tasks.GetFrameworkSdkPath + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + + CP0007 + T:Microsoft.Build.Tasks.RegisterAssembly + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + CP0007 T:Microsoft.Build.Tasks.ResolveComReference ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll ref/net472/Microsoft.Build.Tasks.Core.dll + + CP0007 + T:Microsoft.Build.Tasks.ResolveNativeReference + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + + CP0007 + T:Microsoft.Build.Tasks.UnregisterAssembly + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + + CP0007 + T:Microsoft.Build.Tasks.UpdateManifest + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + + + CP0007 + T:Microsoft.Build.Tasks.WinMDExp + ref/netstandard2.0/Microsoft.Build.Tasks.Core.dll + ref/net472/Microsoft.Build.Tasks.Core.dll + - + CP1002 System.Security.Cryptography, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a From 87cb574311446f352655cf469a848812a1b60c31 Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Tue, 29 Aug 2023 22:11:40 -0400 Subject: [PATCH 5/7] remove Required attribute from .NET stub tasks --- src/Tasks/Al.cs | 1 - src/Tasks/GenerateTrustInfo.cs | 1 - src/Tasks/RegisterAssembly.cs | 1 - src/Tasks/ResolveNativeReference.cs | 2 -- src/Tasks/UpdateManifest.cs | 4 ---- src/Tasks/WinMDExp.cs | 2 -- 6 files changed, 11 deletions(-) diff --git a/src/Tasks/Al.cs b/src/Tasks/Al.cs index 1cac38f4ffb..0b587df5b74 100644 --- a/src/Tasks/Al.cs +++ b/src/Tasks/Al.cs @@ -440,7 +440,6 @@ public AL() public string MainEntryPoint { get; set; } [Output] - [Required] public ITaskItem OutputAssembly { get; set; } public string Platform { get; set; } diff --git a/src/Tasks/GenerateTrustInfo.cs b/src/Tasks/GenerateTrustInfo.cs index fa369fd26b7..7d76056879b 100644 --- a/src/Tasks/GenerateTrustInfo.cs +++ b/src/Tasks/GenerateTrustInfo.cs @@ -127,7 +127,6 @@ public GenerateTrustInfo() public ITaskItem[] ApplicationDependencies { get; set; } [Output] - [Required] public ITaskItem TrustInfoFile { get; set; } #endregion diff --git a/src/Tasks/RegisterAssembly.cs b/src/Tasks/RegisterAssembly.cs index 829e1ee31cf..542e2a8f08b 100644 --- a/src/Tasks/RegisterAssembly.cs +++ b/src/Tasks/RegisterAssembly.cs @@ -377,7 +377,6 @@ public RegisterAssembly() #region Properties - [Required] public ITaskItem[] Assemblies { get; set; } [Output] diff --git a/src/Tasks/ResolveNativeReference.cs b/src/Tasks/ResolveNativeReference.cs index b5a50926dcc..484401442be 100644 --- a/src/Tasks/ResolveNativeReference.cs +++ b/src/Tasks/ResolveNativeReference.cs @@ -358,10 +358,8 @@ public ResolveNativeReference() #region Properties - [Required] public ITaskItem[] NativeReferences { get; set; } - [Required] public string[] AdditionalSearchPaths { get; set; } [Output] diff --git a/src/Tasks/UpdateManifest.cs b/src/Tasks/UpdateManifest.cs index 6ea412fdb70..109f7ee732c 100644 --- a/src/Tasks/UpdateManifest.cs +++ b/src/Tasks/UpdateManifest.cs @@ -52,16 +52,12 @@ public UpdateManifest() #region Properties - [Required] public string ApplicationPath { get; set; } - [Required] public string TargetFrameworkVersion { get; set; } - [Required] public ITaskItem ApplicationManifest { get; set; } - [Required] public ITaskItem InputManifest { get; set; } [Output] diff --git a/src/Tasks/WinMDExp.cs b/src/Tasks/WinMDExp.cs index 037c9f1ab09..280b5dcb55c 100644 --- a/src/Tasks/WinMDExp.cs +++ b/src/Tasks/WinMDExp.cs @@ -293,7 +293,6 @@ public WinMDExp() #region Properties - [Required] public ITaskItem[] References { get; set; } public string DisabledWarnings { get; set; } @@ -306,7 +305,6 @@ public WinMDExp() public string OutputPDBFile { get; set; } - [Required] public string WinMDModule { get; set; } [Output] From 4084c61f5aeee2d683a1d54cbe6de6f5ef320586 Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Tue, 29 Aug 2023 22:17:38 -0400 Subject: [PATCH 6/7] update Microsoft.Common.tasks --- src/Tasks/Microsoft.Common.tasks | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Tasks/Microsoft.Common.tasks b/src/Tasks/Microsoft.Common.tasks index 46d2eff9f2a..f8e09491af3 100644 --- a/src/Tasks/Microsoft.Common.tasks +++ b/src/Tasks/Microsoft.Common.tasks @@ -63,9 +63,8 @@ - + - @@ -85,9 +84,8 @@ - + - From 81706c52102fc99a174b246b8e38d1f306b0f12a Mon Sep 17 00:00:00 2001 From: Jonathan Dodds Date: Tue, 29 Aug 2023 23:00:00 -0400 Subject: [PATCH 7/7] add for .Net Framework but Obsolete and no-op --- src/Tasks/TaskRequiresFramework.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Tasks/TaskRequiresFramework.cs b/src/Tasks/TaskRequiresFramework.cs index a2a128d21d2..e681eb903b5 100644 --- a/src/Tasks/TaskRequiresFramework.cs +++ b/src/Tasks/TaskRequiresFramework.cs @@ -1,18 +1,21 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#if !NETFRAMEWORK using System; namespace Microsoft.Build.Tasks { +#if NETFRAMEWORK + [Obsolete("The class should not be used in .Net Framework.", true)] +#endif public abstract class TaskRequiresFramework : TaskExtension { internal TaskRequiresFramework(string taskName) => TaskName = taskName; private string TaskName { get; set; } +#if !NETFRAMEWORK /// /// Task entry point. /// @@ -22,7 +25,6 @@ public override bool Execute() Log.LogErrorWithCodeFromResources("TaskRequiresFrameworkFailure", TaskName); return false; } +#endif } } - -#endif