Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any extension to visual studio that allows to run functions as tasks? [closed]

Often I have a bit of code I want to execute from time to time, for example seed the database, drop the database, download some data from the database and collate it in some funny way. All of these tasks can be represented as independent functions in C#.

Ala a console app:

class Program{
      static void Task1(){}
      static void Task2(){}
      static void Main(){
          //Task1();
          //Task2();
      }
}

Here, I comment out the function I don't want to call, and run the function I do want to call. Compile and wait for results.

I'm looking for a way to streamline this process. For example in unit testing you can right click a function and through some magic execute just that function directly from Visual Studio.

Maybe there is an extension that does just this, but I haven't been able to find it. Best way I know of cleaning this so far, is to make snippets in LinqPad. But I feel like I should be able to do this directly from Visual Studio.

like image 950
Gleno Avatar asked Aug 05 '12 22:08

Gleno


People also ask

How do I run a function in Visual Studio?

Visual Studio Code integrates with Azure Functions Core tools to let you run this project on your local development computer before you publish to Azure. To call your function, press F5 to start the function app project. The Terminal panel displays the output from Core Tools.

Where is all todo in Visual Studio?

From within Visual Studio Go to View -> Task List. This will display the Task List window and show you any area of your open Solution that has existing comments that start with // TODO . You can filter down to your Current Project, Current Document, or Open Documents. It even will allow you to search the list.

What is task list in Visual Studio?

Use Task List to track code comments that use tokens such as TODO and HACK , or custom tokens, and to manage shortcuts that take you directly to a predefined location in code. Click on the item in the list to go to its location in the source code. Note. This topic applies to Visual Studio on Windows.

How do you todo in C#?

TODO comments allow Visual Studio to maintain a central list of tasks, which it reads from many different places. The Task List shows all the TODO comments in your project. Tip To open the list, go to View, and then Task List. A recent version of Visual Studio is needed.


2 Answers

You can always execute them directly in the Immediate window, even without the application running.

For example:

?Program.Test1()
like image 171
competent_tech Avatar answered Nov 03 '22 00:11

competent_tech


TestDriven.NET supports running arbitrary methods as ad-hoc tests. It works for both static and instance methods without parameters.

like image 28
Bojan Resnik Avatar answered Nov 02 '22 23:11

Bojan Resnik