控制台在类库 c# 中不可用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9675850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 08:24:45  来源:igfitidea点击:

Console unavailable in class library c#

c#consoleclass-library

提问by Adam Schiavone

This question hereseems contrary to what I have experienced. I cannot access the console from within a new class library. I have using System;at the top. I am using visual studio 11 on windows 8. I doubt that this has been lost in the update, so that means that I am doing something wrong.

这里的这个问题似乎与我所经历的相反。我无法从新的类库中访问控制台。我using System;在顶部。我在 Windows 8 上使用 Visual Studio 11。我怀疑这在更新中丢失了,所以这意味着我做错了什么。

Also, once this is working, is the console available in a portable class library?

此外,一旦这工作正常,可移植类库中是否可以使用控制台?

EDIT

编辑

here is just a test file I made

这只是我制作的一个测试文件

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

namespace AdamLib.util.ConsoleSupport
{
    class SafeRead
    {
        private void test()
        {
            System.Console.Writeline("test"); //Console is not found in system
        }
    }
}

This is in the class library.

这是在类库中。

RESOLVED

解决

Like I thought, it was my fault.

就像我想的那样,这是我的错。

Thanks to @DarinDimitrov, who pointed out that with VS 11 and metro, Console support has been removed for use with metro. So to resolve this I needed to create a new project with the second kind of class library. There are two listed and I used the one withthe description that includes metro. To resolve the issue, I had to use the other type withoutmetro in the description.

感谢@DarinDimitrov,他指出在 VS 11 和 Metro 中,Console 支持已被删除以用于 Metro。所以为了解决这个问题,我需要用第二种类库创建一个新项目。有两家上市和我用一个包括地铁的说明。为了解决这个问题,我不得不在描述中使用没有地铁的其他类型。

Thanks again to all that helped.

再次感谢所有帮助。

采纳答案by Darin Dimitrov

If you created a Metro style application, there's no Console in WinRT. Don't search for it as you won't find any. This is explained in this article:

如果您创建了 Metro 风格应用程序,则 WinRT 中没有控制台。不要搜索它,因为你不会找到任何。这在这篇文章中有解释:

The subset of managed types and members was designed with a clear focus on Metro style app development. As a result, it omits the following:

  • Types and members that are not applicable to developing Metro style apps (such as console and ASP.NET types).

  • Obsolete and legacy types.

  • Types that overlap with Windows Runtime types.

  • Types and members that wrap operating system functionality (such as System.Diagnostics.EventLog and performance counters).

  • Members that cause confusion (such as the Close method on I/O types).

托管类型和成员的子集在设计时明确关注 Metro 风格应用程序开发。因此,它省略了以下内容:

  • 不适用于开发 Metro 风格应用的类型和成员(例如控制台和 ASP.NET 类型)。

  • 过时和遗留类型。

  • 与 Windows 运行时类型重叠的类型。

  • 包装操作系统功能的类型和成员(例如 System.Diagnostics.EventLog 和性能计数器)。

  • 引起混淆的成员(例如 I/O 类型的 Close 方法)。

You could use the debugging APIor logging framework.

您可以使用调试 API或日志记录框架。