C# 尝试生成时出现CS1003和CS1026语法错误

C# 尝试生成时出现CS1003和CS1026语法错误,c#,build,syntax-error,C#,Build,Syntax Error,我不确定为什么会出现此错误。我正在尝试在Visual Studio上构建此错误。我是新手,但我需要构建此代码 以下是我的错误和代码: (30,19):错误CS1003:语法错误,'('应为 namespace MelonLoader.AssemblyGenerator { public static class DownloaderAndUnpacker { public static void Run(string url, string targetVersi

我不确定为什么会出现此错误。我正在尝试在Visual Studio上构建此错误。我是新手,但我需要构建此代码

以下是我的错误和代码:

(30,19):错误CS1003:语法错误,'('应为

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
(30,88):错误CS1026:)应为

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
(31,19):错误CS1003:语法错误,'('应为

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
(31,51):预计出现错误CS1026:)

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
(36,23):错误CS1003:语法错误,'('应为

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
(36,63):错误CS1026:)应为

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
(37,23):错误CS1003:语法错误,'('应为

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
(37156):应为错误CS1026:)

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
这似乎是C#8“使用声明”;您可能有最新的编译器可用,但您的csproj配置为使用低级C#;编辑cspoj以更新或添加以下内容是可能的:

8
(或更高,在
元素内)

我会修好的

如果你不能使用C#8,那么:

使用(var stream=new FileStream(tempFile,FileMode.Open,FileAccess.Read))
使用(var-zip=new-ZipArchive(流))
{
foreach(zip.Entries中的var zipArchiveEntry)
{
Logger.Log($“正在提取{zipArchiveEntry.FullName}”);
使用(var entryStream=zipArchiveEntry.Open())
使用(var targetStream=newfilestream(Path.Combine(destinationFolder,zipArchiveEntry.FullName),FileMode.OpenOrCreate,FileAccess.Write))
{
CopyTo(targetStream);
}
}
}
这似乎是C#8“使用声明”;您可能有最新的编译器可用,但您的csproj配置为使用低级C#;编辑cspoj以更新或添加以下内容是可能的:

8
(或更高,在
元素内)

我会修好的

如果你不能使用C#8,那么:

使用(var stream=new FileStream(tempFile,FileMode.Open,FileAccess.Read))
使用(var-zip=new-ZipArchive(流))
{
foreach(zip.Entries中的var zipArchiveEntry)
{
Logger.Log($“正在提取{zipArchiveEntry.FullName}”);
使用(var entryStream=zipArchiveEntry.Open())
使用(var targetStream=newfilestream(Path.Combine(destinationFolder,zipArchiveEntry.FullName),FileMode.OpenOrCreate,FileAccess.Write))
{
CopyTo(targetStream);
}
}
}

您正在使用哪个版本的Visual Studio?第30行在哪里?您发布的代码中的哪一行与错误消息中的第30行相对应?我想您没有使用C#8.0。using语句使用的语法需要C#8.0。因此,我的问题是关于VisualStudio版本。可能您需要启用C#8.0或第30行:使用var stream=new FileStream(tempFile、FileMode.Open、FileAccess.Read);第31行:使用var-zip=new-ZipArchive(流);第36行:使用var entryStream=zipArchiveEntry.Open();第37行:使用var targetStream=new FileStream(Path.Combine(destinationFolder,zipArchiveEntry.FullName),FileMode.OpenOrCreate,FileAccess.Write);您正在使用哪个版本的Visual Studio?第30行在哪里?您发布的代码中的哪一行对应于错误消息中的第30行?我想您没有使用C#8.0。using语句使用的语法需要C#8.0。因此,我的问题是关于VisualStudio版本。可能您需要启用C#8.0或第30行:使用var stream=new FileStream(tempFile、FileMode.Open、FileAccess.Read);第31行:使用var-zip=new-ZipArchive(流);第36行:使用var entryStream=zipArchiveEntry.Open();第37行:使用var targetStream=new FileStream(Path.Combine(destinationFolder,zipArchiveEntry.FullName),FileMode.OpenOrCreate,FileAccess.Write);