rules_dotnet
rules_dotnet copied to clipboard
Question: is there a way to use the `dotnet` executable
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
?
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
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.
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.
I think we are missing an import_binary rule here https://github.com/bazelbuild/rules_dotnet/blob/next/dotnet/private/rules/imports.bzl
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",
],
@njlr Did you get this to work? Going to close this issue if the template variables worked as expected.
Closing this for now since there was no response
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.