Note that there are some explanatory texts on larger screens.

plurals
  1. POMSBuild: How do I create and use a Task to convert Content items at build time?
    text
    copied!<p>I have a Silverlight 3 project with something like this:</p> <pre><code>&lt;ItemGroup&gt; &lt;Content Include="Content\image1.png"&gt; &lt;/Content&gt; &lt;/ItemGroup&gt; </code></pre> <p>Basically I've added a PNG file to my project and set its build action to "Content". This works nicely.</p> <p>Now what I'd like to do is be able to add images in a <em>different</em> format to my project, and have them <strong>converted to PNG at build time</strong> - so that the end result is as if I had added a PNG image to the project (as Content) in the first place.</p> <p>In other words - I want the image to appear, in PNG format, in my XAP package.</p> <p>Ideally I would like to do this in such a way that it will work with Visual Web Developer 2008 Express (so I can add image files to my project by dragging them into the IDE and maybe changing their build action), and without making any system-wide changes.</p> <p>The specific format I want to convert is XCF - I already have the .NET code to do the conversion to PNG. I am assuming that I must <a href="http://msdn.microsoft.com/en-us/library/t9883dzc.aspx" rel="noreferrer">create a MSBuild Task</a>.</p> <p>I don't really have much MSBuild experience, and I'd like to know how to put such a thing together.</p> <hr> <p>Based on my rough understanding of how MSBuild works, I think that I need to know:</p> <ul> <li>How to create a collection of items by (re)moving them from the <code>@(Content)</code> (or some other) collection, based on their file extension? <ul> <li>OR: Create a custom Build Action I can use in Visual Web Developer 2008 Express</li> </ul></li> <li>How to recieve the path of input items in a <code>Task</code>?</li> <li>Where (.NET or MSBuild?) and How to specify the location of output files generated by a <code>Task</code>?</li> <li>How to ensure that a file is rebuilt if its input file changes?</li> <li>Where (probably <code>BeforeBuild</code>?) and How to reinject the converted items into <code>@(Content)</code>? (Or should I use some other collection?) <ul> <li>OR: Some other way of getting them into the XAP?</li> </ul></li> </ul> <p>And if this seems like a reasonable way to do things or if I've missed anything?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload