gpt4 book ai didi

c# - 尝试构建时出现CS1003和CS1026语法错误

转载 作者:行者123 更新时间:2023-12-03 08:19:28 24 4
gpt4 key购买 nike

我不确定为什么会收到此错误。我正在尝试在Visual Studio上构建它。我是新手,但我需要构建此代码。
有我的错误和代码:
(30,19):错误CS1003:语法错误,预期为'('
(30,88):错误CS1026:)
(31,19):错误CS1003:语法错误,'('预期
(31,51):错误CS1026:)
(36,23):错误CS1003:语法错误,预期为'('
(36,63):错误CS1026:)
(37,23):错误CS1003:语法错误,预期为'('
(37,156):错误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以更新或添加:

<LangVersion>8</LangVersion>
(或更高版本,在 <PropertyGroup>元素内)
会解决它。
如果您不能使用C#8,则:
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# - 尝试构建时出现CS1003和CS1026语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64983367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com