设置应用程序的输出类型编程 [英] Set application output type programmatically

查看:190
本文介绍了设置应用程序的输出类型编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程使用命令行应用程序的输出类型显示,而控制台的调试信息的应用程序MOGRE 是处理实际窗口创建。我想编译应用程序发布时隐藏控制台。不显示控制台可以很容易地进入项目属性,应用程序选项卡并更改输出类型到Windows应用程序来完成。如果这样做,只有 MOGRE 的窗口将被显示。

I am programming an application using the command line application output type to display debug information in the console while MOGRE is handling the actual window creation. I would like to hide the console when compiling the application for release. Not showing the console can easily be done by going into the project properties, the application tab and change the output type to windows application. When doing that only the MOGRE window will be shown.

虽然我相信这将是清洁,以创建一个Windows应用程序,附加一个控制台来它当一个人希望这样的行为我还是好奇的天气有可能以编程方式做到这一点。

While I believe it would be cleaner to create a windows application and attach a console to it when one wants that behavior I am still curious weather it is possible to do this programmatically.

也就是说,有没有办法以编程方式确定,在调试模式下进行编译时应用程序编译如下命令行应用程序,当在释放模式可以编译为Windows应用程序?如果是的话,怎么可能做到呢?

编辑:我的没有的询问如何控制台连接到Windows窗体应用程序。我把重要组成部分,以斜体希望,希望会更清楚我想要什么的。

I am not asking how to attach a console to a windows forms application. I put the important part in italics out of hope that will make clearer what I want.

推荐答案

您可以做到这一点,如果你手动编辑的.csproj的:

You can achieve this if you edit the .csproj manually:

  • 右键单击在Solution Explorer
  • 项目节点上
  • 选择卸载项目
  • 右键单击在Solution Explorer
  • 项目节点上
  • 选择编辑MyApp.csproj
  • Right click on the project node in Solution Explorer
  • Select "Unload Project"
  • Right click on the project node in Solution Explorer
  • Select "Edit MyApp.csproj"

移动<输出类型../& GT; 从属性组XML元素<的PropertyGroup ... /> XML元素没有条件的属性组条件对应构建配置/平台。

Move the <OutputType ../> property group Xml element from the <PropertyGroup .../> Xml element without Condition to the property group with conditions corresponding to build configuration / platform.

<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...
    <OutputType>Exe</OutputType>
    ...
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    ...
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    ...
  </PropertyGroup>

<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    ...
    <OutputType>Exe</OutputType>
    ...
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    ...
    <OutputType>WinExe</OutputType>
    ...
  </PropertyGroup>

和面漆:

  • 右键单击在Solution Explorer
  • 项目节点上
  • 选择刷新工程

下面是一个证明的例子:

Here is a proof example:

class Program
{
    public static void Main(string[] args)
    {
#if DEBUG
        Console.WriteLine("test");
#else
        Application.Run(new Form1());
#endif
    }
}

它的工作原理,但我不认为这是官方支持,所以使用您自己的风险: - )

It works, but I don't think this is officially supported, so use at your own risk :-)

这篇关于设置应用程序的输出类型编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆