4

我正在尝试使用以下 msbuild 目标将来自第二个项目的文件作为 EmbeddedResources 包含在内:

    <CreateItem Include="..\MyProject.Templates\**\*.css">
      <Output ItemName="EmbeddedResource" TaskParameter="Include" />
    </CreateItem>

但是包含的文件丢失了它们的路径,例如~\Views\_Layout.cshtml包含为_Layout.cshtml(不是Views._Layout.cshtml所需的)。有什么方法可以达到预期的效果吗?

4

1 回答 1

2

MSBuild has New Methods for Manipulating Items and Properties. Using these methods, you can map your resources using an ItemGroup (instead of CreateItem), then create another ItemGroup applying MSBuild Transforms with MSBuild Well-known Item Metadata. There are many item metadata options you could use to achieve the desired effect. There's a clear example of the syntax on this answer.

I wrote a little script as an example. It creates an ItemGroup with *.exe files and transforms them. Tested with MSBuild 3.5.

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project DefaultTargets="CreateItems" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="CreateItems">
    <ItemGroup>
      <Exe Include="..\**\*.exe" />
    </ItemGroup>
    <ItemGroup>
      <TransformedExe Include="@(Exe->'%(Relativedir)')"/>
    </ItemGroup>
    <Message Text="1 - @(Exe)" />
    <Message Text="2 - @(TransformedExe)" />
  </Target>
</Project>
于 2013-02-16T13:47:33.583 回答