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

眉间皱痕 提交于 2019-12-11 04:13:19

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6004928/visual-studio-2010-extensibility-override-build-action-without-effecting-cproj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!