4

I am trying to include files from a second project as EmbeddedResources using the following msbuild target:

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

but the included file loose their path e.g. ~\Views\_Layout.cshtml is included as _Layout.cshtml (not Views._Layout.cshtml as is desired). Is there some way to achieve the desired effect?

2
  • The 'CreateItem' task is deprecated, are there any reasons for you to use it? Commented Feb 14, 2013 at 0:39
  • Copy n paste from ayende.com/blog/4446/… All I want to achieve is (1) bringing in embedded resources from a wildcard route, (2) in such a way VS doesn't materialize them out, (3) while preserving path structure. This manages (1) and (2)... Commented Feb 14, 2013 at 9:21

1 Answer 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>
Sign up to request clarification or add additional context in comments.

3 Comments

So simple and so useful. I wonder if this ever worked for the OP. I just switched a project from NAnt to MSBuild, and I'm very impressed so far with how well thought-out it is.
your "this answer" has been removed ... do you have new link for it? or ...?
@Seagal82 did my best finding a new link, dunno why they deleted the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.