Skip to content

Commit

Permalink
DllExporter がプラットフォームバージョンに対応
Browse files Browse the repository at this point in the history
  • Loading branch information
mfakane committed Aug 2, 2012
1 parent 84bd47a commit 673cd88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions DllExporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static int Main(string[] args)
var input = "";
var output = "";
var il = "";
var version = "v4";

foreach (var i in args)
if (i.StartsWith("/"))
Expand All @@ -48,6 +49,11 @@ static int Main(string[] args)
case "il":
il = sl.Last();

break;
case "v2":
case "v4":
version = sl.Last().Substring(1);

break;
}
}
Expand All @@ -56,7 +62,7 @@ static int Main(string[] args)

if (string.IsNullOrEmpty(input))
{
Console.WriteLine("Usage: DllExporter [/x64] [/debug] [/il:filename] [/out:filename] <assembly>");
Console.WriteLine("Usage: DllExporter [/x64] [/debug] [/il:filename] [/out:filename] [/v2 | /v4] <assembly>");

return 0;
}
Expand Down Expand Up @@ -115,7 +121,7 @@ static int Main(string[] args)
if (!string.IsNullOrEmpty(il))
File.WriteAllText(il, ilcode, encoding);

Assemble(ilcode, output, is64, isDebug);
Assemble(ilcode, output, is64, isDebug, version);

return 0;
}
Expand Down Expand Up @@ -145,7 +151,7 @@ static string GetCallingConvention(CallingConvention callingConvention)
}
}

static void Assemble(string il, string output, bool is64, bool isDebug)
static void Assemble(string il, string output, bool is64, bool isDebug, string version)
{
var temp = Path.GetTempFileName();

Expand All @@ -157,7 +163,7 @@ static void Assemble(string il, string output, bool is64, bool isDebug)
{
StartInfo =
{
FileName = GetAssembler(),
FileName = GetAssembler(version),
Arguments = string.Join(" ", new[]
{
"/nologo",
Expand Down Expand Up @@ -247,9 +253,13 @@ static string Disassemble(string input)
}
}

static string GetAssembler()
static string GetAssembler(string version)
{
return Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "ilasm.exe");
var dir = RuntimeEnvironment.GetRuntimeDirectory().TrimEnd(Path.DirectorySeparatorChar);

dir = Directory.EnumerateDirectories(Path.GetDirectoryName(dir)).LastOrDefault(_ => Path.GetFileName(_).StartsWith("v" + version)) ?? dir;

return Path.Combine(dir, "ilasm.exe");
}

static string GetDisassembler()
Expand Down
2 changes: 1 addition & 1 deletion Tools/PostBuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ exit /b
exit /b

:export
%dllexporter% /%configuration% %il% %dllexporterOptions% %targetPath%
%dllexporter% /%configuration% /%targetplatform% %il% %dllexporterOptions% %targetPath%

if errorlevel 1 (
echo error from DllExporter, batch job failed
Expand Down

0 comments on commit 673cd88

Please sign in to comment.