在Visual Studio宏中进行宏扩展或添加 [英] Macro expansion in Visual Studio macro or add in

查看:180
本文介绍了在Visual Studio宏中进行宏扩展或添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有IntermediateDirectory的VS项目,例如:".... \ temp \ $(SolutionName)\ $(ProjectName)".

I have a VS project with an IntermediateDirectory like this: "....\temp\$(SolutionName)\$(ProjectName)".

我可以使用宏读取或添加该值,但是,我需要实际的目录才能在其中操作文件.现在,我用相应的值手动替换"$(SolutionName)"和"$(ProjectName)",它们虽然可以正常工作,但是当使用不同的宏甚至是属性表中的用户宏时,可能会变得很复杂.

I can read this value using a macro or add in, however, I would need the actual directory to manipulate files there. Right now, I manually replace the "$(SolutionName)" and "$(ProjectName)" with the respective values, which works fine but might become complicated when different macros or even user macros from property sheets are used.

所以我的问题是: Visual Studio API是否具有内置函数来扩展此类宏?还是有其他一些优雅的解决方案?

So my question is: Does the Visual Studio API have a built in function to expand macros like these? Or is there some other elegant solution?

推荐答案

有一个优雅的解决方案!但是我只知道适用于C ++项目的那个.

There is an elegant solution! But I only know the one that applies to C++ projects.

假设您使用的是C#加载项:

Assuming you're in a C# add-in:

//从第一个启动项目中获取主项目

// Get the main project from the first startup project

VCProject vcMainProject =(VCProject)(_ applicationObject.Solution.SolutionBuild.StartupProjects作为IVCCollection).Item(1);

VCProject vcMainProject = (VCProject)(_applicationObject.Solution.SolutionBuild.StartupProjects as IVCCollection).Item(1);

Project mainProj =(Project)_vcMainProject .Object;

Project mainProj = (Project)_vcMainProject .Object;

//获取我们将要使用的配置

// Get the configuration we'll be using

IVCCollection cfgs =(IVCCollection)_vcMainProject .Configurations;

IVCCollection cfgs = (IVCCollection)_vcMainProject .Configurations;

VCConfiguration vcCfg =(VCConfiguration)cfgs.Item(mainProj.ConfigurationManager.ActiveConfiguration.ConfigurationName +"|" + mainProj.ConfigurationManager.ActiveConfiguration.PlatformName);

VCConfiguration vcCfg = (VCConfiguration) cfgs.Item(mainProj.ConfigurationManager.ActiveConfiguration.ConfigurationName + "|" + mainProj.ConfigurationManager.ActiveConfiguration.PlatformName);

string finalString = vcCfg.Evaluate(".... \ temp \ $(SolutionName)\ $(ProjectName)");

string finalString = vcCfg.Evaluate("....\temp\$(SolutionName)\$(ProjectName)");

您也可以查看此页面: http://msdn.microsoft.com/en-us/library/czt44k0x%28VS.71%29.aspx

You can also check out this page: http://msdn.microsoft.com/en-us/library/czt44k0x%28VS.71%29.aspx

如果您不将其用于C ++,则应该为为其他语言(C#和VB)提供的Project,Configuration和Solution类提供类似的接口.

If you're not using this for C++, there should be a similar interface for the Project, Configuration, and Solution classes provided for other languages (C# and VB).

这篇关于在Visual Studio宏中进行宏扩展或添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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