在VS 2010中创建宏 [英] Creating a macro in VS 2010

查看:143
本文介绍了在VS 2010中创建宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个宏,该宏将遍历选定文件夹的每个子文件夹和文件,并对每个文件运行一些宏步骤.我的问题是我有很多字符串资源文件,所有这些文件都是使用自定义创建的 代码生成工具.重新生成文件时,我必须刷新后面的代码,并将构造函数从内部设置为public.这是一些示例宏代码,显示了我正在尝试执行的操作:

子TemporaryMacro()
        DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
        DTE.ActiveWindow.Object.GetItem("SomeFolder \ Globalization \ DefectStatus \ StringsDefectStatusList.resx")).Select(vsUISelectionType.vsUISelectionTypeSelect)
        DTE.Windows.Item("StringsDefectStatusList.resx").Activate()
        DTE.Commands.Raise("{66BD4C1D-3401-4BCC-A942-E4990827E6F7}",8289,内部",自定义)
        DTE.Commands.Raise("{66BD4C1D-3401-4BCC-A942-E4990827E6F7}",8289,"Public",Customout)
        DTE.ActiveDocument.Save()
    结束

切换到内部"然后返回"Public",刷新后面的代码.我的第一个挑战是:宏针对特定文件:

"SomeFolder \ Globalization \ DefectStatus \ StringsDefectStatusList.resx""

但是如何在"SomeFolder \ Globalization"中找到的所有子文件夹中的所有文件上运行此文件?

我的下一个问题是,当我这样做时,构造函数设置为内部-而不是公共.我认为这是VS中的已知错误.我需要查看后面的代码,并替换内部"代码.与公共".有办法吗?

谢谢!

  


moondaddy

解决方案

对于第一个问题,您需要扫描项目中的所有文件以找到所有resx文件.如果是这样,您可以编写递归调用以使用DTE自动化遍历所有项目项.有关更多信息,请检查 http://msdn.microsoft.com/en-us/library/y849h0w1.aspx

对于第二个问题,您可以使用该cs文件的代码模型来搜索并修改代码以从内部"代码中更改代码.转到公开",有关C#代码模式的详细信息,请检查 http://msdn.microsoft.com/en-us/library/ytc6tc9x.aspx

此致

Yi  


I'm trying to create a macro that will loop through every sub folder and file of a selected folder, and run a few macro steps on each file.  My problem is that I have many resource files for strings and all of these files are created using a custom code generation tool.  When the files are re-generated, I have to refresh the code behind and set the constructor from internal to public.  Here's some sample macro code showing what I'm attempting to do:

    Sub TemporaryMacro()
        DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
        DTE.ActiveWindow.Object.GetItem("SomeFolder\Globalization\DefectStatus\StringsDefectStatusList.resx").Select(vsUISelectionType.vsUISelectionTypeSelect)
        DTE.Windows.Item("StringsDefectStatusList.resx").Activate()
        DTE.Commands.Raise("{66BD4C1D-3401-4BCC-A942-E4990827E6F7}", 8289, "Internal", Customout)
        DTE.Commands.Raise("{66BD4C1D-3401-4BCC-A942-E4990827E6F7}", 8289, "Public", Customout)
        DTE.ActiveDocument.Save()
    End Sub

by toggling to "Internal" and back to "Public", the code behind is refreshed. My first challange is: Here the macro targets the specific file:

"SomeFolder\Globalization\DefectStatus\StringsDefectStatusList.resx"

But how do I run this on all files in all sub folders found in "SomeFolder\Globalization"?

My next problem is when I do this, the constructor is set to internal - not public.  I think this is a known bug in VS.  I need to go into the code behind and replace "internal" with "public".  is there a way to do this?

Thanks!

   


moondaddy

解决方案

Hi

For your first question, you need to scan all files in your project to find all resx file. If so, you can write a recursive call to go through all project items using DTE automation. For more information, check http://msdn.microsoft.com/en-us/library/y849h0w1.aspx

For your second question, you can use code model of that cs file to search and modify the code to change the code from "Internal" to "public", the detail information about C# code mode, please check http://msdn.microsoft.com/en-us/library/ytc6tc9x.aspx

Regards,

Yi 


这篇关于在VS 2010中创建宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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