I'm playing around with powershell and C#.
Specifically I'm using the Add-Type
command to compile C# code to a .dll
file.
But here's the problem: to run the .dll
It would need either an entry point or an export as I understand it, to call functions from it.
To create these exports I found the UnmanagedExports Package. With this I was able to create some exports. Next I wanted to compile this as a .dll
file and try to run it. Let me give you an example code.
$code = @'
using System;
using System.Net;
using System.IO;
using System.Diagnostics;
using RGiesecke.DllExport;
namespace HelloWorldll
{
class Program
{
[DllExport("DllMain", CallingConvention = CallingConvention.Winapi)]
public static void DllMain()
{
Console.WriteLine("Hello World");
}
}
}
'@
$FilePath = "C:\Some\Path\To\File.dll"
Add-Type -TypeDefinition $code -OutputAssembly $FilePath
The problem is the RGiesecke namespace is not recognized in Powershell, So I had the main question is.
Is there another way to Create/Define Exports WITHOUT 3rd party software/tools? Is there a way/command to install the package INSIDE THIS POWERSHELL SCRIPT before compiling to make sure this package is found?
I also read this but didn't help me as much so perhaps someone could pick up ideas to help me from here but so far I have none. install NuGet via PowerShell script
Current Error Compiling:
Add-Type : c:\Users...\AppData\Local\Temp\ahkmqrli.0.cs(6) : The typen or namespace name 'RGiesecke' could not be found (are you missing a using directive or an assembly reference?)