Skip to content

Commit 4c7315d

Browse files
dll fix for c#
1 parent 83cc796 commit 4c7315d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

language/csharp/csharp.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,29 @@ import (
44
"github.com/coderbyte-org/cb-code-runner/cmd"
55
"github.com/coderbyte-org/cb-code-runner/util"
66
"path/filepath"
7+
"io"
8+
"os"
9+
"fmt"
710
)
811

912
func Run(files []string, stdin string) (string, string, error, string) {
1013
workDir := filepath.Dir(files[0])
1114
binName := "a.exe"
15+
sourceFiles := util.FilterByExtension(files, "cs")
1216

13-
// TODO: getting JSON package to work with C#
17+
// for C#, need to link .dll files to this project and include them in directory
1418
// https://stackoverflow.com/questions/50079804/how-do-i-add-json-assembly-to-compile-c-sharp-code-on-ubuntu-terminal-using-mcs
1519
// https://stackoverflow.com/questions/49767212/how-to-compile-and-run-c-sharp-project-from-terminal-mac-os
16-
sourceFiles := util.FilterByExtension(files, "cs")
17-
args := append([]string{"mcs", "-out:" + binName}, sourceFiles...)
20+
// https://docs.unity3d.com/462/Documentation/Manual/UsingDLL.html
21+
oldLocation := "/usr/local/bin/Newtonsoft.Json.dll"
22+
newLocation := workDir + "/Newtonsoft.Json.dll"
23+
srcFile, err := os.Open(oldLocation)
24+
destFile, err := os.Create(newLocation)
25+
_, err = io.Copy(destFile, srcFile)
26+
err = destFile.Sync()
27+
28+
args := append([]string{"mcs", "-r:Newtonsoft.Json.dll", "-out:" + binName}, sourceFiles...)
29+
1830
stdout, stderr, err, duration := cmd.Run(workDir, args...)
1931
if err != nil || stderr != "" {
2032
return stdout, stderr, err, duration

0 commit comments

Comments
 (0)