VS 2010将非GUI类文件设置为Component

我有一个烦恼已经发生了很长一段时间与Visual Studio 2010.我有一个类文件,我做了VS保存为类型“组件”无缘无故我能辨别。 如果我忘记并尝试打开文件,它会查找不存在的设计器。

我查看了Google并发现了VS 2005的一些类似问题,但问题似乎与从GUI组件类(listbox,combobox等)派生有关。 这堂课不这样做。

该文件是GpsUtilities.cs 。 它出现在csproj文件中,如下所示, SubTypeComponent 。 没有其他对该文件的引用,即没有任何声明它作为DependentUpon

  Component  

即使我删除了SubType标记,即使我明确地将其设置为Code而不是Component ,它仍然将其保存为Component SubType

这是类结构(所有代码都被删除)。 正如我所说,它不会inheritance,甚至不会导入与GUI相关的任何名称空间。

 using System; using System.ComponentModel; using System.IO.Ports; using System.Text.RegularExpressions; using System.Timers; using System.Xml.Serialization; namespace AppNamespace { public class GpsUtil : INotifyPropertyChanged { public GpsUtil() { } public static GpsUtil CreateInstance() { } public bool IsGpsReady { get; } public GPSPort GpsSerialPort { get; private set; } public Timer GpsTimer { get; set; } private CircularArray PositionBuffer { get; set; } private GpsPositionData m_GpsCurLoc; public GpsPositionData MyLocation { } public string GpggaPattern { get; set; } public Regex GpggaRegEx { get; set; } public GpsPositionData GpsPosDataFromRegExMatch(Match gpsRegExMatch) { } public void SetGpsPosition(double latitude, double longitude) { } private void gpsTimer_Elapsed(object sender, ElapsedEventArgs e) { } private bool InitializeGpsPort() { } public bool TestGpsPort() { } public double ComputeSquaredDistance(double startLat, double startLon, double endLat, double endLon) { } public event PropertyChangedEventHandler PropertyChanged; } public class GPSPort : SerialPort { public GPSPort(string portName, int baudRate = 9600) : base(portName, baudRate) { } private bool TestResult { get; set; } public bool Test(int interval = 3000, bool leavePortOpen = false) {} } public enum GpsFixQuality { Invalid = 0, GpsFix = 1, DgpsFix = 2 } [Serializable] public class GpsPositionData { public GpsPositionData() { } public GpsPositionData(double latitude, double longitude) {} public override string ToString() {} public bool IsCloseTo(GpsPositionData otherPoint, double tolerance = 0.0001) {} public GpsPositionData(DateTime time, double latitude, double longitude, GpsFixQuality fixQuality, int numberOfSatellites, double hdop, double altitude, double geodialSeparation, int ageOfDgps, string dgpsRefStationId){} [XmlIgnore] public DateTime Time { get; private set; } [XmlElement("Latitude", typeof(double))] public double Latitude { get; set; } [XmlElement("Longitude", typeof(double))] public double Longitude { get; set; } [XmlIgnore] public GpsFixQuality FixQuality { get; private set; } [XmlIgnore] public int NumberOfSatellites { get; private set; } [XmlIgnore] public double Hdop { get; private set; } [XmlIgnore] public double Altitude { get; private set; } [XmlIgnore] public double GeodialSeparation { get; private set; } [XmlIgnore] public int AgeOfDgps { get; private set; } [XmlIgnore] public string DgpsRefStationId { get; private set; } } } 

提前致谢。

如果要将所有类保留在一个文件中,可以使用GPSPort类上的[System.ComponentModel.DesignerCategory("Code")]属性来覆盖默认行为。 这里的详细信息 ,请注意,即使您using System.ComponentModel语句也必须使用完全限定属性,否则VS将忽略它。

猜测一下,我会说这是由于你的GPSPort类,它扩展了SerialPort ,扩展了Component 。 尝试删除它(或将其移动到单独的文件中),看看它是否解决了问题。