Not
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Alla Windows PowerShell modul eller cmdlet kan paketeras som en arbetsflödesaktivitet med hjälp av metoderna i klassen Microsoft.Powershell.Activities.Activitygenerator. Använd Microsoft.Powershell.Activities.Activitygenerator.Generatefrommoduleinfo*, Microsoft.Powershell.Activities.Activitygenerator.Generatefromcommandinfo*, och Microsoft.Powershell.Activities.Activitygenerator.Generatefromname*- metoderna i klassen Microsoft.Powershell.Activities.Activitygenerator för att generera C#-kod som representerar en aktivitet. Du kan sedan kompilera den resulterande C#-koden till en sammansättning som kan läggas till i ett projekt som en aktivitet.
Du kan sedan kompilera den resulterande C#-koden till en sammansättning som kan läggas till i ett projekt som en aktivitet med hjälp av en kommandorad med följande formulär.
csc /nologo /out:AssemblyName /target:library /reference:System.Activities.Activity /reference:Microsoft.PowerShell.Activities codefile.cs
Exempel 1
I följande exempel visas hur du genererar C#-kod för en aktivitet från en Windows PowerShell modul.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Management.Automation;
using System.Collections.ObjectModel;
using Microsoft.PowerShell.Activities;
namespace MakeActivity
{
class Program
{
static void Main(string[] args)
{
StreamWriter CodeFile = new StreamWriter("c:\\\\testmodule\\codefile.cs");
Collection<PSModuleInfo> ModuleInfos = new Collection<PSModuleInfo> { };
PSModuleInfo ModuleInfo;
string ActivityCode = "";
string ModulePath = "";
Console.Write("Type the full path and filename of the module to process:");
ModulePath = Console.ReadLine();
PowerShell ps = PowerShell.Create();
ps.AddCommand("Import-Module").AddArgument(ModulePath);
ps.AddParameter("PassThru");
ModuleInfos = ps.Invoke<PSModuleInfo>();
ModuleInfo = (PSModuleInfo)ModuleInfos[0];
ActivityCode = ActivityGenerator.GenerateFromModuleInfo(ModuleInfo, "MyNamespace").First<String>();
CodeFile.Write(ActivityCode);
Console.ReadLine();
}
}
}
Exempel 2
I följande exempel visas hur du genererar C#-kod för en aktivitet från en Windows PowerShell cmdlet.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Management.Automation;
using System.Collections.ObjectModel;
using Microsoft.PowerShell.Activities;
namespace MakeActivity
{
class Program
{
static void Main(string[] args)
{
StreamWriter CodeFile = new StreamWriter("c:\\\\testmodule\\codefile.cs");
Collection<PSModuleInfo> ModuleInfos = new Collection<PSModuleInfo> { };
PSModuleInfo ModuleInfo;
Collection<CommandInfo> CommandInfos = new Collection<CommandInfo> { };
CommandInfo MyCommand;
string ActivityCode = "";
string ModulePath = "";
Console.Write("Type the full path and filename of the module to process:");
ModulePath = Console.ReadLine();
PowerShell ps = PowerShell.Create();
ps.AddCommand("Import-Module").AddArgument(ModulePath);
ps.AddParameter("PassThru");
ModuleInfos = ps.Invoke<PSModuleInfo>();
ModuleInfo = (PSModuleInfo)ModuleInfos[0];
ps.AddCommand("Get-Command").AddArgument(ModuleInfo);
CommandInfos = ps.Invoke<CommandInfo>();
MyCommand = CommandInfos[0];
ActivityCode = ActivityGenerator.GenerateFromCommandInfo(MyCommand, "MyNamespace");
CodeFile.Write(ActivityCode);
Console.ReadLine();
}
}
}