簡體   English   中英

如何知道VS項目是否屬於WEB應用程序或Windows應用程序

[英]How to know if a VS Project belongs to a WEB Application or Windows Application

我正在使用C#Microsoft.Build.Evaluation.Project類從VS項目文件(如TargetFramework,AssemblyName ...等)中檢索特定信息。 但是我找不到方法或屬性名稱來標識該項目是否為Web項目。 對於框架1.1中的VS Project,我正在使用Xml解析。

string path = "C:\\Test.csproj";
XElement root = XElement.Load(path);
var type = from el in root.Elements("CSHARP")
           select el.Attribute("ProjectType");
if (type.Count() > 0)
{
  //  Local or Web
  return((XAttribute)type.First()).Value);
}

如果有人可以給我財產的名稱或解決該問題的其他建議,我將不勝感激。

提前致謝。

我的完整方法代碼

public bool IsWeb(string path)
    {
        bool isWeb = false;
        try
        {

            Project project = new Project(path);

            // I dont know the name of the propety to identify if its a web project

            //string type = project.GetPropertyValue();
            //if (type.Equals("Web"))
            //{
            //    isWeb = true;
            //}

        }
        catch (InvalidProjectFileException)
        {
            //It's fw 1.1
            XElement root = XElement.Load(path);
            var type = from el in root.Elements("CSHARP")
                       select el.Attribute("ProjectType");

            if (type.Count() > 0)
            {
                if ((((XAttribute)type.First()).Value).Equals("Web"))
                {
                    isWeb = true;
                }
            }

        }
        return isWeb;
    }

您可以檢查項目類型guid是否屬於已知類型之一

我瀏覽了一些項目文件。 在我的一個mvc項目中,我在PropertyGroup節點<MvcBuildViews>發現了這個節點,它絕對不是您問題的最終答案,但看起來比您正在使用的信息更多。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM