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

5

5

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.

Teratoid answered 5/8, 2012 at 22:6 Comment(0)
H
11

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

For example:

?Program.Test1()
Haustorium answered 5/8, 2012 at 22:24 Comment(2)
+1, for teaching me you can could do this without entering debug mode manually before. Sure to come in handy.Speedball
I was really hoping for something simpler and more organized, but I guess this will have to do for now. Thanks.Teratoid
A
2

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

Astrea answered 6/8, 2012 at 6:55 Comment(1)
This sounds potentially interesting; but it didn't work with VS'12.Teratoid
D
1

You could use resharper and create your tasks as unit tests.

Alternatively, you could write them as macros.

Decolorant answered 5/8, 2012 at 22:14 Comment(0)
I
0

Add command line arguments. Pass in the name of the method, find it from reflection and invoke would be another way. An attribute to decorate methods that this would work for would be a good thing as well.

Irade answered 5/8, 2012 at 22:24 Comment(0)
C
0

You can run such functions as commands with my Visual Commander extension.

Conventional answered 21/6, 2016 at 3:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.