如何在代码中读取输出类型 [英] How to read the Output Type in code

查看:37
本文介绍了如何在代码中读取输出类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个常见的麻烦是,我们必须在下面切换此代码,具体取决于我们是在本地测试还是在为构建服务器提交代码.

A common nuisance we have is having to switch this code below depending on whether we are testing locally or committing code for the build server.

    /// <summary>
    /// Main entry point to the application.
    /// </summary>
    public static void Main()
    {
        // Don't forget to uncomment this if committing (!)
        //var servicesToRun = new ServiceBase[] {new myservice()};
        //ServiceBase.Run(servicesToRun);

        // and re-comment this
        RunAsConsoleApp();

    }

如果有一种方法可以在代码中进行测试以告知输出类型,即避免所有的哦,不,我犯了错,并破坏了构建"的时间,那将是非常有用的.

It would be really useful if there was a way to test in the code to tell the output type i.e, and avoid all the 'oh-no I committed and broke the build' time wasting.

        if (IsConsoleApp)
        {
            Using(var host= new ServiceHost(typeof(myservice))
            {
               host.Open();
               etc....
            }
        }
        else
        {
            var servicesToRun = new ServiceBase[] {new myservice()};
            ServiceBase.Run(servicesToRun);
        }

推荐答案

您是否尝试过使用

Have you tried using the Environment.UserInteractive property in place of IsConsoleApp?

这篇关于如何在代码中读取输出类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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