【发布时间】:2012-09-23 09:41:32
【问题描述】:
我很想解决一个小问题。我知道这不是调试可能出现警告的一段代码的最佳方法,但是当我在想法之间有一点中断时,我喜欢一直调试。我刚刚发现了 mono 以及编译在 Mac OS X Mountain Lion 上运行的 C# 代码的可能性。我将它集成到CodeRunner 应用程序中,它可以正常工作。但是,如果代码中出现警告,则不起作用。
例如,我试图编译一个创建一个整数(仅此而已)的代码,但由于该警告,它没有进行调试。我收到此错误消息:
Untitled.cs(9,29): warning CS0219: The variable `test' is assigned but its value is never used
Cannot open assembly 'Compilation succeeded - 1 warning(s)
Untitled.exe': No such file or directory.
可能有人知道如何处理。我知道这不是一个必不可少的功能,但即使有一些未使用的变量,我也很想调试代码。
编译脚本文件内容:
#!/bin/bash
enc[4]="UTF8" # UTF-8
enc[10]="UTF16" # UTF-16
enc[5]="ISO8859-1" # ISO Latin 1
enc[9]="ISO8859-2" # ISO Latin 2
enc[30]="MacRoman" # Mac OS Roman
enc[12]="CP1252" # Windows Latin 1
enc[3]="EUCJIS" # Japanese (EUC)
enc[8]="SJIS" # Japanese (Shift JIS)
enc[1]="ASCII" # ASCII
rm -rf "$4"/csharp-compiled
mkdir "$4"/csharp-compiled
#mcs is the Mono CSharp Compiler
file="$1"
length=${#file}
first=`expr $length - 3`
classname=`echo "$file" | cut -c 1-"$first"`
#echo -out:"$4"/csharp-compiled/"$classname".exe "$1"
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1"
status=$?
if [ $status -ne 0 ]
then
exit $status
fi
#echo "$4"/csharp-compiled/
currentDir="$PWD"
cd "$4"/csharp-compiled/
files=`ls -1 *.exe`
status=$?
if [ $status -ne 0 ]
then
exit 1
fi
cd "$currentDir"
for file in $files
do
mv -f "$4"/csharp-compiled/$file "$file"
done
# Otherwise output the name of the input file without extension (this should be the same as the class name)
file="$1"
length=${#file}
first=`expr $length - 3`
classname=`echo "$file" | cut -c 1-"$first"`
echo $classname".exe"
exit 0
【问题讨论】:
-
这看起来您在代码运行器中的集成是错误的:编译器输出似乎被错误地视为文件名的一部分。您能否详细说明您是如何尝试使其发挥作用的?
-
好的,设置如下。我启用了“语言使用编译脚本”。 I/O 编码是 UTF-8。运行命令是'mono $compiler'。语法模式是“C#”,文件扩展名是 cs。编译脚本的内容取自教程。如果您有兴趣或者可能有问题,我可以发布它们。
-
对不起,还有两件事:我发布的设置是首选项的语言选项卡中的设置。我还用编译脚本文件的内容更新了第一篇文章。
-
你能试试
>&2吗?将其添加到dmcs行的末尾。它会使编译器的任何输出显示在 stderr 上,这应该确保它不会被误解。 -
哇,它似乎在工作。现在我只收到警告和消息“编译完成”。非常感谢。小细节很重要 :) 我是 StackOverflow 的新手。是否有可能对您的评论给予任何评价?
标签: c# macos mono warnings coderunner