I can use the following p-invoke code on Windows, but is there a cross-platform way to create a symbolic link with .NET Core? (3.0 preview if that matters)
If not, is there a way to p-invoke or similar on linux/ubuntu to do it?
public static class PinvokeSymLink
{
[DllImport( "kernel32.dll" )]
public static extern bool CreateSymbolicLink( string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags );
public enum SymbolicLink
{
File = 0,
Directory = 1
}
}
Since .NET 6, the File.CreateSymbolicLink
is available for this purpose.
For the older .NET versions, you can consider p-invoking the symlink
Linux function instead. This worked for me on both Linux and macOS.