Visual Studio 2010 可扩展性 - 覆盖构建操作而不影响 cproj 文件 [英] Visual Studio 2010 Extensibility - Override Build Action without effecting cproj file

查看:27
本文介绍了Visual Studio 2010 可扩展性 - 覆盖构建操作而不影响 cproj 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一种无需更改 cproj 文件即可在 Visual Studio 2010 中构建 MonoTouch 项目的方法.我快到了,但最后一步是在 MonoTouch 项目中具有构建操作Page"的 *.xib 文件.

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.

在 Visual Studio 2010 bild action Page 将调用 XAML 编译器,因此为了在 VS2010 中构建项目,我需要将构建操作设置为 None.这样做的问题是 .cproj 文件已更改,在 MonoTouch 中构建之前,我需要将其设置回 Page.

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.

所以我的问题是这样的.使用 Visual Studio 可扩展性模型,是否可以拦截"某些文件类型并忽略"它们或更改它们的构建类型?还是 Visual Studio 使用 msbuild 构建所有内容,因此只关心 .cproj 文件中实际写入的内容?

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?

推荐答案

我最终使用稍微不同的策略解决了这个问题.您可以在 DTE 对象上侦听不同的构建事件,并在构建前后在 Visual Studio 2010 扩展中运行代码.

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;

使用此策略,我可以在构建前将构建操作更改为 None,然后在构建后返回 Page.更改构建类型的代码简单地枚举了解决方案中的所有项目,以及项目中的所有项目项.它查找所有扩展名为 .xib 的文件,并使用以下代码更改构建操作:

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";

完整的实现可以在 https://github.com/follesoe/VSMonoTouch/blob/master/VSMonoTouch/VSMonoTouchPackage.cs.

这篇关于Visual Studio 2010 可扩展性 - 覆盖构建操作而不影响 cproj 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆