Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] New MSBuildSdk to simplify creating an MSBuild task package #551

Open
MattKotsenas opened this issue Mar 30, 2024 · 4 comments

Comments

@MattKotsenas
Copy link
Member

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:

  1. Set CopyLocalLockFileAssemblies
  2. Mark all PackageReferences with PrivateAssets="All"
  3. Add the CopyProjectReferencesToPackage target
  4. Set the BuildOutputTargetFolder
  5. Suppress NU5100 and NU5128
  6. Mark Microsoft.Build.* assemblies with ExcludeAssets="runtime"
  7. Set GenerateDependencyFile and add target to copy to output directory
  8. 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?

@baronfel
Copy link
Member

baronfel commented Mar 30, 2024

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.

@MattKotsenas
Copy link
Member Author

OK, happy to get started here. Two asks:

  1. If you have initial thoughts on which pieces belong in which part (SDK vs template) post them here
  2. Since we're considering making another template, weigh in on Add 'dotnet new' templates for NoTargets and Traversal #529 as well since
    a. It's directionally aligned
    b. I made a bunch of directory layout assumptions that'll impact the work here

@MeikTranel
Copy link
Contributor

MeikTranel commented Mar 30, 2024

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.

@ericstj
Copy link
Member

ericstj commented May 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants