简体   繁体   English

如何获取当前Active Solution Platform名称以在Visual Studio加载项中使用? (C#)

[英]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.

相关问题 C# Visual Studio Excel 加载项:如何检测 Excel Office 主题更改? - C# Visual Studio Excel Add-in: How can I detect Excel Office Theme Change? 如何在Visual Studio加载项中获取文件的项目名称? - How to get project name of file in visual studio add-in? Visual Studio的C#interpreter加载项 - C# interpreter add-in for visual studio 如何从C#项目的构建事件中访问Visual Studio解决方案级平台? - How can you access the Visual Studio solution level platform from a C# project's build event? 如何以编程方式获取有关其他解决方案的信息或进行操作? (Visual Studio,C#) - How can I programmatically get information about or manipulate another solution? (Visual Studio, C#) 如何在Visual Studio中使用C#在解决方案中轻松获取文件夹内文件的路径? - How can I easily get the path of a file inside a folder in my solution in Visual Studio with C#? 如何使用 c# 在 Visual Studio 2010 中以编程方式将现有项目添加到当前解决方案 - How to add an existing project to a current solution programmatically in visual studio 2010 using c# 如何从 Visual Studio Package 项目中获取当前的解决方案名称? - How to get the current solution name from a Visual Studio Package project? Visual Studio加载项:如何知道解决方案何时完成加载 - Visual Studio Add-In: How do I know when a solution has finished loading 如何在 Visual Studio 2022 中链接 C# 的库 package 以便我每次都可以在任何解决方案或项目中使用它? - How to link a library package of C# in Visual Studio 2022 so that I can use it every time in any solution or project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM