Brightspace / rules_csharp

Bazel rules for C#
Apache License 2.0
8 stars 5 forks source link

bazel run/bazel test only work in specific circumstances #9

Open j3parker opened 5 years ago

j3parker commented 5 years ago

Normally in C# you put all of your DLLs in one folder, and they are loaded based on filename (the full details are more complex).

In Bazel, when you have a target with dependencies in a different folder it will fail to run because the DLL can't be found.

Solutions that probably won't work:

What I think will work:

Have an extra action that produces a shim exe, and also write the real exe path and the list of transitive dependencies to a txt file. The shim exe's Main function:

  1. Reads the txt file into a read only dictionary from Path.GetFilenameWithoutExtension to the path to the DLL
  2. hooks into the AssemblyLoad event and uses the list from (1) to resolve DLLs
  3. Loads the real exe assembly
  4. Calls the real Main( args ) (caution: Main() vs Main( string[] args ).. the runner would need to do the right thing).

In our DefaultInfo for executable rules we point at that shim, with the txt file as a runfile.

This probably makes sense to do after #8 because we should only need to make this exe once (probably for the latest .NET Core version?) but we could also do it for just .NET Framework first too.

j3parker commented 5 years ago

I've got this broadly working but it doesn't make sense to check in until we support net48 + netcoreapp2.1 (the newest target frameworks that can produce exes).

I'm still investigating how runfiles work under the hood to see what stuff we have to DIY.