Skip to content

Spec Proposal: MSBuild Extension support for .NET Core #1756

Closed
@AArnott

Description

NuGet and MSBuild should work more closely together for MSBuild extensions.

Creation of an MSBuild extension

I should be able to dotnet new buildextension to get a new project that:

  1. Includes an MSBuild Task that compiles to net45 and netcoreapp1.x
  2. Includes an MSBuild .props and .targets file in source code that invoke the Task from a target, choosing
  3. Packs to a NuGet package, that
    1. expresses package dependencies for package dependencies referenced in the csproj that compiled the MSBuild Task. No need to embed dependencies in the MSBuild extension package itself.
    2. Sets DevelopmentDependency=true automatically in the nuspec file.

Consumption of this MSBuild extension:

  1. Happens by adding a BuildExtensionReference item to the receiving project. This isn't PackageReference because its dependency graph does not blend into the project's dependency graph. But it isn't DotNetCliToolReference because those items do not contribute MSBuild .props and .targets files to the project. This BuildExtensionReference item may propagate across P2P references if desired (so that a single 'root' project in a solution may add the extension to all other projects that reference it). Or perhaps we can unify this new item with DotNetCliToolReference by calling it ProjectExtension (similar to MSBuild's special element type, but this one would appear inside an ItemGroup element.
  2. Upon NuGet Restore of the project, the MSBuild extension is downloaded to the machine package cache along with all its dependencies in their own respective packages.
  3. The project automatically imports the .props and .targets from the package.
  4. The project can build and invoke the Task both on MSBuild full and MSBuild Core, and dependencies the Task has can resolve from the package cache.
  5. The MSBuild Task controls its own dependencies independently of other Tasks that may run in that project because each one runs in its own AssemblyLoadContext in MSBuild Core and AppDomain in MSBuild Desktop.

Optional dotnet CLI tool as well:

An MSBuild extension may also want to provide convenient dotnet CLI invocation as well. Currently for an MSBuild extension to both modify the build but also make tools accessible by dotnet CLI the user must add both a PackageReference and a DotNetCliToolReference item to their project. This is cumbersome, especially when such an extension applies to all projects in a solution. So dotnet CLI should allow one package to offer both an MSBuild extension and a dotnet CLI tool.

An example is Nerdbank.GitVersioning which both modifies the build with special version semantics, as well as offers a couple of CLI tools to translate a commit to a version and vice versa.

As discussed with @nguerrera and @tmat on another issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions