[Feature Request] New MSBuildSdk to simplify creating an MSBuild task package
The Problem
The general steps to create a NuGet package that contains MSBuild tasks is outlined here: https://learn.microsoft.com/en-us/visualstudio/msbuild/tutorial-custom-task-code-generation?view=vs-2022#package-the-task-for-distribution
This process requires 8 steps:
- Set
CopyLocalLockFileAssemblies - Mark all PackageReferences with
PrivateAssets="All" - Add the
CopyProjectReferencesToPackagetarget - Set the
BuildOutputTargetFolder - Suppress NU5100 and NU5128
- Mark Microsoft.Build.* assemblies with
ExcludeAssets="runtime" - Set
GenerateDependencyFileand add target to copy to output directory - Add the build/, buildTransitive/, buildMultiTargeting/ folders to the package
and I always forget at least one when creating a new project.
The Proposal
Create a new SDK to centralize these steps, and ideally update the docs to point to the SDK instead. In addition to lowering the barrier to authoring MSBuild tasks, centralizing the process for creating an MSBuild task package will make it easier for authors to follow best practices as they evolve (similar to the DotNet.ReproducibleBuilds packages).
I'm happy to do this work myself, but wanted to get approval before starting. Thoughts?
I'm torn about where the line for an MSBuild SDK and a .NET Template might be - I could see pushing several of those steps into an MSBuild SDK, and then shipping a .NET SDK Template that could get your started on a new Task package - project file using the new SDK, placeholder props/targets, a class library for a Task with all of the organization/project file changes to make it all work, etc.
To be clear, I'd love to see something like a base SDK exist! I love this suggestion and would be happy to help push it forward.
OK, happy to get started here. Two asks:
- If you have initial thoughts on which pieces belong in which part (SDK vs template) post them here
- Since we're considering making another template, weigh in on #529 as well since a. It's directionally aligned b. I made a bunch of directory layout assumptions that'll impact the work here
Happy to give input - interested to see how y'all gonna approach this - supporting VS desktop and dotnet cli - supporting testing...
If you need some inspiration i'll throw my package in the ring:
https://github.com/MeikTranel/NXPorts/blob/master/src/NXPorts/NXPorts.csproj
I use MSBuild sdk/task packages much more extensively but unfortunately i cant post these here.
I wonder if there's a broader generalization to this proposal which might be "Plugin SDK". Similar constraints might apply to roslyn analyzers, MSBuild tasks, powershell commandlets, Azure functions, etc.