VSIX 如何在代码中获取项目输出类型
VSIX How to get project output type in code
这是我从 project.csproj
获得的 xml 代码
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C5BEBB57-E9AD-4EAF-B7EF-43DF7ACE2B8F}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WpfApplication3</RootNamespace>
<AssemblyName>WpfApplication3</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>...
有什么方法可以将 ot 的值转换为代码中 'WinExe' 的 OutputType 吗?
提前致谢。
我得到的是这样的:
DTE2 DTE = Package.GetGlobalService(typeof(EnvDTE.DTE)) as DTE2;
var project = ((Array)DTE.ActiveSolutionProjects).GetValue(0) as Project;
var properties = project.Properties;
var ot = properties.Item("OutputType").Value.ToString();
prjOutputType po = (prjOutputType)Enum.Parse(typeof(prjOutputType), ot);
您可以使用 ProjectTypeGuids 组合值获取项目类型。例如,您的项目是 WPF C# 项目。可以找到 ProjectTypeGuid 列表 here.
这是我从 project.csproj
获得的 xml 代码<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C5BEBB57-E9AD-4EAF-B7EF-43DF7ACE2B8F}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WpfApplication3</RootNamespace>
<AssemblyName>WpfApplication3</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>...
有什么方法可以将 ot 的值转换为代码中 'WinExe' 的 OutputType 吗?
提前致谢。
我得到的是这样的:
DTE2 DTE = Package.GetGlobalService(typeof(EnvDTE.DTE)) as DTE2;
var project = ((Array)DTE.ActiveSolutionProjects).GetValue(0) as Project;
var properties = project.Properties;
var ot = properties.Item("OutputType").Value.ToString();
prjOutputType po = (prjOutputType)Enum.Parse(typeof(prjOutputType), ot);
您可以使用 ProjectTypeGuids 组合值获取项目类型。例如,您的项目是 WPF C# 项目。可以找到 ProjectTypeGuid 列表 here.