内联变量声明未编译 [英] Inline variable declaration not compiling

查看:27
本文介绍了内联变量声明未编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2017 中收到一条消息,特别是 IDE0018 变量声明可以内联.

I've been getting a message in Visual Studio 2017, specifically, IDE0018 Variable declaration can be inlined.

因此,我尝试按照 Visual Studio 2017 发行说明中提到的方式使用内联变量声明,但我无法编译我的项目.

So I try using an inline variable declaration the way it's mentioned in the visual studio 2017 release notes, but I can't get my project to compile.

它没有显示错误消息,但输出显示Rebuild All failed..... error CS1525: Invalid expression term 'int'"

It show no error messages, but the output shows "Rebuild All failed..... error CS1525: Invalid expression term 'int'"

错误仅显示在输出中,而不是错误列表中的实际错误.

The error only shows up in the output, not as an actual error in the error list.

这是我正在使用的代码失败的实际示例.

Here is an actual example of the code I'm using that is failing.

if (int.TryParse(ExpYear, out int IExpYear))
  {
    if (IExpYear < DateTime.Now.Year || IExpYear > DateTime.Now.AddYears(10).Year)
    {
      e += "Expiration Year is invalid.
";
    }
  }
  else
  {
    e += "Expiration Year is not a number.
";
  }

如果我恢复更改,它会按预期编译.有没有可能我没有以某种方式使用 c#7 编译器?

If I revert the change, it compiles as expected. Is it possible that I'm not using the c#7 compiler somehow?

谢谢.

更新:我在 Build > Advanced 中找到了语言设置并将其设置为 C# 7.0.现在构建项目给了我这个错误:

Update: I found the language setting in Build > Advanced and set it to C# 7.0. Building the project now gives me this error:

CSC:错误 CS1617:/langversion 的无效选项7";必须是 ISO-1、ISO-2、默认值或 1 到 6 范围内的整数.

CSC : error CS1617: Invalid option '7' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6.

推荐答案

我能够通过为 v2.0.0-rc3<安装 Microsoft.Net.Compilers nuget 包来解决这个问题/em>,之前安装的唯一版本是 1.3.2.

I was able to resolve this by installing the Microsoft.Net.Compilers nuget package for v2.0.0-rc3, the only version installed prior was 1.3.2.

我仍然不明白如果安装的编译器不支持这个,为什么会出现智能感知和编译器错误.

I still don't understand why the intellisense and compiler errors would show up if the installed compiler didn't support this.

这篇关于内联变量声明未编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆