[英]How can I get the current Active Solution Platform name for use in a Visual Studio add-in? (C#)
I am creating a Visual studio add-in writing in C# allowing users to send their code to a remote PC for parsing. 我正在用C#创建一个Visual Studio插件,允许用户将他们的代码发送到远程PC进行解析。 The process will differ depending on what Active Solution Platform is being used. 该过程将根据使用的Active Solution Platform而有所不同。
I would like the add-in to be able to obtain the current Active Solution Platform so the users code can be processed correctly. 我希望加载项能够获取当前的Active Solution Platform,以便正确处理用户代码。
I tried the following: 我尝试了以下方法:
try
{
SolutionBuild builder = applicationObject.Solution.SolutionBuild;
SolutionConfiguration2 config;
config = (SolutionConfiguration2)builder.SolutionConfigurations.Item(1);
MessageBox.Show("The platform name of
the solution configuration is: " + config.PlatformName);
}
catch(SystemException ex)
{
MessageBox.Show(ex.ToString());
}
However this always returns the first Platform in the list, not the current platform. 但是,这始终返回列表中的第一个平台,而不是当前平台。
To get the active solution config and platform use this 要获得活动解决方案配置和平台,请使用此功能
string active_config = (string)addin_inst.DTE.Solution.Properties.Item("ActiveConfig").Value;
This will get a string of the form "Debug|Win32". 这将获得“Debug | Win32”形式的字符串。 The platform will be after the '|' 该平台将在'|'之后
This will get the configuration name and platform name for the active project. 这将获取活动项目的配置名称和平台名称。
object[] openProjects = (object[])applicationObject.ActiveSolutionProjects;
Project activeProject = (Project)openProjects[0];
string configurationName = activeProject.ConfigurationManager.ActiveConfiguration.ConfigurationName;
string platformName = activeProject.ConfigurationManager.ActiveConfiguration.PlatformName;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.