I'd like to run a custom EXE against my XAML Resource Dictionaries. Let's say this exe that I've got is going to strip out comments, whitespace and unused resources. The original XAML files need to be untouched, but the XAML (silverlight) and BAML (wpf) that ends up i开发者_开发技巧n the XAPs and DLLs needs to be transformed. It needs to work on my computer and the build server.
My question is: what's the simplest and most reliable way to run this exe?
My first thought was to have a pre-build event. But this would have to work on the original XAML file. Development would become quite painful.
By the time the post build event has been run, my resources are already compiled into the dlls.
What are my options?
You should implement the "exe" as an MSbuild Task.
Essentially you build a C# class that inherits from the Microsoft.Build.Utilities.Task class, and overide the Execute() method.
Something like
public class CleanXAML : Task
{
}
Then you spefify (either in your build file, or an external .tasks file that you import, the task name and the path to the DLL you just built)
<UsingTask AssemblyFile="C:\customtasks\XamlTasks.dll"
TaskName="Rob.CustomTasks.Xaml.CleanXaml"/>
That enables you to invoke this like any other MsBuild task
<CleanXaml Source="$(PathtoOriginalXaml)"
Destination="$(SourceCodePath)\$(cleanXaml.xaml)" />
From there you need to figure out the best way to "inject" this into your build process. Depending on how you are building (msbuild, vs2010, teambuild, or teambuild workflow) there are different ways to do this. Essentially you need this to happen BEFORE the CoreCompile target is invoked and make sure your "output xaml" properly replaces what CSC.exe is going to expect.
Do some searches on MsBuild tasks for more info, or ask any question you've got here.
I would highly recommend this approach vs. using a CallEXE task in MSBuild, b/c this way the MSBuild properties and items stay in context so you are just moving from build step to build step, vs sidetracking the whole thing to do the transform, then hoping it keeps working.
精彩评论