Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# 7.1 can't be published

I have ASP.NET Core C# web application. I made some changes that now use C# 7.1 features. I changed project version, so it compiles and runs fine. However, when I try to publish the project, I am getting an error:

Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater.

Compile command that I see is:

C:...\.nuget\packages\microsoft.net.compilers\2.6.1\tools\csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705,1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE;RELEASE;NETCOREAPP2_0 /errorendlocation /preferreduilang:en-US /warnaserror+:NU1605` 

As suggested elsewhere, I installed Microsoft.Net.Compilers (v2.6.1), but it didn't make any difference.

Is there a Visual Studio setting that affects publish specifically?

UPDATE: Looks like a console application doesn't have this problem. If it builds successfully, it publishes successfully as well. However, the web application does not publish. Was anybody successful in publishing ASP.NET Core web application with C# 7.1 features?

like image 592
Felix Avatar asked Dec 22 '17 19:12

Felix


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


2 Answers

Adding <LangVersion>latest</LangVersion> to your .pubxml file made it possible for Visual Studio 2017 (15.5.2 in my case) to publish.

Source: https://developercommunity.visualstudio.com/solutions/166543/view.html

like image 150
Jeremy Cook Avatar answered Oct 04 '22 02:10

Jeremy Cook


Update:
After upgrading my VS2017 from version 15.4.5 to 15.5.2 I can reproduce the problem, and I get an error

Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater

The answer from @Jeremy Cook solves the issue:
<LangVersion>latest</LangVersion> in .pubxml


In both old and new project formats the LangVersion element in project file is responsible for this. You can either change that via csproj xml file or via UI in visual studio.

Please note that this setting is dependent on your build configuration. To make sure that you can both code and publish using C# 7.1 and later make sure you configure this setting regardless of build configuration (Debug, Release etc).

<Project Sdk="Microsoft.NET.Sdk">    <PropertyGroup>     <TargetFramework>netstandard2.0</TargetFramework>     <LangVersion>latest</LangVersion>   </PropertyGroup>  </Project> 

enter image description here

like image 22
ironstone13 Avatar answered Oct 04 '22 03:10

ironstone13