我有 ASP.NET Core C# Web 应用程序.我做了一些更改,现在使用 C# 7.1 功能.我更改了项目版本,所以它编译并运行良好.但是,当我尝试发布该项目时,我收到一个错误:
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:
功能默认文字"在 C# 7.0 中不可用.请使用 7.1 或更高版本的语言.
Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater.
我看到的编译命令是:
C:....nugetpackagesmicrosoft.net.compilers2.6.1 oolscsc.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`
按照其他地方的建议,我安装了 Microsoft.Net.Compilers
(v2.6.1),但没有任何区别.
As suggested elsewhere, I installed Microsoft.Net.Compilers
(v2.6.1), but it didn't make any difference.
是否有专门影响发布的 Visual Studio 设置?
Is there a Visual Studio setting that affects publish specifically?
更新:看起来控制台应用程序没有这个问题.如果它构建成功,它也会成功发布.但是,Web 应用程序不会发布.是否有人成功发布了具有 C# 7.1 功能的 ASP.NET Core Web 应用程序?
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?
将 <LangVersion>latest</LangVersion>
添加到您的 .pubxml 文件中,使 Visual Studio 2017 (15.5.2就我而言)发布.
Adding <LangVersion>latest</LangVersion>
to your .pubxml file made it possible for Visual Studio 2017 (15.5.2 in my case) to publish.
来源:https://developercommunity.visualstudio.com/solutions/166543/view.html
这篇关于C# 7.1 无法发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!