c# - 尝试构建时出现 CS1003 和 CS1026 语法错误
问题描述
我不确定为什么会出现此错误。我正在尝试在 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);
}
}
}
推荐阅读
- python - 在 Pandas 中替换?Python
- java - 无法计算字符串的每个部分中有多少个唯一日期可用
- python - 从其他列计算 Panda 数据框中的 np.arange
- opengl - 接口块数组可以从顶点着色器转移到片段着色器吗
- javascript - JavaScript 在三种或更多语言之间切换语言
- javascript - 如何在reactjs中解决没有eval()或mathjs的数学表达式
- reactjs - 按钮禁用,直到 youtube 视频结束 - 反应打字稿
- c# - 如何从 Form 变量中获取 toolStripMenuItem?
- java - 使用 reassured 和 testng 得到错误。java.lang.ClassCastException:类 java.util.ArrayList 不能转换为类 org.hamcrest.Matcher
- spring - Spring项目上的Hibernate SessionFactory注入不起作用