繁体   English   中英

使用Coderunner编译C#代码-不允许出现警告

[英]Compiling C# Code with Coderunner — No Warnings Allowed

我很想解决一个小问题。 我知道这不是调试可能带有警告的代码的最佳方法,但是当我在想法之间稍有休息时,我总是喜欢调试。 我刚刚发现了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
 dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1" 

dmcs在stdout上放一些消息,在stderr上放一些消息。 CodeRunner希望stdout仅包含输出文件名,而不会包含其他任何文件,因此要实现这一点,可以使用>&2将其他所有内容重定向到stderr。

dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1" >&2

在MS编译器中,thre是一种隐藏警告的方法

语用警告预处理器指令

#pragma warning disable 219
var test = "";
#pragma warning restore 219

它可能会帮助您。

这对于我使用当前Mono和CodeRunner版本的Sierra起作用:

语言编译脚本:

file=$CR_FILENAME
/Library/Frameworks/Mono.framework/Versions/Current/bin/mcs "$CR_FILENAME" >&2
status=$?
if [ $status -ne 0 ]
then
exit $status
fi
echo $file | sed -e "s/\.cs/.exe/"
exit 0

运行命令:

PATH="/Library/Frameworks/Mono.framework/Versions/Current/bin:$PATH"; mono $compiler

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM