Tuesday, August 7, 2012

NuGet: change build action value

For a client, I had to create a custom NuGet package. This packaged adds some custom content(images, scripts, icons,…) to an ASP.NET MVC project. Adding the content files was no problem, however I noticed that the BuildAction was incorrectly set.

To solve this we need some Powershell magic. Create an install.ps1 file and add it to your NuGet package(More info here).

Inside the powershell file I added the following code:

param($installPath, $toolsPath, $package, $project)

$item = $project.ProjectItems | where-object {$_.Name -eq "ReleaseNotes.txt"}

$item.Properties.Item("BuildAction").Value = [int]2

To find the correct enum value for BuildAction have a look here: http://msdn.microsoft.com/en-us/library/aa983962(VS.71).aspx

Remark: Note that the search through the ProjectItems is not recursive. Subfolders are not scanned.