2

I am pretty new in .NET\C# (I came from Java) and I have the following doubt.

In my solution I have a project that should be a SharePoint job, something like this in my solution explorer:

enter image description here

I know that this project is deployed as a SharePoint job and it works fine.

Now I have the need to manually perform a specific operation that is in some way related to this job. So my idea was to create this MigrateAttachments class into this project and put a Main() method here, then perform only this class as a script:

namespace XXXMigrationJob
{
    class MigrateAttachments
    {
        static void Main(string[] args)
        {

            Debug.Print("MigrateAttachments Main() START");

            Debug.Print("MigrateAttachments Main() END");
        }
    }
}

But it seems to me that I can't perform this Main() method as a standalone method and that the only way to do it is to create a brand new Console Application project that will contain this class.

is it true or am I missing something and I can manually run this MigrateAttachements Main() method also into my XXXMigrationJob project?

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • 3
    Possible duplicate of [Can I run code from a .NET assembly from a command line?](https://stackoverflow.com/questions/6813557/can-i-run-code-from-a-net-assembly-from-a-command-line) – NineBerry May 23 '19 at 08:23

1 Answers1

1

No you can't really just execute that. It will be in a DLL not an exe. You'll need to bootstrap it somehow.

I would refactor the reusable code into a class library. Then create a console app as you mentioned. Reference the reusable class library and call it.

However if you don't want to create a console app, then the link NineBerry put in discusses calling .net code with PowerShell and Reflection.

TimW
  • 126
  • 4