Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify build action of content - Nuget

What is the simplest way to tell Nuget package to add all css files as an embedded resource (ie build action is embedded resource).

I am trying to do it through install.ps1 in the tools folder but still cant get anywhere

Note: I am creating the package from the directory structure(tools\content\lib)

This is my install.ps1 which does not work.

param($installPath, $toolsPath, $package, $project)
$MsbNS = @{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'}    
function EmbeddContent($ProjectLink, [string]$XPath)
{
    $nodes = @(Select-Xml $XPath $ProjectLink -Namespace $MsbNS | Foreach {$_.Node})

    foreach ($node in $nodes)
    {   
    if($node.Include.StartsWith("Content\css"))
    {           
        $cet = $node.ownerdocument.CreateElement("EmbeddedResource")
        $cet.setAttribute("Include", $node.Include)
        $parent = $node.ParentNode          
        [void]$parent.RemoveChild($node)
        [void]$parent.Appendchild($cet)        
    }
    }
}
$project.Save()
$fileLocation = $project.FileName
$dte.ExecuteCommand("Project.UnloadProject");

$proj = [xml](gc $fileLocation)
Embeddcontent $fileLocation '//msb:Project/msb:ItemGroup/msb:Content'
$proj.Save($fileLocation)

Help Please ..

like image 849
labroo Avatar asked Sep 14 '11 22:09

labroo


People also ask

How do you set build Action to content?

Set a build action Or, right-click on the file in Solution Explorer and choose Properties. In the Properties window, under the Advanced section, use the drop-down list next to Build Action to set a build action for the file.

What is PackagePath?

PackagePath : Path where the file should be output in the package. NuGet issues a warning if more than one file is added to the same package path. BuildAction : The build action to assign to the file, required only if the package path is in the contentFiles folder. Defaults to "None".


1 Answers

You can use DTE instead of messing with xml to change the BuildAction. From http://nuget.codeplex.com/discussions/227696:

$item = $project.ProjectItems | where-object {$_.Name -eq "ReleaseNotes.txt"} 
$item.Properties.Item("BuildAction").Value = [int]3

This link shows the enumeration values: http://msdn.microsoft.com/en-us/library/aa983962(VS.71).aspx

like image 172
davidfowl Avatar answered Oct 12 '22 11:10

davidfowl