Dotnet auto grading

Has anyone been successful at setting up assignments with auto grading for dotnet?

The command dotnet run fails in autograder with the following message

“The user’s home directory could not be determined. Set the ‘DOTNET_CLI_HOME’ environment variable to specify the directory to use.”

I tried to “export” the variable as a setup command but that didn’t work either.

I’ve got the same question. Did you find a solution?

I don’t think it is currently possible to run dotnet inside autograding. Child processes are spawned with only PATH and FORCE_COLOR environmental variables set. Trying to set variables in either the workflow, or in the setup field won’t work. The same problem seems to effect Golang as well. Both languages require specific environmental variables to be set.

I opened a PR for this, but I’m not sure if it will get any attention.

If you want a work-around for dotnet testing (or any testing that requires context or env) and to have grading scores reported in the GH Classroom interface:

  • add the .github/workflows/classroom.yml and .github/classroom/autograding.json files to your template starter repository. Don’t use the Classroom interface to create the autograding tests.
  • add your dotnet tests as steps in classroom.yml workflow. For each test, if the test passes drop a file (e.g. ‘.github/results/test-1.txt’)
  • in autograding.json add a test to check if the file exists. (e.g. "[ -e .github/results/test-1.txt ] && exit 0 || exit 1")

@acrokat Can the development team look at this? Not being able to use dotnet or Golang in autograding is a big issue.

Thank you for your response and the workaround @markpatterson27
I hope your PR gets some attention soon.

I’m currently experimenting with .NET 6 and autograding and this run command works for me: DOTNET_CLI_HOME=/tmp/ dotnet test Probably would be better to set it to $PWD? But this works…

Full autograding.json:

  "tests": [
      "name": "dotnet test",
      "setup": "sudo apt-get update && sudo apt-get install -y apt-transport-https && sudo apt-get update && sudo apt-get install -y dotnet-sdk-6.0",
      "run": "DOTNET_CLI_HOME=/tmp/ dotnet test",
      "input": "",
      "output": "",
      "comparison": "included",
      "timeout": 2,
      "points": 1
1 Like

.NET 6 is already installed on the runner. You don’t need to reinstall it.

You’ll need to include DOTNET_CLI_HOME=/tmp/ for every test run that needs dotnet. It won’t persist between tests (or even between setup and run.)

1 Like

Thanks, @markpatterson27! This solution worked!
It’s probably worth to mention that if you need to do an exact string match on the output, the welcome message needs to be suppressed. This is the full command I ran and tested:
DOTNET_CLI_HOME=/tmp/ DOTNET_NOLOGO=true dotnet run

1 Like