NuGet and MSBuild

Dec 7, 2011 at 1:36 AM


Is there a MSBuild task to create Nuget packages?

I have a VS 2010 project and a nuspec file which I would like to build when the projects builds.

How can I do this?

Thank You,


Dec 7, 2011 at 1:37 AM

The NuGet solution includes an MSBuild task.

Dec 7, 2011 at 2:20 AM


I downloaded it and tried with a simple project. I added the following to my proj file:

  <Import Project="C:\Users\Miguel\Projects\NuGet\nuget.targets" />
    <Content Include="package.nuspec" />
  <Target Name="AfterBuild">

And when I reload the project I get the following error:

"Unable to read the project file "ClassProj.csproj". ... The element <#text> beneath the element <CreateNuGetPackage> is unrecognized.

Any idea what I am doing wrong?

Thank You,


Dec 7, 2011 at 4:03 AM

Yea, don't use that one. Instead do the following.

  1. Open the powershell console in VS.
  2. Run Install-Package NuGetPowerTools
  3. type Enable-PackageBuild
  4. Profit :)
Dec 7, 2011 at 4:29 AM

Ha, didn't know that the PowerTools has the Enable-PackageBuild command.

We need to either fix the MSBuild task project or just delete it.

Dec 7, 2011 at 8:54 AM


Dec 7, 2011 at 5:40 PM

That was quite useful. I installed it and worked fine. Just one question:

After build I want to "publish" the package to a local folder where I have all the packages I use. I am using:


    <Package Include="$(OutputPath)\Helpers.Core.1.0.nupkg"/>

  <Target Name="AfterBuild">
    <Copy SourceFiles="@(Package)" DestinationFolder="C:\Users\Miguel\Packages" />


This is working fine ... But is there anything in Power Tools for this?

Finally, how can I use the Naming rule that power tools use for naming the package? Basically, instead of having:

    <Package Include="$(OutputPath)\Helpers.Core.1.0.nupkg"/>

I would like to have something like:

    <Package Include="$(OutputPath)\PROJECT_NAME.PROJECT_VERSION.nupkg"/>

Or whatever rule Power Tools is using for package naming.

So I don't have to change this too all projects.

Thank You,


Nov 17, 2012 at 9:06 AM

>Failed to add import 'NuGet.targets' to WebApplication1

I see the above error when running Enable-PackageBuild command NuGetPowerTools package. When I search for NuGet.targets on my disk, I don't find the file. I am using this in VS 2010 SP1 Rel.

Following is the output from the Package manager console. Any pointers on how to find out what is going wrong here?

PM> Install-Package NuGetPowerTools
Successfully installed 'NuGetPowerTools 0.29'.



 - To enable building a package from a project use the Enable-PackageBuild command

 - To enable restoring packages on build use the Enable-PackageRestore command.

 - When using one of the above commands, a .nuget folder will been added to your
solution root. Make sure you check it in!

 - For for information, see


PM> Enable-PackageBuild
Failed to add import 'NuGet.targets' to WebApplication1
Enabled package build for WebApplication1

Nov 18, 2012 at 1:47 AM

I was able to resolve this issue by installing the NuGet.Build package and its dependencies. I then copied NuGet.exe, NuGet.targets to the solution level .nuget folder for this to work.

Reviewing the .nuspec of NuGetPowerTools package, I found that it does not have an explicit dependency on NuGet.Build. If that were specified then the pre-reqs would have got installed along with it.