rules_dotnet icon indicating copy to clipboard operation
rules_dotnet copied to clipboard

[Next] Allow targets to have the same name as a package

Open njlr opened this issue 3 years ago • 3 comments

Update

The issue is caused by a Paket package and an fsharp_binary sharing a name ("expecto"). This is easy to work-around (just rename), but it should be possible with the same name.


Note I am experimenting with the next branch:

git_repository(
  name = "rules_dotnet",
  remote = "https://github.com/bazelbuild/rules_dotnet",
  # branch = "next",
  commit = "5fc875093b558a199fbe739f0717dfe09ff626e5",
  shallow_since = "1655891408 +0000",
)

I have defined a test executable like this:

fsharp_binary(
  name = "expecto",
  srcs = [
    "Program.fs",
  ],
  target_frameworks = [ "net6.0" ],
  deps = [
    "@paket.main//microsoft.netcore.app.ref",
    "@paket.main//fsharp.core",
    "@paket.main//expecto",
    "//lib",
  ],
)

When I run this target, I get an assembly load error:

$ bazel run //tests:expecto

...
INFO: Build completed successfully, 1 total action

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Expecto, Version=9.0.4.0, Culture=neutral, PublicKeyToken=null'. Could not find or load a specific file. (0x80131621)
File name: 'Expecto, Version=9.0.4.0, Culture=neutral, PublicKeyToken=null'
 ---> System.IO.FileLoadException: Could not load file or assembly 'Expecto, Version=9.0.4.0, Culture=neutral, PublicKeyToken=null'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at BazelManifest.Resolve(AssemblyLoadContext context, AssemblyName name)
   at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

Full repro is here: https://github.com/njlr/fsharp-monorepo

Any ideas?

njlr avatar Jul 09 '22 15:07 njlr

Haha, I was getting very confused why I could not create a minimal repro of this but then I noticed that the name of your test target is expecto and that leads to the target producing an expecto.dll which clashes with the Expecto.dll that is in the NuGet package. You just need to rename the test target.

I also added an Expecto example to the next branch: https://github.com/bazelbuild/rules_dotnet/pull/295

purkhusid avatar Jul 10 '22 17:07 purkhusid

Yep, renaming it works. Thank you!

I have renamed the title of this issue to reflect the real issue.

njlr avatar Jul 10 '22 17:07 njlr

Just wanted to say thanks for experimenting with the next branch @njlr !

tomdegoede avatar Jul 11 '22 09:07 tomdegoede

I don't think we can fix this. This issue also exists in MSBuild. I tried creating an fsproj called Expecto and got the same issue.

purkhusid avatar Jan 12 '23 08:01 purkhusid