c# - Visual Studio 2013 将我的文件解释为表单文件

标签 c# visual-studio-2013

我用一个类创建简单的 cs 文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Bed
{
    public class TimeoutWebClient : WebClient
    {
        protected override WebRequest GetWebRequest(Uri uri)
        {
            WebRequest w = base.GetWebRequest(uri);
            w.Timeout = 30 * 1000;
            return w;
        }
    }
}

突然间,我的 Visual Studio 将其解释为一个表单类。我哪里出错了?

VS screen

这些是我使用的版本:

Microsoft Visual Studio Ultimate 2013
Version 12.0.21005.1 REL
Microsoft .NET Framework
Version 4.5.50938

最佳答案

我不确定它是怎么发生的,但我是这样解决的:

  • 右键单击项目并选择“卸载”
  • 右键单击项目并选择“编辑”
  • 在文件“TimeoutWebClient”中找到

我希望你能找到这样的东西:

 <ItemGroup>
    <Compile Include="TimeoutWebClient.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="TimeoutWebClient.Designer.cs">
      <DependentUpon>TimeoutWebClient.cs</DependentUpon>
    </Compile>
    <!-- other files go here -->

删除 SubType标签。如果您还想撤消任何依赖项,请删除 <DependentUpon>标签也是如此。

保存您的项目文件,右键单击它并选择“重新加载”。
验证您是否达到了所需。

关于c# - Visual Studio 2013 将我的文件解释为表单文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23180941/

相关文章:

c++ - 为什么只执行最后一个线程?

c++ - 如何设置 freeGLUT 和 GLEW 以在 Visual Studio 2013 中使用?

visual-studio - 每次进行临时更改时,如何阻止 Visual Studio 询问是否要保存解决方案文件?

c# - 检测哈希表或字典中的重新散列或冲突

c# - 使用 MSTest 和 Fakes (Shim) 填充 .Net System.Windows.Forms.Screen 构造函数以进行单元测试

c# - ViewModel 中的构造函数

sql-server - 多环境场景TFS/SSDT部署

c# - 创建一个 IObservable 并立即返回缓存异步操作的结果

c# - 仅在 using 语句范围内创建和使用时的对象生命周期

c++ - 如何编译没有项目文件的C++源代码?