Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cannot find csc.exe when running in Unity #196

Open
DemaCya opened this issue Oct 29, 2024 · 2 comments
Open

Cannot find csc.exe when running in Unity #196

DemaCya opened this issue Oct 29, 2024 · 2 comments

Comments

@DemaCya
Copy link

DemaCya commented Oct 29, 2024

Unity reports an error when using ProcessTemplateAsync: TemplatingEngineException: Could not find csc in host Mono installation.I tried 2019.4.22 and 2022.3.24, and also tried Mono's .Net Standard 2.0/2.1, .Net Framework, and .Net 4.8, but I still get this error. I imported it using NuGetForUnity and used it directly.What am I doing wrong? I'm really upset.

@mhutch
Copy link
Contributor

mhutch commented Nov 15, 2024

When running in the Mono runtime, it looks for csc.exe in the same directory as the executing assembly that contains System.Object: https://github.com/mono/t4/blob/main/Mono.TextTemplating/Mono.TextTemplating.CodeCompilation/RuntimeInfo.cs#L106

Presumably Unity's bundled version of Mono is modified and differs from the standard layout. If you can provide alternate logic, I'd be happy to integrate it.

@mhutch mhutch changed the title TemplatingEngineException: Could not find csc in host Mono installation. Cannot find csc.exe when running in Unity Nov 15, 2024
@indie-hub
Copy link

Hello!
Because I faced the same issue, here's a "possible" solution.

var runtimeDir = Path.GetDirectoryName (typeof (object).Assembly.Location);
var csc = Path.Combine (runtimeDir, "csc.exe");
if (!File.Exists (csc)) {
  var parentRuntimeDir = Path.Combine (runtimeDir, "..");
  string[] cscs = Directory.GetFiles (parentRuntimeDir, "csc.exe", SearchOption.AllDirectories);
  
  if (!cscs.Any()) {
	  return FromError (RuntimeKind.Mono, "Could not find csc in host Mono installation");
  }
  
  csc = cscs[0];
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants