当前位置: 动力学知识库 > 问答 > 编程问答 >

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

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: