Docker + dotnet-watch
Setup an ASP.NET Core project with Docker and dotnet-watch, without making Visual Studio crash and burn
I made a change to dotnet-watch recently that will make it much easier to setup Docker + dotnet-watch in your ASP.NET Core project, without causing Visual Studio to crash and burn. In current versions of dotnet-watch, there have been issues getting it to work with Docker, and it required some ugly workarounds. Even then, it was hard to keep Docker, dotnet-watch, and Visual Studio happy. Either Docker or Visual Studio would complain about issues with NuGet caches, duplicate attributes, etc. The next version of dotnet-watch removes the need for those ugly workarounds. This version isn’t available yet on NuGet.org, but you can still give it a test run today with ASP.NET Core 2.0.0 projects. The post below shows you how to setup your project to do this today using a nightly build of dotnet-watch.
Bundling .NET build tools in NuGet
How to share your console app via NuGet and MSBuild
If you are looking for a way to share a build tool among several .NET Framework or .NET Core projects,
NuGet is an excellent way to distribute it. Starting with Visual Studio 2017, NuGet comes “batteries included”
with Microsoft.NET.Sdk (typically for .NET Standard and Core) projects, and can be made to work with
“classic” .NET Framework projects, too. Most of the time, NuGet packages are used to share runtime libraries,
but NuGet packages can be used for build tools, too.
By adding a
<PackageReference> to your *.csproj files, you can ensure that the tool is available, and
you can even automatically wire it up into the project’s compilation steps.
MSBuild tasks with dependencies
You could wrestle with MSBuild's task loading mechanism, or just don't.
A few months ago, I wrote demos and a blog post about writing MSBuild tasks and shipping them in a NuGet package. The question I’ve been asked most frequently since then is “how to I make a task with external dependencies work?” i.e. “my task needs to connect to MySql, Postgres, load SQLite”, or something like that. When I started writing a post to answer these questions, I intended to show you the way to make all this work.
Shipping a cross-platform MSBuild task in a NuGet package
MSBuild allows users to write and register their own tasks. Tasks, unlike targets, can be written in C# and can perform build operations that would be impossible to write in MSBuild’s XML dialect. In this post, I’m going walk through the key pieces of how to write an MSBuild task that works on both the .NET Core command line and in Visual Studio, and then how to bundle that task into a NuGet package so the task can be shared and installed automatically into projects.