in src/dotnet/ReSharperPlugin.DotNetDisassembler/JitDisasm/LoaderAppManager.cs [28:90]
public static async Task InitLoaderAndCopyToAsync(string dotnetCliExePath, string tf, string dest, Action<string> logger, Version addinVersion, CancellationToken ct)
{
if (!Directory.Exists(dest))
throw new InvalidOperationException($"ERROR: dest dir was not found: {dest}");
string dir;
try
{
logger("Getting SDK version...");
dir = await GetPathToLoaderAsync(dotnetCliExePath, tf, addinVersion, ct);
}
catch (Exception exc)
{
throw new InvalidOperationException("ERROR in LoaderAppManager.GetPathToLoader: " + exc);
}
string csproj = Path.Combine(dir, $"{JitDisasmLoaderName}.csproj");
string csfile = Path.Combine(dir, $"{JitDisasmLoaderName}.cs");
string outDll = Path.Combine(dir, "out", $"{JitDisasmLoaderName}.dll");
string outJson = Path.Combine(dir, "out", $"{JitDisasmLoaderName}.runtimeconfig.json");
string outDllDest = Path.Combine(dest, JitDisasmLoaderName + ".dll");
string outJsonDest = Path.Combine(dest, JitDisasmLoaderName + ".runtimeconfig.json");
if (File.Exists(outDllDest) && File.Exists(outJsonDest))
{
return;
}
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
else if (File.Exists(outDll) && File.Exists(outJson))
{
File.Copy(outDll, outDllDest, true);
File.Copy(outJson, outJsonDest, true);
return;
}
logger($"Building '{JitDisasmLoaderName}' project...");
ct.ThrowIfCancellationRequested();
if (!File.Exists(csfile))
TextUtils.SaveEmbeddedResourceTo($"{JitDisasmLoaderName}.cs_template", dir);
if (!File.Exists(csproj))
TextUtils.SaveEmbeddedResourceTo($"{JitDisasmLoaderName}.csproj_template", dir, content => content.Replace("%tfm%", tf));
Debug.Assert(File.Exists(csfile));
Debug.Assert(File.Exists(csproj));
ct.ThrowIfCancellationRequested();
var msg = await ProcessUtils.RunProcessAsync(dotnetCliExePath, "build -c Release", workingDir: dir, cancellationToken: ct);
if (!File.Exists(outDll) || !File.Exists(outJson))
throw new InvalidOperationException($"ERROR: 'dotnet build' did not produce expected binaries ('{outDll}'" +
$" and '{outJson}'):\n{msg.Output}\n\n{msg.Error}");
ct.ThrowIfCancellationRequested();
File.Copy(outDll, outDllDest, true);
File.Copy(outJson, outJsonDest, true);
}