specify build action of content - Nuget

早过忘川 提交于 2019-12-03 15:30:02

问题


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 ..


回答1:


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



来源:https://stackoverflow.com/questions/7423564/specify-build-action-of-content-nuget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!