rules_dotnet icon indicating copy to clipboard operation
rules_dotnet copied to clipboard

Question: is there a way to use the `dotnet` executable

Open njlr opened this issue 2 years ago • 6 comments

The context is to be able to execute pre-built assemblies with dotnet.

I noticed a substitution variable here:

https://github.com/bazelbuild/rules_dotnet/blob/5c95c346d2b362d56eeada72bdf9d42395eae405/dotnet/toolchain.bzl#L91

Is there an example of how to use it, e.g. in a genrule?

njlr avatar Jul 21 '22 18:07 njlr

Some progress...

genrule(
  name = "test",
  outs = [ "out.txt" ],
  cmd = "echo \"$(DOTNET_BIN)\" > $@",
  toolchains = [
    "@dotnet_toolchains//:resolved_toolchain",
  ],
)

cat ./bazel-bin/out.txt 
external/dotnet_x86_64-unknown-linux-gnu/dotnet

njlr avatar Jul 21 '22 20:07 njlr

We do something similar in our private repository by just invoking bazel run @core_sdk//:dotnet.exe commands. I'm not sure where it'll be located for you but I'm sure you should be able to do the same. Probably there will be an external repo for your current platform such as dotnet_x86_64-pc-windows-msvc, but we could simply expose a .sh and .bat file to proxy it via a more generic name.

tomdegoede avatar Jul 21 '22 20:07 tomdegoede

Do you want to use dotnet.exe from within a bazel action or just from the commandline? You could also look into importing the prebuilt binaries as a rules_dotnet executable.

tomdegoede avatar Jul 21 '22 20:07 tomdegoede

I think we are missing an import_binary rule here https://github.com/bazelbuild/rules_dotnet/blob/next/dotnet/private/rules/imports.bzl

tomdegoede avatar Jul 21 '22 20:07 tomdegoede

Some progress...

genrule(
  name = "test",
  outs = [ "out.txt" ],
  cmd = "echo \"$(DOTNET_BIN)\" > $@",
  toolchains = [
    "@dotnet_toolchains//:resolved_toolchain",
  ],
)
cat ./bazel-bin/out.txt 
external/dotnet_x86_64-unknown-linux-gnu/dotnet

This should work but you also need to add

tools= [
    "@dotnet_toolchains//:resolved_toolchain",
  ],

purkhusid avatar Aug 23 '22 19:08 purkhusid

@njlr Did you get this to work? Going to close this issue if the template variables worked as expected.

purkhusid avatar Aug 31 '22 15:08 purkhusid

Closing this for now since there was no response

purkhusid avatar Jan 05 '23 12:01 purkhusid

I'm having a bit of trouble here; i'm trying to use the dotnet executable to invoke a dotnet-tool from nuget (hopefully the dotnet-ef cli).

Currently I can't get bazel to expose the dotnet binary to my genrule:

genrule(
    name = "test",
    outs = ["out.txt"],
    cmd = "echo \"$(DOTNET_BIN)\" > $@",
    toolchains = [
        "@dotnet_toolchains//:resolved_toolchain",
    ],
    tools = [
        "@dotnet_toolchains//:resolved_toolchain",
    ],
)

the out.txt ends up with the expected content of external/dotnet_x86_64-unknown-linux-gnu/dotnet but when i use --sandbox_debug I can confirm that none of the toolchain files are available to the rule.

I expected to see the external/dotnet_x86_64-unknown-linux-gnu/ folder mounted but it's not there.

So i can't actually execute the dotnet binary, i can only get the variable from the resolved_toolchains target.

Place1 avatar Feb 05 '23 23:02 Place1