我正在尝试使用带有引用的单声道编译某些内容但由于某种原因它会抛出无意义错误(我可以使用visual studio编译,而不是使用单声道编译)。
制作剧本:
#!/bin/bash
SAVEPATH="/usr/home/"
LIBPATH="usr/home/source/lib"
REFS=( "MySql.Data.dll" "MySql.Web.dll" )
MAKEFILES=( "Main.cs" "HandleCallback.cs" "Logs.cs" "Database.cs")
CMDCOMPILE="mcs"
for element in "${REFS[@]}"; do
CMDCOMPILE=$CMDCOMPILE" -reference:$LIBPATH/$element "
done
for element in "${MAKEFILES[@]}"; do
CMDCOMPILE=$CMDCOMPILE" $element "
done
eval $CMDCOMPILE
mv /usr/home/source/Main.exe $SAVEPATH/Server
结果错误是
Database.cs(24,65): error CS1010: Newline in constant
Database.cs(25,0): error CS1525: Unexpected symbol `3306'
Database.cs(25,8): error CS1010: Newline in constant
Database.cs(26,16): error CS1525: Unexpected symbol `return'
Database.cs(54,68): error CS1010: Newline in constant
Database.cs(55,0): error CS1525: Unexpected symbol `trying'
Database.cs(55,49): error CS1010: Newline in constant
Database.cs(56,13): error CS1002: ; expected
Database.cs(75,68): error CS1010: Newline in constant
Database.cs(76,0): error CS1525: Unexpected symbol `trying'
Database.cs(76,47): error CS1010: Newline in constant
就像我说的那样,Database.cs中没有错误。我认为它给了我这个,因为“-reference:”标签没有完成它的工作。
最终命令输出
mcs -reference:usr/home/source/lib/MySql.Data.dll -reference:usr/home/source/lib/MySql.Web.dll Main.cs HandleCallback.cs Logs.cs Database.cs
命令是否不正确或是否缺少其他内容?
Database.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Server
{
public static class Database
{
private static MySqlConnection conn;
public static bool ConnectDB()
{
Console.WriteLine("Connecting to Database...");
string connString = "Server=xxx.xxx.xxx.xxx;Port=3306;Uid=xxxx;password=xxxxxxx";
conn = new MySqlConnection(connString);
try
{
conn.Open();
Console.WriteLine("Connected to Database");
return true;
}
catch (Exception e)
{
Console.WriteLine("Couldn't connect to database:");
Console.WriteLine(e.ToString());
return false;
}
}
private static bool isAlive()
{
if (conn != null)
return true;
else
return false;
}
(...)
}
}