开发者

Visual Studio 2010 Extensibility - Override Build Action without effecting cproj file

I'm working on a way to get MonoTouch projects to build in Visual Studio 2010 without requiring a change of the cproj file. I'm almost there, but the final step is the *.xib files that has build action "Page" in MonoTouch projects.

In Visual Studio 2010 bild action Page will invoke the XAML compiler, so in order to build the project in VS2010 I need to set the build action to None. The problem doing this is that the .cproj file is changed, and开发者_运维问答 I need to set it back to Page before building in MonoTouch.

So my question is something like this. Using the Visual Studio extensibility model, is it possible to "intercept" certain file types and "ignore" them or alter their build type? Or is Visual Studio building everything using msbuild, and hence only caring about what is actually written in the .cproj file?


I ended up solving this problem using a slightly different strategy. You can listen for different build events on the DTE object and run code in your Visual Studio 2010 extension before and after build.

_dte.Events.BuildEvents.OnBuildBegin += MakeXibsNone;
_dte.Events.BuildEvents.OnBuildDone += MakeXibsPage;

Using this strategy I can change the build action to None before the build, and then back to Page after the build. The code to change the build type simply enumerates all the projects in the solution, and all the project items in the project. It finds all files with a .xib extension and change the build action using the following code:

xib.Properties.Item("ItemType").Value = "Page";
xib.Properties.Item("ItemType").Value = "None";

The complete implementation can be found at https://github.com/follesoe/VSMonoTouch/blob/master/VSMonoTouch/VSMonoTouchPackage.cs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜