简体   繁体   中英

Running Main method in Web Application in VS2010

I am writing a web application and there I have created a class with Main method. I am in VS2010.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Dao {
    /// <summary>
    /// Summary description for User
    /// </summary>
    public class User {

        public User() {
            //
            // TODO: Add constructor logic here
            //
        }

        public static void Main(String[] args) {
            Console.WriteLine("JYM");

        }
    }
}

Is there any way to run that particular class's Main() without running the complete application?


The purpose is for testing.

I assume you are trying to write unit test for your applications.

In case if you are using the inbuilt MS-Test for this, you can debug your tests from the Test menu.

Test -> Run -> ....options for running tests...

In the Test results window you can see all the tests and debug using the debug option.

In case if you are using NUnit for this, you need to create a new C# console applicaition and add a reference to the test project and then call the class and methods of your test project in this console applicaiton and debug them.

Visual Studio 2010 a 'Test' menu in the menu bar. Pick 'New Test', and use the wizard. It will make a secondary project that is dependent on your main project, and you are supposed to run the secondary project to run your tests.

At least, it let's me do that for a normal DLL or EXE. I'm not sure about a web application; but you should try it out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM