Producing an MSBuild task package
See original GitHub issueCan we get better support for projects designed to produce MSBuild tasks?
Pain points
- packing. You can get a task assembly and files into the package, but requires deep understanding of how to alter the default layout of the package in csproj.
- TargetFrameworks. A package that only has task assemblies/targets is compiled for net46 and netcoreapp1.0, but the package itself can be compatible with any project, regardless of its TFM.
- task references. When loading a task assembly, MSBuild does not use the NuGet cache to find dependencies. This means we have to package assemblies to sit side-by-side on disk so task loading works.
- tasks with native dependencies. Never been able to make this work.
Workarounds Task assembly projects end up looking like this
<PropertyGroup>
<!--
The netstandard1.0 and net45 TFMs don't actually compile tasks.
Only here so the generated nuspec includes the TFM so it appears as "compatible" on NuGet.org
and in VS NuGet GUI.
netstandard1.6 => loaded on dotnet.exe
net46 => loaded on MSBuild.exe
-->
<TargetFrameworks>netstandard1.6;net46;netstandard1.0;net45</TargetFrameworks>
<!-- Be quiet NuGet. I don't want assemblies in lib/ and yes I'm sure this is right. -->
<NoPackageAnalysis>true</NoPackageAnalysis>
<!-- forces SDK to copy dependencies into build output to make packing easier -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
</PropertyGroup>
<ItemGroup>
<!-- ensure nuspec doesn't contain any package references as we bundle their assemblies in our package -->
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
</ItemGroup>
<!--
Copy dependencies into the tools/$(TargetFramework)/ package folders.
MSBuild does not resolve task runtime dependencies from PackageReference
-->
<Target Name="PackTaskDependencies" BeforeTargets="GenerateNuspec">
<!--
The include needs to happen after output has been copied to build output folder
but before NuGet generates a nuspec.
-->
<ItemGroup>
<_PackageFiles Include="bin\$(Configuration)\*\Newtonsoft.Json.dll;bin\$(Configuration)\*\NUglify.dll">
<PackagePath>tools\%(RecursiveDir)</PackagePath>
<Visible>false</Visible>
<BuildAction>Content</BuildAction>
</_PackageFiles>
</ItemGroup>
</Target>
Some MSBuild task projects in the wild:
madskristensen/BundlerMinifier aspnet/BuildTools natemcmaster/Yarn.MSBuild
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Create a custom task for code generation - MSBuild
In this tutorial, you'll create a custom task in MSBuild in C# that handles code generation, and then you'll use the task in...
Read more >Shipping a cross-platform MSBuild task in a NuGet package
Step 1 - write the task. An MSBuild task can be implemented in C#. MSBuild can load and run any public class that...
Read more >Producing an MSBuild task package · Issue #5063
task references. When loading a task assembly, MSBuild does not use the NuGet cache to find dependencies. This means we have to package...
Read more >Shipping msbuild task as nuget
I want my users to be able to download and install a nuget package and once the package is installed the build task...
Read more >Implementing and Debugging Custom MSBuild Tasks
Inline Tasks – We can write code fragments directly into .targets files. They will be compiled into tasks by the RoslynCodeTaskFactory and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In a world of unlimited resources, I’d love to see this:
Microsoft.NET.Sdk is geared towards runtime packages, not MSBuild task packages. Packages designed to carry MSBuild tasks are fundamentally different from packages that only carry runtime bits.
This issue was moved to NuGet/Home#5063