Why the target “Package” does not exist in the project

I wasn’t intending to write about this simply because to be honest, it’s a stupid mistake. What swung me into blogger mode was that if I had found this post in my searches a couple of hours ago I’d be relaxing with a cold beer right now rather than nursing the sore head I’ve been banging against the wall this evening.

This is all about MSBuild and more specifically, targeting “Package” so that the app can then be pushed out to a server via Web Deploy (MSDeploy). Vishal Joshi writes about this target very eloquently in Web Packaging: Creating web packages using MSBuild.

Anyway, although I could build the solution just fine with MSBuild, every time I added the /T:Package switch I’d get something like this:


For the sake of succinctness and the search bots, here’s the important bit:

c:\Projects\MySolution\MySolution.sln.metaproj : error MSB4057: The target "Package" does not exist in the project. [c:\Projects\MySolution\MySolution.sln]

The oracle of programming truth, AKA “Stack Overflow”, suggested it was a .NET framework issue or a missing Web Deploy install. However, I still had the same problem whilst being certain it was neither of these root causes and I could reproduce the problem on a second machine.

The penny finally dropped when I started thinking about it; the whole purpose of creating a web package is to package up the website, not the entire solution. Here’s the problem:


As soon as I changed the .sln solution path to the appropriate .csproj project path, everything played nice and a beautiful web package emerged from the carnage. In a perfect world, MSBuild would be a bit more intuitive and say something along the lines of “Hey, you’re trying to turn a solution into a web package, stupid!” but then again, this was such an obvious problem (in retrospect) I probably shouldn’t be trying to deflect too much of the blame.

Just as an aside, I’ve had some great feedback on similar posts to this – short and sharp “here’s what’s wrong” posts – as they often help people out of a hole in their darkest hours. If this post has done that for you, leave your feedback so I know I’m not the only one to overlook the flaming obvious!

Tweet Post Update Email RSS

Hi, I'm Troy Hunt, I write this blog, create courses for Pluralsight and am a Microsoft Regional Director and MVP who travels the world speaking at events and training technology professionals