Inline variable declaration not compiling

后端 未结 3 1544
旧巷少年郎
旧巷少年郎 2020-12-14 13:52

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

So I try using an inline variable declara

相关标签:
3条回答
  • 2020-12-14 14:45

    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.

    0 讨论(0)
  • 2020-12-14 14:47

    In case the above answer doesn't work for you, as it didn't work for me do the following:

    Open the csproj file and check if you have the following package referenced in the file after the upgrade, if yes, remove it.

    <Import Project="packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />
    

    Next, check the "Project ToolsVersion". It has to be 15.0, it probably is 14.0 though so you have to change that.

    <Project ToolsVersion="15.0" .../>
    

    Then simply reload the SOLUTION and you're good to go. Be aware that if you select "Reload Project" it will give you an error and not load it.

    0 讨论(0)
  • 2020-12-14 14:53

    To set the use of latest released C# compiler:

    In Visual Studio, (I'm using Visual Studio 2017), right click project and select "Properties"

    Select the "Build" tab in left-side menubar

    Click "Advanced..." button in lower right corner of the "Build" window

    Under "General," in listbox to the right of "Language Version", select "C# latest minor version (latest)"

    Also, make sure to keep the Visual Studio IDE up-to-date using Visual Studio Installer.

    0 讨论(0)
提交回复
热议问题